Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (2024)

In this guide, you’ll learn how to program the Raspberry Pi Pico board with MicroPython using VS Code Editor and the MicroPico extension (previously called Pico-W-Go).

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (1)

New to the Raspberry Pi Pico? Check out our Raspberry Pi Pico Getting Started Guide.

If you like to program using VS Code, great news. There’s an extension for VS Code that allows you to program your Raspberry Pi Pico board using VS Code editor.

If you’re not used to programming using VS Code, it might be a little difficult to get started. You may stick to simpler IDEs, like Thonny IDE.

Prerequisites

To program the Raspberry Pi Pico with VS Code using MicroPython, you need to check the following steps.

1) Installing Python

You need to have Python 3.9 or newer installed on your system and in your PATH. You also need to have the pyserial package installed.

2) Flashing MicroPython Firmware

You need to install MicroPython firmware on your Raspberry Pi Pico. Follow the next section.

  • Flashing MicroPython Firmware on the Raspberry Pi Pico

3) Installing VS Code

You need to install VS Code on your computer. Follow one of the next sections if you need to install VS Code:

  • A) Installing VS Code on Windows
  • B) Installing VS Code on Mac OS X
  • C) Installing VS Code on Linux Ubuntu

4) Installing MicroPico Extension

Finally, follow the instructions to set up the MicroPico extension, configure your project folder and run your first project:

  • Installing MicroPico Extension
  • Configuring a MicroPython Project Folder
  • Running a MicroPython File
  • Uploading a MicroPython File

Installing Python

1.Go to the Python Downloads page:www.python.org/downloadsand download the installation file.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (2)

2.After a few seconds, you should have an executable file downloaded to your computer. Double-click the file to open it.

3. Make sure you have the option Add Python to PATH ticked to add Python to path.

4. Then, you can proceed with the installation.

Flashing MicroPython Firmware on the Raspberry Pi Pico

You can flash MicroPython firmware on your Raspberry Pi Pico by connecting it to a computer via USB, then dragging and dropping a file onto it. Click on one of the following links to download the MicroPython firmware for your board (if you have a W version, you can choose if you want to add support for Bluetooth):

Then follow the next steps:

Connect the board to your computer via the USB cable while holding the BOOTSEL button at the same time to put it in bootloader mode.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (3)

A new Mass Storage Device called RPi-RP2 will show up.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (4)

Drag and drop the MicroPython file you downloaded previously onto the RPI-RP2 device. The window will automatically close and your device will be running MicroPython.

A) Installing VS Code on Windows

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Windows).

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (5)

Click on the installation wizard to start the installation and follow all the steps to complete the installation. Accept the agreement and press the Next button.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (6)

Select the following options and click Next.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (7)

Press the Install button.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (8)

Finally, click Finish to finish the installation.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (9)

Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (10)

That’s it. Visual Studio Code was successfully installed.

B) Installing VS Code on Mac OS X

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Mac OS X).

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (11)

After downloading the Visual Studio Code application file, you’ll be prompted with the following message. Press the “Open” button.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (12)

Or open your Downloads folder and open Visual Studio Code.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (13)

After that, you’ll be greeted by a Welcome tab with the released notes of the newest version.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (14)

That’s it. Visual Studio Code was successfully installed.

C) Installing VS Code on Linux Ubuntu

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Linux Ubuntu).

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (15)

Save the installation file:

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (16)

To install it, open a Terminal windows, navigate to your Downloads folder and run the following command to install VS Code.

$ cd Downloads~/Downloads $ sudo apt install ./code_1.49.1-1600299189_amd64.deb

When the installation is finished, VS Code should be available in your applications menu.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (17)

Open VS Code and you’ll be greeted by a Welcome tab with the released notes of the newest version.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (18)

That’s it. Visual Studio Code was successfully installed.

Installing MicroPico Extension

Open VS Code and click on the Extensions tab at the left sidebar.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (19)

Search for “MicroPico” or “pico-w-go” and install the MicroPico Extension.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (20)

Configuring a MicroPython Project Folder

Now, create a project folder on your computer called for example Pi Pico Test.

Then, in VS Code, go to File > Open Folder and open the folder you just created.

Press CTRL+Shift +P. A little window will show up to search commands. Write “micropico” and then, select the option MicroPico: Configure project.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (21)

At the bottom right corner, you should get a success message.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (22)

Additionally, it should have created some essential files at the left sidebar.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (23)

At the same time, you should see some commands to interact with your Raspberry Pi Pico.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (24)

Running a MicroPython File

Inside your project folder, create a new Python file, for example blinking.py, and copy the following code.

from machine import Pinfrom time import sleepled = Pin('LED', Pin.OUT)print('Blinking LED Example')while True: led.value(not led.value()) sleep(0.5)
Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (25)

Then, click on the little Run icon at the bottom of the window.

If everything went as expected, the Raspberry Pi Pico onboard LED should be blinking every half second.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (26)
Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (27)

Additionally, it will open a new Terminal window (REPL) where it will print the message ‘Blinking LED Example’.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (28)

To stop the execution of the program, click on the Stop button at the bottom of the window.

Important note: just running the file doesn’t copy it permanently to the board’s filesystem. This means that if you unplug it from your computer and apply power to the board, nothing will happen because it doesn’t have any Python files saved on its filesystem. The Runfunction is useful to test the code, but if you want to upload it permanently to your board, you need to create and save a file to the board filesystem. MicroPython will automatically run a file called main.py on boot. See the next section.

Uploading a MicroPython File

Inside your project folder, create another file called main.py and copy the exact same code.

from machine import Pinfrom time import sleepled = Pin('LED', Pin.OUT)print('Blinking LED Example')while True: led.value(not led.value()) sleep(0.5)

Then, press CTRL+Shift+P, or click on the All commands button at the bottom of the window. Write MicroPico and select the option MicroPico: Upload current file to Pico.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (29)

You should get a success message after a few seconds. Now, you can unplug the board from your computer and power it using a power bank for example. You’ll see that the board will start blinking the LED as soon as power is applied (for this to happen, the file should be called main.py and it should be uploaded to the board).

Wrapping Up

This article was a quick guide to show you how to set up VS Code with the MicroPico extension (previously called Pico-W-Go) to program the Raspberry Pi Pico with MicroPython.

If you’ve never used VS Code, it might be a little difficult to get started. If you find that this option is very advanced, you might consider using simpler IDEs likeThonny IDE.

Alternatively, if you prefer to program the Raspberry Pi Pico using C/C++ with Arduino IDE, you can follow the next tutorial:

  • Programming Raspberry Pi Pico with Arduino IDE (Pico W compatible)

Other MicroPython tutorials to get started:

  • Raspberry Pi Pico and Pico W Pinout Guide: GPIOs Explained
  • Raspberry Pi Pico: Control Digital Outputs and Read Digital Inputs (Arduino IDE)
  • Raspberry Pi Pico: Control Digital Outputs and Read Digital Inputs (MicroPython)

Thanks for reading.

Programming Raspberry Pi Pico with VS Code and MicroPython | Random Nerd Tutorials (2024)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 5703

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.