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: http://docs.platformio.org/en/latest/projectconf.html

[env:uno]
platform = atmelavr
framework = arduino
board = uno

[env:nodemcu]
platform = espressif
framework = arduino
board = nodemcu
build_flags = -D LED_BUILTIN=BUILTIN_LED

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31

[env:lpmsp430g2553]
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.
  pinMode(LED_BUILTIN, OUTPUT);
}

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

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()) {
            device.putc(pc.getc());
        }
        if(device.readable()) {
            pc.putc(device.getc());
        }
    }
}

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