Over the years I have used different tools for coding, compiling, flashing and debugging applications (mostly assembler and C) on what we nowadays call 'embedded systems' or even IoT devices... I'll skip the old days when I used special high-voltage programmers and UV light for EPROMS with 2 to 16KB memory, the 27xx series as they were called with a 24-pin wide DIP footprint.

Development platforms for embedded devices come in many shapes and sizes. Some open source, some commercial. Some focused on easy installation and usage for novice users, some supporting only one manufacturer's systems, and others aim to provide a wide range of languages, build environments and target systems. I state some opinions in this article, but there is a tool for every need and what works for me may not work for you.

Atmel Studio (a customized Visual Studio based IDE provided by Atmel) and WinAVR have been the default tools for programming the Atmel AVR MCU's. Atmel Studio works well with the AVR and ARM devices. The 6.x release (based on VS2010) was a bit buggy from time to time, the 7.x release is much more stable. However, it only supports Atmel devices and boards and assembler support is somewhat limited. Since I recently ordered some ESP8266 WiFi SoC's, which have their own toolchain and libraries, it was time to look for new tools of the trade.

New kid on the block

Having used Eclipse occasionally for PHP and Java development, it was an obvious candidate for 'embedded programming'. It is a solid open source IDE with broad community support and lot's of flexibility and add-ons. Although it's GUI feels a bit old-fashioned, it works well. But then I stumbled upon Atom and PlatformIO. After a quick test run, I decided to give it a go. Atom is a highly extensible open source editor with strong IDE aspirations, and although there is a learning curve to get to know all the feature rich packages and options, it is stable and fast. As the Atom developers say, it's "A hackable text editor for the 21st Century, designed to be deeply customizable". See atom.io for more information. Since is built on Electron, a cross platform framework, Atom is available for all major platforms (Windows, Mac OSX, Linux). It can even run on a RaspberryPi if you like. At the time of writing this blog post, version 1.7.2 is the current version.

Atom has a lot of extensions and packages that are managed through the Atom Package Manager (APM), and one of particular interest is PlatformIO; more on that shortly. For the power users among us that don't like to walk trough a cascade of dropdown menus, it also has a command palette where you can just start typing a command with autocomplete and search for commands. If you hit ctrl-shift-P (cmd-shift-P on OS X), it will pop up. You can select various themes to change the look of Atom and even the syntax highlighting can be fully customized. I prefer a dark background as it is easier on my old eyes. Atom can work with individual files or complete directories, using the File -> Open Folder menu. You are presented with a tree view of the directories and can have multiple files open.

Developing for different MCU's

One of the challenges you face when working with different types of microcontrollers and boards, like Atmel's AVR, various Arduino clones or ESP8266 WiFi SoC based devices, is to deal with all the different libraries, toolchains, frameworks, programmers and debuggers. You can easily end up with different development environments for each. Arduino has its own IDE, Atmel provides Atmel Studio, etc. The guys behind PlatformIO are solving that for us by doing all the hard work. PlatformIO supports a lot of boards (200+), platforms (15+) and frameworks out-of-the-box and when you select a board/controller, it will take care of the toolchain, libraries, framework and debugger for you. PlatformIO started as a Command Line based solution for easy library and toolchain management, and could be used with well known IDE’s like Eclipse or Visual Studio. Recently they’ve released a version with built-in IDE based on the Atom editor. That's the one I am using right now. In fact I write this blog post with Atom.

Out of the box PlatformIO supports almost every Arduino variant known to mankind, Espressif ESP8266 boards including NodeMCU and WeMOS, which I ordered recently (see my other blog post), and many more. And you can add your own platforms, boards and frameworks if you cannot find yours. Since I was going to develop my own Atmel 8-bit MCU and ESP8266 based devices, I decided to try it out (and will soon define my own platform and boards for the home-made devices).

If you don't want to use Atom as your editor, you can still benefit from PlatformIO's features because it can also be integrated with other IDE like Eclipse, NetBeans, SublimeText and even Visual Studio (no first hand experience on those integrations).

Installing the new development tools: Atom and PlatformIO

The steps to install Atom and PlatformIO are (see also PlatfrmIO installation page):

  1. Install Python 2.7 interpreter
  2. Install clang for code auto completion
  3. Install PlatformIO IDE with Atom
  4. Configure Atom to your preferences
  5. Install additional packages

Although simple steps, there were some hiccups along the way as you can read below.

Since Atom is written in Python, you must install Python 2.7.x first from the official Pyyhon website if running on Windows - most Linux distributions come with Python pre-installed. Don't forget to add the Python executable directory to the Windows PATH environment variable.

Clang is used for code auto completion. You should download the latest Clang for Windows and Linux. Scroll down a bit and choose the correct pre-built binary for your system (Clang for Windows 64-bit in my case) and make sure you select “Add LLVM to the system PATH” option on the installation step. The latest version at the time of writing this was 3.8.0. The installation didn't go as smooth as I expected. I was presented with an error message in a command shell: "Failed to find MSBuild toolsets directory. MSVC integration install failed"

Clang for Windows error installing

My guess was that it was not relevant for the PlatformIO environment, since it was referring to a Microsoft build toolset. Checking the installed files, I found an install.bat in the C:\Program Files\LLVM\tools\msbuild directory. It searches for the MSBuild toolset directory in places like "%ProgramFiles%\MSBuild\Microsoft.Cpp\v4.0\Platforms\%PLATFORM%\PlatformToolsets", and copies some files from LLVM to the MSBuild directory if it finds them. Otherwise the above error is thrown. This confirmed that the error is not relevant for this environment, we can just ignore it.

Next step: Atom. Installing Atom ended in a "installation has failed" error, and it was suggested that I inspect the setup log. That happened on a completely fresh install of Windows 10 Enterprise with just the needed Windows updates and the Chrome and Firefox browsers installed, nothing else yet. The error in the log file stated that it could not access "C:\Users\Ron\AppData\Local\atom\app-1.7.2\lib\net45\resources\app.asr" because it was in use by another process.

To my knowledge, nothing else was going on at that time. As a hunch, I installed the older .NET framework (3.5), which is usually installed on just about any Windows computer, but not on this freshly installed Windows 10 laptop. You can find the .NET framework in the Control Panel: Programs > Turn Windows features on or off right at the top. The next attempt at installing Atom was successful. The easiest way to install Atom and PlatformIO is to go to http://platformio.org/platformio-ide and download the combined installer. The 104MB executable for Windows is just a one-click installer, after running it Atom is installed and started and from there it continues to install the PlatformIO IDE package. Once that's done you should reload Atom to activate it.

It will create a PlatformIO menu entry with all the relevant commands like Build and Upload. Near the bottom of the PlatformIO Home Screen you will see a checkbox to select whether you want to open the PlatformIO home screen every time you start Atom. Note that PlatformIO IDE also includes PlatformIO CLI with all the command line options to run all the powerful commands from a shell (even from within Atom).

I strongly advice you to get to know Atom a bit, by starting to customize it's look-and-feel and add a few packages. You can also find more instructions for adding essential packages and configuring Atom and PlatformIO here.

Test drive the new tools

Before we go into more options and extensions to tune PlatformIO and Atom to our needs, a test drive is recommended. We will use a 'Hello world' test (or Blinky I should say in this age of IoT). To get some software running on a device we go through the following steps:

  1. Install any needed drivers for accessing the device (like USB drivers).
  2. Create a PlatformIO project and select the right directory and board.
  3. Write (or copy) your first Hello World/Blinky program.
  4. Build and flash the program.
  5. Unplug and reset the device to let the program run.

Having ordered a set of WeMOS D1 mini devices (a NodeMCU clone preloaded with Lua), based on the ESP8266, I used that as testing board. As explained in my previous blog post, the D1 Mini has a CH430 USB-to-serial converter built-in. There are drivers available for Windows and Linux from the WeMos site.

After having confirmed we can communicate with the D1 Mini, we move on to create a new project in PlatformIO by choosing "Initialize new PlatformIO project or modify existing..." in the PlatformIO menu and choose the WeMos D1 Mini board and select an empty project directory. We use a very simple Hello World/Blinky program, like this:

// Blinky - The "Hello, World" of IoT
// Flashes the build-in LED in a one second interval and writes "Hello, World."
//  to the serial interface.

// Use the Arduino libraries for ESP8266 (make it easy for this test run).
// They are automatically downloaded by PlatformIO.
#include <Arduino.h>

// The built-in LED is connected to "Arduino compatible" pin 2 (is D4 on the D1 Mini).
#define BUILTIN_LED 2

void setup() {
  // Initialize the LED pin as output.
  // Set port speed to 9600 baud.

void loop() {
  digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED on.
  delay(1000);                      // Wait a second.
  digitalWrite(BUILTIN_LED, LOW);   // Turn the LED off.
  Serial.println("Hello, World.");  //Send our happy message to the universe.

This tiny program just flashes the little blue LED once every second and sends the message "Hello, World." out on the serial interface at 9600 baud. Compile/Build it using the Build button (the big checkmark icon on the top left) or use the PlatformIO -> Build menu entry. You should get a [SUCCESS] message in the terminal window at the bottom. If not check for syntax errors and try again. To upload this program to the flash memory of the ESP8266 we simply click the Upload button on the left side (the big arrow icon below the Build icon) or use the PlatformIO -> Uplaod menu entry. Obviously you should have connected the board first and make sure the driver is installed and the board recognized. After a successful upload, you should see the blue LED flash at a one second interval and if you start the serial monitor (click the 'plug icon' on the left side or select the PlatformIO -> Serial menu entry) you can see the Hello World messages appear, every other second.

Congratulations, you now have a powerful IoT development environment up and running!

Atom extensions

Extensibility of Atom through packages is a key feature of Atom, so we definitely should look at some interesting packages, besides PlatformIO, that could make our developer's life easier or more fun. Out of the box, Atom comes with several plugins installed already. And by installing some interesting add-ons you get a even more productive platform. More on that in another blog post.

Add a comment

Next Post Previous Post

Add a comment