In previous posts we programmed ESP32 by Arduino IDE .This post is on a More powerful and advanced IDE
Platform IO installed over VISUAL STUDIO CODE .
VS CODE is a lightweight but powerful source code editor which is available for Windows, macOS and Linux.
https://code.visualstudio.com/docs/?dv=win
VS Code is an advanced Text Editor on which we install PLATFORM IO EXTENSION and use it as IDE to program ESP32 .
The Platform IO is a Python based open source ecosystem for IoT development and a cross platform IDE with a unified debugger .
The PlatformIO supports many Platforms, Frameworks, Boards like Arduino, ESP32, ESP8266,STM32,NUCLEO and includes examples and libraries.
Instead of VS CODE , we can use ATOM Text editor .
But ATOM editor requires CLANG installation for Code completion facility.
Platform IO on VSCODE is the next generation IOT IDE which supports programming of a wide range of boards like Arduino, ESP32,STM32 & NUCLEO.
Visit this link for a detailed comparison between ATM & VS CODE Editors
https://platformio.org/platformio-ide
VS CODE has advanced
Intelligent Code Completion , Smart Code Navigation & Code Formatting
Advanced Debugging tools like
Conditional Breakpoints , Expressions and Watchpoints
Memory Viewer , A hot restart of an active debugging session
As VS CODE offers key features, let us proceed with VS CODE installation.
Download the Windows installer suitable for your PC ( 32 or 64 bit).
Before starting the VSCODE installation, ensure that your PC has PYTHON.
Visit this link to download Python
Select the version 2.7.xx to install & not the 3.7.xx version.
2.7 version best supports Platform IO.
While installing Python , ensure that you enable ADD PYTHON.EXE to PATH & entire feature is installed on your local hard drive.
Finish the PYTHON installation & start with VS CODE installation.
Ensure to tick mark ADD TO PATH during installation.
Once the installation is over , click FINISH to launch VS CODE.
A dark IDE APPEARS after a while.
TO the left side of IDE you see a list of control Icons.
Click on EXTENSIONS ICON to visit the market place add on s.
A new search bar appears , where you type in PLATFORM IDE.
Select the PLATFORM IDE & click on the green INSTALL button.
Installation takes a while & finally the PLATFORM IO ICON appears.
The first initialization requires Internet connection and may take a while(need to install dependent toolchains, frameworks, SDKs).
At the bottom of IDE PLATFORM IO control Icons appear.
If you prefer a light skin , go to File –> Preferences & click on Color Theme.
From the list of Skins you can select a light skin .
You need to click on Platform IO Home button for the new skin to be effective.
At the center of IDE you can see some PLATFORM IO icons to add Libraries , Boards , Platforms& Devices
Under QUICK ACCESS list click on + New Project to create a new one.
You can also click on Project examples or Import Project to download one.
Provide a name to the project.
Against Board , search for ESP32 & select the correct board you’re using.Mine is DO IT ESP32 DEVKIT V1.
Against Framework select ARDUINO.
Click OK to create the Project.
Now under the left side Explorer window , the new Project (led_blink) appears
Locate the folder src , under which you find main.cpp file.
Click on it.
Here is where you write your code.
The code starts with #include <Arduino.h>
If you find a squiggle under line beneath it , then the path to header file is not defined.
The solution to this problem is explained in next post.
For now, proceed with the code.The squiggle indicates error & Intellisense regrading Arduino core will not show up.But you can complete typing the code & upload.Everything else works fine.
Let us blink the inbuilt LED on board ESP32 which is mapped to GPIO2.
While typing the code you can see the Code completion in action , which is handy while working on big projects.You need not remember the variables & functions declared.
Click on the tick mark at the bottom row of icons to Build or Compile the code.
Or you can directly click on ARROW button to upload the code.
While Upload is in progress PRESS & HOLD the BOOT button on ESP32 .
Once the code is uploaded , you can see the on board Blue LED blinking.
Now let us explore the Serial monitor capability of the IDE.
Under setup() add
Serial.begin(9600);
The default baud rate is 9600.
Under loop() function Serial.println the message LED ON or LED off.
Upload the code & then click on the PLUG symbol seen at the bottom row of Icons.
Now the Serial monitor opens displaying the LED ON OFF message/
To change the BAUD RATE , click on platformio.ini file under project files.
At the right side you see the platform,board & framework setting we selected while creating the project.
At the bottom add this line
monitor_speed=115200
where 115200 is the new Baud rate.
Now save the file & upload.
Open the Serial monitor (PLUG symbol) to see some garbage message printed.This is because the IDE Serial monitor baud rate has been changed to 115200, but in code we have initiated
Serial.begin(9600);
Click on main.cpp & replace 9600 with 115200.
Save the file & upload again.
Open the Serial monitor to see the LED ON OFF message with new baud rate 115200..
VIDEO SUPPORT :