Start with PlatformIO, the alternative IDE for Arduino, ESP8266, ESP32 and other microcontrollers

PlatformIO IDE is a development environment that can replace the traditional Arduino IDE. PlatformIO supports more than 400 development cards for the main microcontrollers (Atmel AVR, Espressif ESP8266 and ESP32, STMicro STM32, Teensy …). It is not a simple code editor, it is a true development platform that targets the professional market with very powerful tools. For example, it is possible to test the code on different microcontrollers, to deploy the updates remotely via the Internet. It is a solution that addresses the company with a paid offer. PlatformIO is perfectly usable for recreation or learning with a free version (Community) allows to use almost all functions with certain limitations. For example, it is not possible to make more than 50 remote updates (OTAs) per month. This is enough for personal use, start a small business venture or school. The fee schedule is available here.

Installing PlatformIO on MacOS, Windows or Linux

The PlatformIO IDE is an overlay that is added to a code editor or text editor. PIO is offered by default as an Open Source Atom Text Editor package developed by GitHub. Atom is fully developed in Javascript (the language of the Web) and compiled with the help of Electron. Electron is a compiler that allows to create cross-platform applications. The same javascript source code can be compiled to build a Windows, MacOS, Linux application.

platformio web site

Go to this page then download the version of Atom that corresponds to your environment

platformio 1 install atom

On macOS, simply unpack the archive and move Atom to the Applications folder. For Linux, only regret, the 32-bit version is no longer supported. It is therefore no longer possible to recycle a (too) old PC to turn it into a development platform.

Installing the PlatformIO package in Atom

Once Atom is installed, you must install the PlatformIO package. Open the preferences. Depending on your operating system, the path is different

  • Windows, Menu: File> Settings> Install
  • macOS, Menu: Atom> Preferences> Install
  • Linux, Menu: Edit> Preferences> Install

In the search box, type platformio-ide. There are 3 packages available:

  • platformio-ide
  • platformio-ide-terminal
  • platformio-ide-debugger

Install the ide and ide-terminal packages by clicking Install. The installation is silent but you can follow it by flying over the toothed wheel in the lower right corner of the screen. The installation can last a few minutes depending on your internet speed. Stay on this page until the package is marked as installed.

platformio 2 atom install packages

When installation is complete, a new PlatformIO Home tab is added to Atom. This tab can be opened automatically when Atom starts and allows you to manage your projects and update the PlatformIO package and Core. If a new version is available (here version 3.3.1), take advantage of it to update before continuing by clicking on Upgrade NOW !.

platformio 3 atom home screen update

The PlatformIO menu and toolbar

A new menu is also added to the Atom menu bar. If you close the Home screen, do not panic, you can re-open it from the menu >> Home Screen.

platformIO 1 menu atomIn menu contains the following options

  • Home Screen: open the home page
  • Projects Example: Creates a new project from examples for supported platforms
  • Initialize or Update Project: Allows you to add a platform to an existing project. Resources are downloaded and installed
  • Import Arduino IDE Project: imports an existing Arduino project
  • Open Project folder: opens the project directory in the file manager (or Finder on macOS)
  • Build: compile code before upload
  • Upload: upload the code to the microcontroller
  • Clean: Removes the hidden .pioenv folder that contains all the compiled versions.
  • Test: Test the code for all target platforms. Function not available for the free Community version.
  • Run other target: Choose the target. PlatformIO only detects the connected card and uploads the corresponding code. In this case, you can choose the card (for example if several cards are connected to the machine), or send files to the SPIFFS memory area (contents of the Data folder)
  • Toggle Build Panel: Displays or hides the Terminal
  • Terminal: Opens Terminal on MacOS, Linux, Raspberry and Power Shell on Windows 10
  • Library Manager: an information page that explains how to manage libraries. Everything is done in command line (further on)
  • Serial Monitor: Opens the serial monitor. On Windows, a Power Shell session is launched.
  • List Serial Ports: lists USB connected devices that can communicate over the serial port
  • Update: you can directly update the PlatformIO Core, the packages and the libraries used
  • Settings: a shortcut to access the Atom settings and packages
    All these functions also take the form of a sidebar icon. The icon bar can be placed at the top, bottom, left or bottom.

platformIO 1b barre laterale atom

Install Clang

PlatformIO uses Clang for self-completion of commands. This installation is optional.

New project ESP8266 with PlatformIO

We will now create a small ESP8266 project to understand how the environment works. Compared to the Arduino IDE, PlatformIO sets up a more complex file structure. With the Arduino IDE, just create a new sketch to start a new project. With PlatformIO, it’s not that simple. PlatformIO works with a tree that contains the source code (src), the libraries, the configuration file … Fortunately, there is a tool to prepare all this. Open the menu and select Initialize or Update PlatformIO Project.

This dialog box does two things:

  • Add a target (a development map) to an existing project
  • Or create a new project tree.

Creating the project structure

To create a new project, select the desired map from the list. You can enter the first few letters to find it easier. Then click Other to the right of the path entry field and select the destination directory.

platformIO 5 nouveau projet board

Warning. Compared to the Arduino IDE, you must create the root folder. Otherwise, the tree and files will be added to the specified level.

Click Process. PlatformIO will retrieve all necessary dependencies and resources for the selected adapter. This is the magic of PlatformIO.

platformIO 7 init project esp8266

For example, if you want to develop with the new ESP32 boards, you will have nothing to install compared to the Arduino IDE. It is a real comfort. The first time you use a card, you must allow PIO a little time. It must download the resources, install them and in some cases compile.

Here is the resulting projects structure

project_dir
├── lib
│   └── readme.txt
├── platformio.ini
└── src
    └── main.cpp

platformIO 8 arborescence project

Let’s take a closer look at the file platformio.ini

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino

For the moment, it contains only the d1 mini target (Wemos d1 mini). At any time, you can add a target map by running the Initialize or Update PlatformIO Project tool again (recommended) or manually. In this case, all cards are listed here. We will see in more detail all the other options available in an upcoming tutorial.

Arduino Code

Now we have to create our first program. No base file is added. You have to do it yourself. To do this, right click on the scr folder and choose New File.

platformIO 9 new cpp file

Give the file a name by giving it the .cpp extension

platformIO 10 new cpp file path

To run on Arduino, ESP8266, ESP32, you must include the Arduino library at the beginning of the program!

Then, the programming is identical to the Arduino IDE. Here is a small program that flashes a LED connected to the D2 pin of the ESP8266.

[ads1}

/*
 * Demo PlatformIO - ESP8266 - Blink a Led
 * Turns on an LED on for one second, then off for one second, repeatedly.
 * projetsdiy.fr - diyprojects.io
 */

#include <Arduino.h>

#define LED_BUILTIN 4  //or D2 but display an error

void setup()
{
  // initialize LED digital pin as an output.
  Serial.begin(115200);
  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);
  Serial.println("Blink");
   // wait for a second
  delay(1000);
}

Some remarks about the Arduino IDE

  • Error detection is performed after each backup (CTRL + S)
  • The use of pin marking following the Espressive convention (D2 instead of 4) generates an error but works perfectly
  • It is not necessary to re-compile the code between two uploads (time saving)

Adapt the code to your needs and save it (CTRL + S). Then choose Build from the menu (or use the dedicated icon).

Once the compilation is complete, upload the program.

platformIO 12 upload project

Now open the serial monitor. Directly from the menu, via the keyboard shortcut Alt + Shift + M or from the icon bar.

platformIO 13 open serial monitor

Select the COM port on which the card is connected and the speed

platformIO 14 choice port serial monitor

You can trace the progress of your programs as on the Arduino IDE.

platformIO 15 serial monitor

This completes this first tutorial to discover the PlatformIO development environment. A bit confusing the first time, PIO has many arguments in its favor. Completed the installation of the libraries, the resources of the cards. PIO takes care of everything!

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

DIY Projects