1.2 Install PlatformIO
Last updated
Last updated
Go to and download the stable build for your operating system.
Go to and download Python 3.8.5 or a newest version.
It is possible to program the ESP32 and ESP8266 boards using VS Code with the PlatformIO IDE extension. Follow the next steps to install the PlatformIO IDE extension.
Open VS Code:
Click on the Extensions icon or press Ctrl+Shift+X to open the Extensions tab
Search for “PlatformIO IDE”
Select the first option
Finally, click the Install button (Note: the installation may take a few minutes)
After installing, make sure that PlatformIO IDE extension is enabled as shown below.
After that, the PlatformIO icon should show up on the left sidebar as well as an Home icon that redirects you to PlatformIO home. Restart VS code for the changes to take effect.
At the bottom of the IDE, there’s a blue bar with PlatformIO commands. From left to right:
PlatformIO Home
Build/Compile
Upload
Clean
Serial Monitor
New Terminal
If you hover your mouse over the icons, it will show what each icon does. Alternatively, you can also click on the PIO icon to see all the PlatformIO tasks. You may need to click on the three dot icon at the top and enable PlatformIO tasks as shown below.
On VS Code, click on the PlartfomIO Home icon. Click on + New Project to start a new project.
Give your project a name (for example Blink_LED) and select the board you’re using. The Framework should be “Arduino” to use the Arduino core.
The default location is in this path Documents >PlatformIO >Projects. Finally, click “Finish”. The Blink_LED project should be accessible from the Explorer tab.
VS Code and PlatformIO have a folder structure that is different from the standard .ino project. If you click on the File Explorer tab, you’ll see all the files it created under your project folder. It may seem a lot of files to work with. But, don’t worry, usually you’ll just need to deal with one or two of those files.
The platformio.ini file is the PlatformIO Configuration File for your project. It shows the platform, board, and framework for your project. You can also add other configurations like libraries to be included, upload options, changing the Serial Monitor baud rate and other configurations.
platform: which corresponds to the SoC used by the board.
board: the development board you’re using.
framework: the software environment that will run the project code.
monitor_speed: set the baud rate. The default baud rate used by PlatformIO is 9600. However, it is possible to set up a different value.
In this file, you can also include the identifier of libraries you’ll use in your project using the lib_deps
directive, save that file if you make any changes.
Under the src folder, there’s a main.cpp file. That’s where you write your code. Click on that file. The structure of an Arduino program should open with the setup() and loop() functions.
After writing code, press Ctrl+S or go to File > Save to save the file. Now, you can click on the Upload icon to compile and upload the code. Alternatively, you can go to the PIO Project Tasks menu and select Upload.
If the code is successfully uploaded, you should get the following message. Now, click on the Serial Monitor, and if you don’t see the Terminal window, go to the menu Terminal > New Terminal.
PlatformIO will automatically detect the port your board is connected to. To check the connected devices you can go to the PIO Home and click the Devices icon.
If you try to upload a new sketch to your ESP32 and you get this error message “A fatal error occurred: Failed to connect to ESP32: Timed out… Connecting…“. It means that your ESP32 is not in flashing/uploading mode. Having the right board name and COM por selected, follow these steps:
Hold-down the BOOT button in your ESP32 board
Press the Upload button in the Arduino IDE to upload your sketch
After you see the “Connecting….” message in your Arduino IDE, release the finger from the BOOT button
After that, you should see the “Done uploading” message You’ll also have to repeat that button sequence every time you want to upload a new sketch.
If you get the error “COM Port not found/not available”, you might need to install the CP210x Drivers
Click the Home icon to go to PlatformIO Home. Click on the Libraries icon on the left side bar. Search for the library you want to install. For example Adafruit_BME280. Click on the library you want to include in your project.
Click Add to Project. Select the project that you want to use the library.
This will add the library identifier using the lib_deps
directive on the platformio.ini file. If you open your project’s platformio.ini file, it should look as shown in the following image.
Alternatively, on the library window, if you select the Installation tab and scroll a bit, you’ll see the identifier for the library. You can choose any of those identifiers depending on the options you want to use. The library identifiers are highlighted in red.
Then, go to the platformio.ini file of your project and paste the library identifier into that file, like this:
If you need multiple libraries, you can separate their name by a coma or put them on different lines. For example:
VS Code with the PlatformIO IDE extension is a great alternative to the classical Arduino IDE, especially when you’re working on more advanced sketches for larger applications.
Here’s some of the advantages of using VS Code with PlatformIO IDE over Arduino IDE:
It detects the COM port your board is connected to automatically;
VS Code IntelliSense: Auto-Complete.
Error Highlights: VS Code + PIO underlines errors in your code before compiling;
Multiple open tabs: you can have several code tabs open at once;
You can hide certain parts of the code;
Advanced code navigation;
And much more…
If you’re looking for a more advanced IDE to write your applications for the ESP32 boards, VS Code with the PlatformIO IDE extension is a great option.