Today we will see how to program Espressif ESP32 microcontrollers with the PlatformIO IDE (PIO). If you discover PlatformIO, you can start by reading this first article that explains step by step how to install and start. Support for new ESP32 boards by the Arduino IDE requires installation and configuration work (all steps in detail in this article). PIO, he takes care of everything!
Which ESP32 card to choose to start
The price of ESP32 boards has fallen sharply in recent times. It is happy because the competition is tough compared to the Raspberry Pi Zero W offers around 11 €. Now we find development boards about €7. Generic boards are very well supported by the Espressif SDK.
If you prefer to stay on cards supported natively by the SDK, the Wemos LoLin32 4MB is an excellent choice. Wemos is now a recognized manufacturer that offers quality cards at a very reasonable price. The LoLin32 has been presented in this article.
You can also read this more detailed article on the subject.
Preparing the PlatformIO environment
If you’re starting out with PlatformIO, start by reading this article that explains step by step installation as well as the basics of operating the environment. Launch Atom to begin your development.
Create a new project for ESP32
PIO is very flexible. It is possible to add a development card to a current project, it is the great strength of PlatformIO, or simply create a blank project. It’s the same option that serves everything. Select the Initialize or Update PlatformIO Project option from the menu or from the sidebar.
Select your development card. If you are using a generic card (for example the Geekcreit Doit), choose Espressive ESP32 Dev Module from the list. To add this card to an existing configuration, select it from the list. Otherwise, click Other and specify the folder where PIO should create the project tree.
Finally, click Process. PlatformIO takes care of recovering and installing the Espressive SDL for the ESP32 modules. This is the magic of PlatformIO. If you have started programming with the Arduino IDE, you must understand me, otherwise read this article.
Once the SDK is installed, PIO creates the project structure as well as the platformio.ini file
Arduino code: flashing a Led
PIO creates the project tree and automatically creates the platformio.ini configuration file. On the other hand it is up to us to create the first Arduino file. To do this, right click on the scr folder and choose New File.
Give the file a name by giving it the .cpp extension
For the program to work, you must include the Arduino.h library at the beginning of the program! And yes, it is necessary to indicate to PIO that the target must execute code Arduino.
Then, the programming is identical to the Arduino IDE. Here is a small program that flashes a LED connected to pin 15 of the ESP32. It is perfectly identical to the code of ESP8266 presented in the previous tutorial. The only difference is the number of the spindle. Pin No. 15 does not exist on ESP8266. It’s cool to have so many I/O!
* Demo PlatformIO - ESP32 - 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 15
// 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
Adapt the code to your needs and save it (CTRL + S). Then choose Build from the menu (or use the dedicated icon).
You can follow the progress of the compilation by flying over the toothed wheel in the lower right corner of Atom.
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
And then, we trace the course of the program for any other card as on the Arduino IDE.
- 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