visual studio code platformio raspberry

Program a Raspberry Pi Pico with Visual Studio Code and PlatformIO


PlatformIO is a collaborative platform for embedded developments. We will detail here the programming of a Raspberry Pi Pico with the Visual Studio Code editor and the PlatformIO IDE.


Download Visual Studio Code from the download page and install it on your system:

Launch Visual Studio Code and install the PlatformIO IDE extension:

Create your PlatformIO project, by clicking on the PlatformIO IDE icon on the left. You must select the “Raspberry Pi Pico” board and the “Arduino Framework” framework.

You can then create your first program by putting for example the following code in the “main.cpp” file:

// Clignotement de LED du Raspberry Pi Pico
// Copyleft 2020
#include "Arduino.h"
void setup() {
  // Declare la broche sur laquelle la LED est  
  // reliee comme une sortie
void loop() {
  // Passer le sortie à l'état HAUT pour allumer la LED
  digitalWrite(LED_BUILTIN, HIGH);
  // Attendre 1 seconde, pendant ce temps la LED reste allumee
  // Passer le sortie à l'état BAS pour eteindre la LED
  digitalWrite(LED_BUILTIN, LOW);    
  // Attendre 1 seconde, pendant ce temps la LED reste donc éteinte

Then simply compile this program by clicking on the “Build” icon :

Compilation of the program to blink the LED of the Raspberry Pi Pico

First upload of the program on the Raspberry Pi Pico

The compilation generates the binary file of your program in UF2 format. The UF2 format is intended for flashing a microcontroller connected as USB mass storage on your PC. This file named “firmware.uf2” is located in the directory “PlatformIO/Projects/MonPremierProjet/.pio/build/pico”. Just drag and drop it on the USB device corresponding to the Raspberry Pi Pico.

Once the program is copied to the Raspberry Pi Pico, it runs immediately. The Raspberry Pi Pico LED should be flashing.

From this moment the Raspberry Pi Pico no longer appears as a USB mass storage. If you want to upload a new program this way, you will have to start it in “bootloader” mode. To do this, you must disconnect the USB cable, hold the “reset” button pressed and reconnect the USB cable.

Next uploads

Once the first upload has been done following the method above, it is possible to upload your programs directly from the PlatformIO IDE. Simply click on the “Upload” command in the “Project Tasks” menu of PlatformIO or on the “Upload” button in the blue banner at the bottom of the editor.

Uploading the program to the Raspberry Pi Pico from the PlatformIO IDE

Note: On Linux, you must first install the PlatformIO permission rules for the USB ports, by typing the following command in a shell:

curl -fsSL | sudo tee /etc/udev/rules.d/99-platformio-udev.rules

Votre avis compte !

Note moyenne : 4.8 / 5. Nombre de votes : 21

Pas encore de vote pour ce tutoriel

Désolé si cet article ne vous a pas intéressé

Merci de commenter afin que je puisse l’améliorer.

Dites-moi comment améliorer cette page.