PlatformIO is a solution

PlatformIO is a solution

I have had to work on quite lots of embedded platforms like Arduino, mbed, PIC32, Raspberry Pi… and develop them on Window as well as Linux. It is really inconvenient to me because each platform has each IDE to develop, and for some platforms its IDE is quite poor comparing with Text Editor (Atom, Vim, Sublime, Emacs) and I have to change environments many times. Fortunately, I found this one as the best solution at this time, PlatformIO. It is an open source ecosystem for “IoT” development and cross platform code builder and library manager with a lot of development platforms and frameworks (check here):

  • Colourful command-line output
  • IDE Integration with Arduino, Atom, CLion, Eclipse, Emacs, Energia, Qt Creator, Sublime, Vim, even Visual Studio
  • Cloud compiling and Continous Integration with AppVeyor, Circle CI, Drone, Shipable
  • Build-in Serial Port Monitor and configurable build -flags/-options
  • Automatic firmware uploading
  • Pre-built toolchains, frameworks for the popular Hardware Platforms
  • Friendly Comaand-Line Interface
  • Modern Web 2.0 Library Search
  • Open Source Library Registry API
  • Library dependency management
  • Automatic library updating

How to build PlatformIO based project

Arduino Uno

1. Make a new project directory and initialize an empty project

mkdir platformio/test_uno
cd platformio/test_uno
platformio init

This will create:

  • /src
  • /lib
  • platformio.ini

2. Configure platformio.ini with boards

platformio init --board=uno

platformio.ini looks like this:

; Project Configuration File
; Docs:

platform = atmelavr
framework = arduino
board = uno

platform = espressif
framework = arduino
board = nodemcu

platform = teensy
framework = arduino
board = teensy31

platform = timsp430
framework = energia
board = lpmsp430g2553
build_flags = -D LED_BUILTIN=RED_LED

3. Arduino code in src/main.cpp

#include "Arduino.h"

void setup()
  // initialize LED digital pin as an output.

void loop()
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second

4. Upload to arduino

platformio run --target upload

LPC1768 development board

Basically, It is similar with Arduino. There are different when you initialize platformio:

platformio init --board=lpc1768

Example code for LPC1768:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
Serial device(p9, p10);  // tx, rx

int main() {
    while(1) {
        if(pc.readable()) {
        if(device.readable()) {

Maybe you will get error at the first line because the library of mbed is not in library manager then you have to add it (guide here).

You can get mbed library here.

Cuong Tran Viet

Cuong Tran Viet
I'm a person that always opens to new, incredulous, curious and too often against the trend (the classical sheep that doesn’t want to follow the herd)

Basic knowledge about quadcopter (part 2)

This part will talk about basic knowledge that I accumulated to prepar for building my own quadcopter Continue reading

Drone Project Introduction (part 1)

Published on January 04, 2017