Part 1/3: PlatformIO open-source embedded development ecosystem

This post is part of a series:

Getting an Arduino based project (or other embedded platform) to compile and upload can be a pain. Making sure all the libraries are installed in the correct locations and are the correct versions can be tricky and time-consuming.

I’m sure many developers will agree that the tools we use for embedded development are generally not as good as those used for web application development.

The Arduino team have done a good job with their IDE to try and make the embedded development tool-chain setup as easy as possible. However, I still find library management a cause of frustration. Especially since I move between computers and OS’s frequently.

Recently I have been using PlatformIO and am rather impressed with the ease of setup, speed of compilation, uploading (auto port detection), and most importantly an excellent library manager.

PlatformIO is an open-source ecosystem for IoT development.

Cross-platform build system, IDE integration and continuous testing. Arduino, Espressif, ARM and mbed compatible.

PlatformIO IDE

Here are some things that have impressed me about PlatformIO (pio) after using it for a couple of weeks:

  • Fully open-source with active and friendly dev community.
  • Easy to install - Pure python based, installed using pip
    • Tool-chains are auto installed on first compile / upload e.g.
      • If trying to upload to Arduino avrdude will automatically be installed
      • If trying to compile an ESP8266 project the ESP toolchain will be installed
    • Cross-platform (Linux, Windows and mac all work the same), this will make support much easier
  • Supports all the main embedded platforms
    • atmelavr (Arduino), espressif (ESP8266), ststm32 (ARM etc.)
  • Command line and IDE
    • At work I use pio via Atom IDE on Ubuntu
    • At home, I use a Chromebook with Caret IDE and interact with pio via command-line
    • When developing directly on an emonPi / RaspberryPi pio command-line works great - Yes, that’s right pio works on a RaspberryPi to compile and upload code directly!
  • Excellent library manager
    • Libraries can be searched and reviewed using command-line or web 2.0 manager
    • Required libraries can be specified in the platformio.ini file and if not present install is prompted upon compilation
    • Specific library version (as defined in library.json (emonLib example)) or git commit SHA
  • Fast compilation & pain-free uploading
    • PlatformIO’s compiler is the fastest in the business
    • USB / Serial ports auto detected
    • Since the emonPi has been added as a custom board PlatformIO can even upload direct to emonPi via RaspberryPi GPIO and trigger GPIO AVR reset, not more hacked avrdude.
  • Easy integration with continuous testing & deployment
    • Integration with TravisCI to enable compilation, code testing and binary (.hex / .bin) release generation in the cloud.
    • emonPi and emonTx git repos are now enabled for continous-testing and auto binary generation on release tag…this is a step change in embedded development.

Example: Compiling emonTx / emonPi firmware

PlatformIO has some excellent quick start docs to cover setting up your first ‘blinky’ project, therefore I will not duplicate here. In this example I focus on setting up pio and compiling emonTx / emonPi firmware. This example assumes a totally bare metal machine with nothing installed except python (2.7 recommended). Pio works great on a Raspberry Pi.

This guide used command-line steps on Linux, if using Windows or if you want to use the platformio IDE see PlatformIO Getting Started Page.

The PlatformIO IDE or Atom IDE is excellent and very easy to use (self explanatory). This guide uses pio via command line as this gives a more hands-on experience to how pio is working.

1. Install PlatformIO

The easiest way if running Linux is to use the install script, this installs pio via python pip and installs pip if not present. See PlatformIO installation docs:

$ sudo python -c "$(curl -fsSL"

2. Clone emonTx / emonPi repo

We’ll use the emonTx (V3 discrete sampling) as an example here but the steps are exactly the same for emonPi.

emonTx V3

$ git clone`
$ cd emonTxFirmware/emonTxV3/RFM/emonTxV3.4/emonTxV3_4_DiscreteSampling


$ git clone`
cd emonpi/firmware

3. Compile with PlatformIO

$ platformio run

or shorthand for the lazy

$ pio run

That’s it! That’s all that’s needed to setup pio from scratch and compile emonTx firmware :-D

The first time platformIO is run it will ask to install the required libraries (versions specified) and AVR toolchain. The required libraries are defined in platformio.ini in the emonTx discrete sampling firmware folder:


lib_deps_external =
  DHT sensor library @1.2.3
  DallasTemperature @3.7.7
  [email protected]
  LiquidCrystal_I2C @4bb48bd648

The latest version of the libraries are automatically cloned from their native git repos into the ~/platformio folder.

If required specific versions can be installed e.g.:

$ pio lib install 252 --version="e70c9d9f4e"
$ platformio lib install 54 --version="3.7.7"

3. Upload using PlatformIO

3a. Via USB to UART programmer to emonTx

$ sudo platformio run --target upload

or lazy shorthand

$ sudo pio run -t upload

Pio will attempt to auto detect the USB programmer and upload :-)

Note: you will need sudo unless you have correctly configured udev rules.

To list available serial ports:

$ pio serialports list

There is even a built in serial monitor

$ pio serialports monitor

3b. Using ttyAMA0 GPIO to upload direct to emonPi

This is where things get very exciting, pio can compile the code directly on a Raspberry Pi. The latest version of pio (due to be released in the next few weeks, released 2.10.0) will have built in support for the emonPi auto-reset on upload using GPIO4. See emonPi listed on PlatformIO boards page:


The emonPi board is defined in platformio.ini in the emonpi/firmware folder:

board = emonpi
upload_port = /dev/ttyAMA0

All that is needed to compile and upload directly on the emonPi is:

cd ~/emonpi/firmware
$ sudo service emonhub stop
$ sudo pio run -t upload
$ sudo service emonhub start

Thanks a lot to Ivan Kravets for helping integrate emonPi into the PlatfomIO ecosystem. View commit changes

Stay tuned for part 2/3 of the PlatformIO post series which will cover setting up firmware continuous testing using Travis CI and auto compiled binary generation on release tag directly on github. This is currently live on the emonPi & emonTx repos if you want a sneak preview. See travis.yaml file and Travis build status icon on the main emonpi repo

To engage in discussion regarding this post, please post on our Community Forum.