ESP32. Getting started coding with PlatformIO IDE and Arduino code

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp
Table of Contents

PlatformIO (PIO) is an alternative code editor to the Arduino IDE that is installed as a plugin for many more general-purpose code editors. PlatformIO allows the development of most micro-controllers on the market and in particular the ESP32 from Espressif.


Before starting

Before you begin, you must have installed the PlatformIO plugin for the favorite code editor. Here we will be using VSCode. The installation process and the tools offered are similar from one publisher to another.

Import an existing arduino project on platformio pio

If you are new to PlatformIO, start by reading this article which explains step by step the installation as well as the basics of operating the environment.

Read Also
Getting started with PlatformIO IDE on VSCode (Windows, macOS, Raspbian, Linux)

Create a new ESP32 project

PIO is very flexible. It is possible to add a development board to a current project, this is the great strength of PlatformIO, or simply create a blank project. It’s the same option that is used for everything. Select the Initialize or Update PlatformIO Project option from the menu or from the sidebar.

Select your development board. If you are using a generic ESP32 board, choose Espressive ESP32 Dev Module from the list. To add this board 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 demo: 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 board is connected and the speed

platformio esp32 7 serial monitor

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

platformio esp32 8 serial monitor

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

Thanks for your reading

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

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
We will be happy to hear your thoughts

      Leave a Reply

      Read more
      Recent posts on the Forum
      DIY Projects
      DIY Projects