How To Write Code on Pi Pico using CircuitPython and VS Code?
Raspberry Pi Pico
The Raspberry Pi Pico is a small yet powerful microcontroller that is based on the RP2040 chip. It is an excellent choice for hobbyists and professionals who need a reliable and low-cost microcontroller board.
One of the standout features of the Raspberry Pi Pico is its dual-core ARM Cortex M0+ processor. This processor provides excellent performance and makes the board suitable for a wide range of applications. Additionally, the board has an on-board temperature sensor, which makes it suitable for projects that require temperature sensing.
Another impressive feature of the Raspberry Pi Pico is its 26 multi-function GPIO pins. These pins can be used to connect the board to a wide range of devices, including sensors, actuators, and other microcontrollers. This makes the board highly versatile and suitable for many different types of projects.
Learn More 👉 Raspberry Pi Pico
Steps to use CircuitPython with VS Code
The following steps will help you to write code on Pi Pico using CircuitPython & VS Code.
1. Download and upload CircuitPython .uf2
file
- Download the
.uf2
file for Raspberry Pi Pico from Pico Download (circuitpython.org). - Push and hold the BOOTSEL button on the Pi Pico and plug in the USB cable.
- The Pi Pico will be mounted as a mass storage device (RPI-RP2) on the computer.
- Copy the
.uf2
file to the RPI-RP2 volume.
Learn More 👉 CircuitPython
2. Download VS Code and install CircuitPython extension
- Download VS code from Visual Studio Code.
- Install the
CircuitPython
extension by joedevivo from VS Code Marketplace.
3. Write Code
- Open a new directory in VS Code.
- Open the command palette and select
CircuitPython: Select Serial Port
. - Select the COM port of your Pi Pico (for example,
COM3
). - Create a Python file in the root directory (for example,
main.py
). - Write your code in the file.
The following code sample will blink the LED on the Pi Pico board.
4. Upload code to Pi Pico
Here "E:" is the drive letter of the RPI-RP2 volume. Change it according to your system.
- If you are using Windows, open a new terminal and run the following command.
- If you are using Linux, open a new terminal and run the following command.
References
- "Raspberry Pi Documentation - Raspberry Pi Pico and Pico W" Raspberrypi, https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html.
- "CircuitPython" Circuitpython, https://circuitpython.org/.