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
Go to this page then download the version of Atom that corresponds to your environment
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:
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.
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 !.
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.
In 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 uses Clang for self-completion of commands. This installation is optional.
- macOS X: Install the latest version of Xcode
- Windows: Download Clang 3.9.1 for Windows and select the option “Add LLVM to the system PATH”
- Linux: Execute the command apt-get install clang or yum install clang
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.
Click Process. PlatformIO will retrieve all necessary dependencies and resources for the selected adapter. This is the magic of PlatformIO.
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
│ └── readme.txt
Let’s take a closer look at the file platformio.ini
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.
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.
Give the file a name by giving it the .cpp extension
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.
* Demo PlatformIO - ESP8266 - Blink a Led
* Turns on an LED on for one second, then off for one second, repeatedly.
* projetsdiy.fr - diyprojects.io
#define LED_BUILTIN 4 //or D2 but display an error
// initialize LED digital pin as an output.
// turn the LED on (HIGH is the voltage level)
// wait for a second
// turn the LED off by making the voltage LOW
// wait for a second
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.
Now open the serial monitor. Directly from the menu, via the keyboard shortcut Alt + Shift + M or from the icon bar.
Select the COM port on which the card is connected and the speed
You can trace the progress of your programs as on the Arduino IDE.
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!
- Deviot, the Sublime Text 3 PlatformIO package for PC recycled under 32-bit Linux
- Install the IDE PlatformIO extension for Visual Studio Code (VSCode): Windows, 32-bit Linux
- Getting start programming the ESP32 with the PlatformIO IDE
- Start with PlatformIO, the alternative IDE for Arduino, ESP8266, ESP32 and other microcontrollers