Saturday, March 12, 2016

PlatformIO, the Arduino IDE for programmers

The Arduino IDE is a great way to get started with embedded programming. It combines an editor, library manager, board manager, examples, programming tool and serial monitor all in one easy to install application.

As a programmer I'm used to my editor understanding the code and helping me out by suggesting what I might like to type next and showing me errors right in line with the code.

Here's PlatformIO in the Atom editor suggesting completions to Serial.

I also like the cool dark look.

PlatformIO is a set of command line tools that can be hooked in to various text editors but the easiest way to get started is to download the IDE they've made from the GitHub Atom editor here.

Although Arduino code is c++ the actual files aren't strictly c++ so a few changes need to be made to get some sketches ported over.

Typically you'll need to #import arduino.h and put a function declaration above where a function is first called.

(PlatformIO has the ability to import an Arduino sketch too).

Here's how Blink looks:

#include <Arduino.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH); 
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off 
  delay(1000);              // wait for a second

To use external libraries you've imported into your Arduino environment you need to add the path to that library directory in the platformio.ini file.

; Here's the trick for finding Arduino libraries
lib_dir = ~/Documents/Arduino/Libraries

; Windows OS / "piolib-arduino" project
; [platformio]
; lib_dir = ~\Documents\Arduino\libraries

; Linux OS / "piolib-energia" project
; [platformio]
; lib_dir = ~/sketchbook/libraries

The environment  It supports more than 200 development boards along with more than 15 development platforms and 10 frameworks. It took me a while to find the esp8266 board I have, (search for board might be a good feature), but when chosen programming worked perfectly and it figured out the serial port automagically.

This looks like a great way to explore the Internet of Things.

Welcome to the Reddit community, there's an interesting thread here.

Installing on MacOS "just worked" but that's probably because I already have Xcode installed. On Linux I needed to install clang to get code completion going, but the IDE told me what was missing. I'm sorry I can't help Windows users.

No comments: