In this tutorial, we will learn how to program ThingHz ESP32 boards using VS Code and PlatformIO IDE extension. We will be going through the following:
- Installing VS code in windows.
- Installing Python on windows.
- Installing PlatformIO IDE Extension on VS Code
- VS Code and PlatformIO IDE Overview
- Downloading ESP32 boards and library in PlatformIO IDE
Installing VS Code
go to https://code.visualstudio.com/download and click on system installer to download it for windows.
Accept the agreement and press the Next button
Select the following options and click Next.
Press the Install button.
Finally, click Finish to finish the installation.
Installing Python on windows
To program the ESP32 and ESP8266 boards with PlatformIO IDE we need ESPTool that has a python dependency. So you need to install Python 3.5 or higher.
Go to python.org/download and download the latest version
No the next page click on windows installer to download for 32 bit or 64bit windows
Installing PlatformIO extension on VSCode
- Click on the Extensions icon on the left navigation tab to open the Extensions tab
- Search for “PlatformIO IDE”
- Click on the Install button to Install platformIO extension.
4. After installing platformIO icon should show up on the left navigation tab. Click on it then click on Open on the left navigation panel to open PlatformIO Home. You can also go home by clicking on the home icon on the bottom navigation tab. If you don’t see the PlatformIO icon and the quick tools at the bottom, you may need to restart VS code for the changes to take effect.
Getting started with Blinking LED on ThingHz ESP32 blinking LED using PlatformIDE
Here we will flash the blinking LED project to ESP32 to get an overview of PIO.
Give your project a name like here we have given ESP32BlinkingLED and select the board we are using DOIT ESP32 DEVKIT V1. The Framework should be “Arduino” to use the Arduino core.
You can choose the default location to save your project or a custom location.
The default location path for PIO projects is Documents >PlatformIO >Projects. Check the checkbox to choose the default location. Finally, click “Finish”.
Platform IO project structure
On the left side navigation tab click on top most Explorer icon. On the left navigation panel you can see the project structure which is different from arduino IDE. The platform IO project structure consists of following files
- .pio directory: This contains ESP32 build files
- .vscode: This directory contains three json files
- c_cpp_properties.json: This contains all the include paths of the projects.
- extensions.json: This contains estension information like in our case it is platformio.platformio-ide
- launch.json: this contains startup configuration, like setting up of board environment and tool chain.
- src: this contains main.cpp
- platform.ini: This contains configuration file of your project like platform, board information and framework information
Add following line to set up the baudrate in platform.ini
monitor_speed = 115200
Compiling and Uploading the code to ESP32
First go to src folder and edit main.cpp with blinking LED code.
Click on the Upload icon in the botton navigation tab to compile and upload the code. Alternatively, you can go to the PIO Project Tasks menu and select Upload.
Press the Boot(1) button on your ThingHz ESP32 board to upload the program. Then Press Reset(2)
After successful upload , you should get the following message.
Adding Libraries to PlatformIO IDE
- To add extrnal library to the project, Go to PIO home and click on Libraries icon
- Search for the library
- Click on the library you want to include in your project. Then, click Add to Project.
- Select the project were you want to use the library.
- Go to platform.ini folder and you will find it there in lib_deps.
- Alternatively you can directly copy and paste the lib_deps to the platform.ini from the Installation tab
If you need multiple libraries, you can separate their name by a coma or put them on different lines. For example:
adafruit/Adafruit SHT31 Library@^2.0.0
me-no-dev/ESPAsyncTCP @ ^1.2.2
We hope you’ve found this Getting started with VSCOde and PlatformIO guide useful. Next, you will learn about getting started with Arduino IDE and ESP32. Stick to ThingHz for more upcoming IoT projects. Keep Learning.