In the previous post we have seen the installation of PLATFORM IO on VS CODE.
While connecting the ESP32 to PC the PLATFORM IO detects AND ASSIGNS the COM port automatically.
To see the COM port click on DEVICES icon.
Refresh button can be pressed if new connection is made.
If more than one COM port is listed , then you can select the COM port manually.
In this demo ,I ‘ve connected another USB-TTL device with CP2102. To another USB port ESP32
is connected.
Click the Refresh button under DEVICES to view all the COM Ports.Here COM5 is allotted to ESP32 &
COM21 to USB-TTL device.
TO SELECT COM port 5 Manually, open the platform.ino file.
Add this line at the end.
upload_port=COM5
Save & upload code to see COM port 5 selected & used.
Now let us see the solution for the error we encountered in previous post.
Under Arduino.h we received a Squiggle red line indicating error & Intellisense regarding Arduino core was not effective. Arduino.h file was not recognized.
If you move the cursor over the Squiggles you see a balloon.Clicking on this shows some solution for the problem.But this was not successful.
Finally I got the solution from Plaform IO forum.
Just DELETE the folder .vscode under Explorer.
Right click .vscode folder & just DELETE it.
Now close the VS code & restart again .
The Squiggles are gone & new .vscode folder is automatically created.
Now Intellisense regarding Arduino.h is working Fine
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..