Getting start programming the ESP32 with the PlatformIO IDE

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp
drapeau france
level advanced
esp32 geekcreit wroom

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.

esp32 geekcreit wroom

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.

wemos lolin32 esp-wroom-32 espressif top view

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.

platformio 3 atom home screen update

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.

platformio esp32 init project

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.

platformio esp32 2 choose board

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

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.

platformio esp32 3 install espressif sdk

Once the SDK is installed, PIO creates the project structure as well as the platformio.ini file

platformio esp32 4 project structure 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.

platformIO 9 new cpp file

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

platformIO 10 new cpp file path

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.
 * -

#include <Arduino.h>

#define LED_BUILTIN 15

void setup()
  // initialize LED digital pin as an output.

void loop()
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, 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).

platformio esp32 build

You can follow the progress of the compilation by flying over the toothed wheel in the lower right corner of Atom.

platformio esp32 6 building

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 esp32 7 serial monitor

And then, we trace the course of the program for any other card as on the Arduino IDE.

platformio esp32 8 serial monitor

Click to rate this post!
[Total: 0 Average: 0]

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
Ask your question

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

We will be happy to hear your thoughts

      Leave a Reply

      DIY Projects