PlatformIO is an opensource ecosystem (as it’s defined in the homepage of the project) to develop IoT projects.
The heart of the platform is a software component named PlatformIO Core. This component includes:
- a cross-platform compiler
- a libraries and dependences manager
- a serial monitor
PlatformIO Core is developed in Python and therefore it can run on different operating systems (Windows, Linux, MacOS).
Although you can use the Core component directly, PlatformIO’s strength lies in its IDE, which allows the development of multi-platform projects and integrates with the Core itself.
In this article I’m going to show you how to use PlatformIO to develop projects running on the esp32 chip.
PlatformIO IDE is provided as a plugin for two different development tools: Atom and VisualStudio Code. I tried both solutions and I preferred VSCode: both the installation and the use are simpler and more immediate.
Install VSCode after having downloaded the package from Microsoft’s website (the installer is available for Windows, Linux and MacOS).
Open the Package Manager:
search the PlatformIO IDE package, then click on Install:
wait until the installation is complete:
Now it’s time to develop your first program, which traditionally will display the sentence Hello world! on the terminal.
If it doesn’t show up automatically, open the PlatformIO’s homepage:
then click on New Project:
give a name to the project and choose a devboard based on the esp32 chip (in this example I’ll use a Lolin32 board by Wemos). PlatformIO supports both the esp-idf framework and the arduino-esp32 one. All my tutorials are based on the first one:
PlatformIO automatically creates some folders for your project. Choose the src folder (it stands for source, that is the folder which will contain the source code) and create a new file:
name the file main.c and type the simple program as it follows:
run the compiler by clicking on the corresponding button in the bottom bar:
the editor displays an error… indeed your code is using the printf() function without having included the library:
add the missing line, now you should be able to complile the code without errors:
PlatformIO can also upload the compiled program to your board. Thanks to its auto-detect feature, you usually don’t need to specify the serial port the board is connected to:
PlatformIO also includes a serial monitor you can use to test your program. By default, this monitor connects to the serial port with a speed of 9600 baud. The esp32 chip instead has a default speed of 115200 baud; you have therefore to change the platformio.ini file included in your folder as it follows:
Now open the serial monitor; you should see the correct output of your program:
I found the use of PlatformIO really immediate: after a few minutes I was able to develop, compile, load and test a program. Try it and leave a comment with your impressions!