Introduction: It Turned Black! 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.
Step 1: Software and Files Used
• 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.
Step 2: Qualities of the VSCode Editor
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
• Code Navigation (navigate to the setting)
Step 3: Download Visual Studio Code
Step 4: Visual Studio Code Installation
• Run the installer
• Click Ok
• Follow the installation by clicking Next to Finish
Step 5: Installing the PlatformIO Extension
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...
Step 6: Brief Explanation of the PlatformIO Home Page
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.
Step 7: Creating a New Project
1. Name of the project.
2. Plate used.
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.
Step 8: Main Project File
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"
Step 9: PlatformIO Toolbar
1. Errors and warnings
3. Build (Build)
4. Upload (Record / Upload)
5. Upload to remote device
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)
Step 10: Importing an Arduino Project (.ino) Into the PlatformIO
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.
Step 11: Importing an ESP32 .ino Project to the PlatformIO
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.
Step 12: Wait Until the Platform IO Home Opens
The source files will be located in the src folder. Compile, load, and debug (Serial monitor).
Step 13: Done!
Step 14: Notes and Warnings Regarding the PlatformIO Extension
• 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.
Step 15: 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.