Raspberry Pi Pico – Micropython Setup

What is MicroPython?

Edit this on GitHub

MicroPython is a full implementation of the Python 3 programming language that runs directly on embedded hardware like Raspberry Pi Pico. You get an interactive prompt (the REPL) to execute commands immediately via USB Serial, and a built-in filesystem. The Pico port of MicroPython includes modules for accessing low-level chip-specific hardware.

Drag-and-Drop MicroPython

Edit this on GitHub

You can program your Pico by connecting it to a computer via USB, then dragging and dropping a file onto it so we’ve put together a downloadable UF2 file to let you install MicroPython more easily.

MicroPython 640x360 v2

Download the correct MicroPython UF2 file for your board:

MicroPython distributions for other RP2040-based boards are available on the MicroPython download page.

To program your device, follow these steps:

  1. Push and hold the BOOTSEL button while connecting your Pico with a USB cable to a computer. Release the BOOTSEL button once your Pico appears as a Mass Storage Device called RPI-RP2.
  2. Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython.
  3. Access the REPL via USB Serial.

MicroPython UF2 Firmware Explained

  1. UF2 File Behavior: When you copy the MicroPython UF2 file to the Pico, the Pico flashes this firmware to its memory. Once the flashing process completes, the Pico reboots, and the UF2 file itself is no longer visible. This is because the Pico doesn’t retain the UF2 file after it’s flashed; it only keeps the firmware that the UF2 installed.
  2. USB Drive Disappearance: After the reboot, the Pico no longer acts as a USB storage device. Instead, it operates in MicroPython mode, where you can access it via a serial connection (e.g., through the REPL in Thonny).

What’s Happening Under the Hood

  • When you copy the UF2 file, it installs the MicroPython firmware.
  • The Pico then reboots into MicroPython, which doesn’t have a filesystem accessible as a USB drive like when it’s in bootloader mode.

Verifying MicroPython is Running

To confirm that MicroPython is running:

  1. Open Thonny IDE (or any compatible serial terminal).
  2. Select the MicroPython (Raspberry Pi Pico) interpreter.
  3. You should see a >>> prompt in the console, indicating that MicroPython is running.

From here, you can start writing and testing MicroPython code directly on the Pico. If you want to upload and manage scripts on your Pico, you can save files to it using Thonny or other tools that support MicroPython file transfers.

The Raspberry Pi Pico Python SDK book contains step-by-step instructions for connecting to your Pico and programming it in MicroPython using both the command line and the Thonny IDE.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *