Getting started with PlatformIO

Posted on September 23, 2019
Tags: arduino, electronics, making

I’ve been wanting to look into PlatformIO as an alternative to the Arduino IDE. I’ve been hoping it might solve problems like:

Arduino tools menu

Basically, PlatformIO appears to be a unified build tool, which can build and flash embedded projects for a wide variety of chips and boards. PlatformIO is not an API, but rather it reuses existing platforms like Arduino or mbed. However, you do not have to learn a new workflow or install new tools to use a different platform. Rather, you interact with the PlatformIO tool, and it automatically downloads toolchains and libraries when needed.

So, I gave PlatformIO a try, by running a “blinking LED” example on an Arduino Uno board. (Actually, I used a STEMTera, which is 100% Uno compatible.)

First, I needed to install PlatformIO. I did this on my Ubuntu 16.04 machine. The first step was to install the udev rules:

curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/master/scripts/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
sudo service udev restart

Then I installed PlatformIO using pip:

sudo pip install -U platformio

And that’s it for installation! Now, following the quickstart guide, I was ready to try building an example. The first step was to create a project:

~$ mkdir -p pio/blink
~$ cd pio/blink
~/pio/blink$ pio init --board uno
********************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for IoT development > https://platformio.org/platformio-ide
- support us with PlatformIO Plus > https://pioplus.com
********************************************************************************


The current working directory /home/ppelleti/pio/blink will be used for the project.

The next files/directories have been created in /home/ppelleti/pio/blink
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File

Project has been successfully initialized! Useful commands:
`pio run` - process/build project from the current directory
`pio run --target upload` or `pio run -t upload` - upload firmware to a target
`pio run --target clean` - clean project (remove compiled files)
`pio run --help` - additional information

This worked fine, although after printing all of this out, it hung for a long time. I’m not sure what it was doing, but it eventually returned my to the prompt after quite a while. Just be patient.

Then I created the src/main.cpp file as specified in the quickstart. After that, I just needed to do:

pio run

to build the project. And then finally, I flashed the code onto my STEMTera by running:

pio run -t upload

And it worked! I still have a lot to learn about PlatformIO, but it seems promising so far.