It Turned Black! VS Code

by Fernando Koyanagi in Circuits > Microcontrollers

2202 Views, 4 Favorites, 0 Comments

It Turned Black! VS Code

1.png
A coisa ficou preta! VS Code

Today, we’ll talk about PlatformIO. This is an advanced tool with several features that “link” its use to Visual Studio Code. I consider this topic somewhat advanced, and thus, I suggest using this pair for codes that have more than 200 lines. But, that's just my opinion. To explain this better, for compiling a microcontroller, the VSCode extension (PlatformIO) accesses the Arduino framework that is installed on your computer.

Moving along, today we are going to deal with the qualities of VS Code, its installation, as well as the extension for the VS Code. Also, we'll have a brief explanation of the PlatformIO home interface, the tools, and the creation of a project from scratch, such as importing an Arduino project (.ino) into PlatformIO.

Software and Files Used

4.png

• Arduino IDE software (must be previously installed)

• Visual Studio Code Software

• PlatformIO Extension for VSCode

• Sample .ino .h and .cpp files for ESP32

Note: We will use the INO code of a project that was made with ESP32 LoRa. To function properly, the Arduino core for ESP32 must be pre-installed for the ESP32 example project that we import.

In other words, if you do not have the ESP32 libraries installed in the Arduino IDE and cannot compile within the Arduino IDE itself, you will not be able to compile the project imported into PlatformIO.

Qualities of the VSCode Editor

5.png
6.png
7.png
8.png

VS Code has several qualities. It runs on Mac, Linux, and Windows. Thus, it is open, and it is from Microsoft. Some of the other qualities include:

• Hide / display code blocks

• Detection of code errors during writing

• Auto complete (ctrl + space) for variables and methods

• Source code minimap

• Git Integration

• Peek

• Code Navigation (navigate to the setting)

Download Visual Studio Code

9.png

​Visual Studio Code Installation

10.png

• Run the installer

• Click Ok

• Follow the installation by clicking Next to Finish

Installing the PlatformIO Extension

13.png
15.png
14.png

1. Open Visual Studio Code as an administrator

2. Follow the steps below

Note: It is recommended that you log on to the computer as an administrator user

Click the button indicated by the arrow

Search for PlatformIO, in accordance with the image.

Click one of the buttons to install and wait for the installation...

Reload to restart the IDE

Wait for the installation...

Brief Explanation of the PlatformIO Home Page

16.png

After restarting the VS Code,

the extension will then already be installed and a flap will open, depending on the image.

1. New project.

2. Import Arduino project.

3. Open an existing project.

4. Open project examples.

Creating a New Project

17.png
19.1.png
19.2.png
20.1.png
20.2.png

1. Name of the project.

2. Plate used.

3. Framework.

4. Location where the project will be saved.

The default is located at C: \ Users \ User \ Documents \ PlatformIO \ Projects.

Choose a name for the project and search for the board that is being used by typing in the Board field.

Choose the framework that will be used. We will use the Arduino framework.

If you choose to save the project to a specific folder, uncheck the Location checkbox and select the location you want. In our example, we will leave it as the default location, in accordance with the image.

Click Finish to complete the project creation.

Main Project File

21.png

The main.cpp file is located in the src folder, depending on the image.

You can insert libraries (.h) into the src folder itself and import them into quotation marks.

Example: #include "LibESP32.h"

PlatformIO Toolbar

22.png

1. Errors and warnings

2. Home

3. Build (Build)

4. Upload (Record / Upload)

5. Upload to remote device

6. Clean

7. Test (Test)

8. Run Task (Opens a search field to search and execute, in addition to other tasks such as Upgrade installed platforms, Debug, Upload, Monitor, etc ...)

9. Serial Monitor (Opens the serial monitor)

10. New Terminal (Windows PowerShell)

Importing an Arduino Project (.ino) Into the PlatformIO

23.png
24.png

NOTE: We will use the INO code of a project made with ESP32 LoRa, but it can be imported to any other Arduino IDE-compatible board, such as STM, ESP, Arduino, etc.

Importing an ESP32 .ino Project to the PlatformIO

25.png
26.1.png
26.2.png

Look for the plate used. In our example, we are using the Heltec WiFi LoRa 32 card.

Check the Use libraries option. Select the project location with the .ino and .h files. Click Import.

Wait Until the Platform IO Home Opens

27.png

The source files will be located in the src folder. Compile, load, and debug (Serial monitor).

Done!

28.png

Notes and Warnings Regarding the PlatformIO Extension

29.png

• It’s dependent on the Arduino framework.

• Recompiling a project requires the serial monitor to be manually disconnected / closed (the Arduino IDE automatically disconnects).

• Do not install the Arduino through the Microsoft application store because it will not be located by the VS Code.

LoRa Project Used As an Example of Import

As a conclusion, I advise you to watch the video: ESP32 LORA: GAS SENSOR, MOISTURE AND TEMPERATURE BY SMS. In the video, I used the same code as I used in this project today.

Download the Files