Category: platform io


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.

 

Image 36

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.

Image 37

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.

 

Image 40

 

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.

Image 6

 

error

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.

Image 8

Finally I got the solution from Plaform IO forum.

Just DELETE the folder .vscode under Explorer.

 

Image 26

Right click .vscode folder & just DELETE it.

Image28

 

Image29

 

Now close the VS code & restart again .

The Squiggles are gone & new .vscode folder is automatically created.

 

Image 30

Now Intellisense regarding Arduino.h is working Fine

Image 35

 

 

Image 10

 

blog_image

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.

clip_image002         clip_image004          clip_image006

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.

image

 

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

https://www.python.org/

 

clip_image002[4]

Select the version 2.7.xx to install & not the 3.7.xx version.

2.7 version best supports Platform IO.

 

clip_image004[4]

 

 

clip_image006[4]

 

While installing Python , ensure that you enable ADD PYTHON.EXE to PATH & entire feature is installed on your local hard drive.

 

 

clip_image002[6]

clip_image004[6]

Finish the PYTHON installation & start with VS CODE installation.

 

 

clip_image006[6]

 

 

 

clip_image008   clip_image010

 

Ensure to tick mark ADD TO PATH during installation.

 

clip_image012

 

 

clip_image014  clip_image016

 

Once the installation is over , click FINISH to launch VS CODE.

A dark IDE APPEARS  after a while.

clip_image018

TO the left side of IDE you see a list of control Icons.

clip_image022

Click on EXTENSIONS ICON  to visit the market place add on s.

clip_image020

 

A new search bar appears , where you type in PLATFORM IDE.

Select the PLATFORM IDE & click on the green INSTALL button.

 

clip_image024

 

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).

clip_image026

At the bottom of IDE PLATFORM IO control Icons appear.

 

clip_image028

 

 

 

clip_image030

If you prefer a light skin , go to File –> Preferences & click on Color Theme.

 

clip_image032

 

From the list of Skins you can select a light skin .

 

clip_image034

You need to click on Platform IO Home button for the new skin to be effective.

 

clip_image036

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.

clip_image038

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.

 

clip_image040

 

Now under the left side Explorer window , the new Project (led_blink) appears

clip_image042

Locate the folder src , under which you find main.cpp file.

Click on it.

 

clip_image044

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.

 

clip_image046

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.

 

clip_image048

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.

 

clip_image049

 

 

clip_image051

 

While Upload is in progress PRESS & HOLD the BOOT button on ESP32 .

 

clip_image053

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/

 

Image 25

 

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.

Image27

At the bottom add this line

monitor_speed=115200

where 115200 is the new Baud rate.

 

image

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);

 

Image 33

 

Click on main.cpp & replace 9600 with 115200.

 

 

Image 34

 

image

Save the file & upload again.

Open the Serial monitor to see the LED ON OFF message with new baud rate 115200..

 

VIDEO SUPPORT :

 

blog_image