Programming with PlatformIO on VSCode#
As the Arduino-Pico core docs state:
“PlatformIO is a free, open-source build-tool written in Python, which also integrates into VSCode code as an extension.
PlatformIO significantly simplifies writing embedded software by offering a unified build system, yet being able to create project files for many different IDEs, including VSCode, Eclipse, CLion, etc. Through this, PlatformIO can offer extensive features such as IntelliSense (autocomplete), debugging, unit testing etc., which are not available in the standard Arduino IDE.”
Despite the added features, all your programs can still be written in Arduino code, and basic functions like compile, upload and serial monitor are present.
If you’re wondering why we don’t promote PlatformIO as the default way to program EVN, it can be a little more troublesome to setup as PlatformIO does not natively support our board despite being a community project. But if you’re up for it, here we go!
Steps#
Install the latest version of Git for your OS.
Install the latest version of Visual Studio Code for your OS.
(For Windows Users only) Enabling Long Paths in Windows
Taken from the Arduino-Pico core docpage on using PlatformIO:
Open a Command Prompt window and execute the following command. Depending on your Git install, you may need to run Command Prompt to run as administrator (Instead of clicking Command Prompt to open, right-click and select “Run as administrator”.
git config --system core.longpaths true
Enable long paths in the OS
Click Windows key+R and type gpedit.msc, then press the Enter key. This launches the Local Group Policy Editor.
Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem.
Double click Enable NTFS/Win32 long paths. This should popup a window.
Select Enabled, then click Apply, followed by OK.
Reboot your computer for the changes to take effect
Install the PlatformIO IDE Extension on Visual Studio Code
Open Visual Studio Code.
Next, open the Extensions Panel by clicking the Extension Button on the left side of Visual Studio Code.
Search for “PlatformIO IDE” in the search bar and install the first result.
Download (or Git Clone) our Example PlatformIO Project
In this repository you’ll be able to download our example project to use as a template for other projects.
After downloading as a ZIP file, unzip it to obtain the project folder.
Alternatively, execute the command below in Command Prompt (Windows) or Terminal (Mac/Linux) to clone the repository.
git clone https://github.com/EVNdevs/EVN-PlatformIO-Example.git
Open the project in Visual Studio Code (File > Open Folder > Select your project folder).
Once opened, PlatformIO should recognise this folder as a PlatformIO project and begin installing the necessary frameworks and toolchains for compilation.
The initial setup can take some time, so you might want to grab a coffee.
Meanwhile, here is the folder structure for our example project:
|__ include | |__ README |__ lib | |__ README |__ test | |__ README |__ src | |__ main.cpp |__ platformio.ini |__ .gitignore
On the bottom, you’ll find the PIO toolbar, which contains the familiar buttons for Compile, Upload and Serial Port Monitor.
platformio.inicontains many important project settings, that we have configured to work with the Arduino-Pico Core and EVN libraries.src/main.cppis where your program will be. Note that this is not an.inofile, and you need to add#include <Arduino.h>to the start of the file.lib/are where your libraries go. This is unlike Arduino IDE, where all installed libraries can be used by any sketches on the same computer.
Note
Creating a “New Project” without using our example template is possible, but you will need to swap out the contents of platformio.ini with the contents from our example.
Updating PlatformIO Integration#
As mentioned earlier, EVN Alpha is not natively supported by PlatformIO.
The only RP2040 boards natively supported are the Arduino Nano RP2040 Connect and Pi Pico, as shown in this repo.
Our boards are actually added via this project, which integrates a version of the Arduino-Pico core (and all its supported boards) into PlatformIO.
Updating the integration ensures that more up-to-date versions of the Arduino-Pico core can be used.
Run the following line in the PlatformIO CLI to update:
pio pkg update -g -p https://github.com/maxgerhardt/platform-raspberrypi.git
Alternatively, update it in the PIO Home > Platforms > Updates GUI.
Additional Resources#
Here are some additional resources you may want to explore:
PlatformIO Documentation: https://docs.platformio.org/en/latest/index.html
PlatformIO CLI reference: https://docs.platformio.org/en/latest/core/index.html
PlatformIO
platformio.iniReference: https://docs.platformio.org/en/latest/projectconf/index.htmlArduino-Pico docs regarding PlatformIO: https://arduino-pico.readthedocs.io/en/latest/platformio.html