Zum Inhalt

Raspberry Pi Pico Flashing Guide

This comprehensive guide covers how to flash MicroPython firmware onto your Raspberry Pi Pico and upload your first program.

Table of Contents

  1. Prerequisites
  2. Understanding Raspberry Pi Pico
  3. Method 1: Flashing with Thonny (Recommended)
  4. Method 2: Manual Flashing
  5. Uploading Your First Program
  6. Setting Up Autostart
  7. File Management
  8. Common Issues

Prerequisites

Before you begin, make sure you have:

  • ✅ Raspberry Pi Pico or Pico W
  • ✅ Micro USB cable (data cable, not charging-only)
  • ✅ Computer with USB port
  • ✅ Thonny IDE installed (Installation Guide)
  • ✅ Internet connection (to download firmware)

Understanding Raspberry Pi Pico

Raspberry Pi Pico Specifications

Feature Specification
Microcontroller RP2040 (Raspberry Pi custom chip)
CPU Dual-core ARM Cortex-M0+ @ 133MHz
RAM 264KB SRAM
Flash Memory 2MB
GPIO Pins 26 multi-function pins
PWM Channels 16
ADC 3 channels, 12-bit
UART, SPI, I2C Multiple interfaces
USB 1x USB 1.1 controller
Temperature Sensor Built-in

Pico vs Pico W

  • Pico: Standard version without wireless
  • Pico W: Includes WiFi and Bluetooth (via Infineon CYW43439)

Boot Modes

The Pico has two boot modes:

  1. BOOTSEL Mode (USB Mass Storage)
  2. Appears as a USB drive
  3. Used for flashing firmware
  4. Accessed by holding BOOTSEL button while plugging in

  5. Normal Mode (Running Code)

  6. Executes uploaded MicroPython code
  7. Regular operation mode

This is the easiest method for beginners.

Step 1: Enter BOOTSEL Mode

  1. Disconnect the Pico from your computer (if connected)
  2. Locate the BOOTSEL button on the Pico (small white button near the USB port)
  3. Press and hold the BOOTSEL button
  4. While holding the button, connect the Pico to your computer via USB
  5. Release the BOOTSEL button after 2 seconds

Result: The Pico appears as a USB drive named "RPI-RP2"

The BOOTSEL button is a small white button located near the USB port on the Pico board.

Step 2: Flash Firmware via Thonny

  1. Launch Thonny IDE

  2. Check Connection

  3. The Pico should be detected as "RPI-RP2" drive

  4. Install MicroPython Firmware

  5. Click ToolsOptions
  6. Select the Interpreter tab
  7. Choose "MicroPython (Raspberry Pi Pico)" or "MicroPython (Raspberry Pi Pico W)"
  8. Click Install or update MicroPython

  9. Configure Installation

  10. Target volume: Select "RPI-RP2" drive
  11. MicroPython variant:
    • For Pico: "Raspberry Pi Pico / Pico H"
    • For Pico W: "Raspberry Pi Pico W / Pico WH"
  12. Version: Select the latest stable version
  13. Click Install

  14. Wait for Completion

  15. Installation takes 10-30 seconds
  16. Don't disconnect during installation
  17. Pico will restart automatically

  18. Verify Installation

  19. After restart, Thonny's Shell should show:

    MicroPython v1.x.x on YYYY-MM-DD; Raspberry Pi Pico with RP2040
    Type "help()" for more information.
    >>>
    

  20. Test with Simple Code

    >>> print("Hello, Pico!")
    Hello, Pico!
    


Method 2: Manual Flashing

Advanced method for those who prefer manual control.

Step 1: Download MicroPython Firmware

  1. Visit MicroPython Download Page
  2. Go to https://micropython.org/download/

  3. Select Your Device

  4. For Pico: Raspberry Pi Pico
  5. For Pico W: Raspberry Pi Pico W

  6. Download Latest .UF2 File

  7. Click on the latest stable release
  8. Save the .uf2 file (e.g., rp2-pico-latest.uf2)

Step 2: Enter BOOTSEL Mode

Follow the same steps as Method 1, Step 1.

Step 3: Copy Firmware to Pico

  1. Locate RPI-RP2 Drive
  2. macOS: Check Finder sidebar
  3. Windows: Check "This PC"
  4. Linux: Usually mounted in /media/ or /mnt/

  5. Copy UF2 File

  6. Drag and drop the .uf2 file to the RPI-RP2 drive
  7. Or use command line:
# macOS/Linux
cp rp2-pico-latest.uf2 /Volumes/RPI-RP2/

# Linux (adjust mount point)
cp rp2-pico-latest.uf2 /media/$USER/RPI-RP2/
# Windows (adjust drive letter)
copy rp2-pico-latest.uf2 D:\
  1. Wait for Auto-Reset
  2. The Pico will automatically reboot
  3. RPI-RP2 drive will disappear
  4. Flashing is complete!

Step 4: Verify in Thonny

  1. Open Thonny
  2. Go to ToolsOptionsInterpreter
  3. Select "MicroPython (Raspberry Pi Pico)"
  4. Port should auto-detect
  5. Click OK
  6. Check Shell for MicroPython prompt >>>

Uploading Your First Program

Using Thonny

  1. Create New File
  2. Click FileNew

  3. Write Code

    # blink.py - Simple LED blink example
    import machine
    import time
    
    led = machine.Pin("LED", machine.Pin.OUT)
    
    while True:
        led.toggle()
        time.sleep(0.5)
    

  4. Save to Pico

  5. Click FileSave as...
  6. Select "Raspberry Pi Pico"
  7. Name it blink.py
  8. Click OK

  9. Run the Program

  10. Click the green Run button (F5)
  11. Or click RunRun current script
  12. The LED should start blinking!

  13. Stop the Program

  14. Click the red Stop button
  15. Or press Ctrl+C in the Shell

Setting Up Autostart

To make your program run automatically when the Pico powers on:

Method: Rename to main.py

  1. Save or Rename Your Script
  2. In Thonny, save your working script as main.py
  3. Or rename existing file on Pico to main.py

  4. Upload to Pico

  5. Make sure main.py is saved to the Pico (not your computer)

  6. Test Autostart

  7. Disconnect the Pico from USB
  8. Reconnect it (without holding BOOTSEL)
  9. The program should start automatically
# main.py - Autostart LED blink
import machine
import time

led = machine.Pin("LED", machine.Pin.OUT)

print("Autostart: LED blink program")
print("Press Ctrl+C to stop")

try:
    while True:
        led.toggle()
        time.sleep(0.5)
except KeyboardInterrupt:
    led.off()
    print("Program stopped")

To disable autostart: - Delete or rename main.py on the Pico - Or add a long delay at the start and interrupt with Ctrl+C


File Management

Viewing Files on Pico

In Thonny: 1. Click ViewFiles 2. You'll see two file browsers: - This computer: Your local files - Raspberry Pi Pico: Files on the Pico

Uploading Files

Drag and drop: - Drag files from "This computer" to "Raspberry Pi Pico"

Or use menu: - Right-click file in "This computer" - Select "Upload to /"

Downloading Files

  • Right-click file in "Raspberry Pi Pico"
  • Select "Download to..."
  • Choose destination on your computer

Deleting Files

  • Right-click file in "Raspberry Pi Pico"
  • Select "Delete"
  • Confirm deletion

Creating Directories

  • Right-click in "Raspberry Pi Pico" area
  • Select "New directory"
  • Enter directory name

Common Issues

Pico Not Detected

Symptoms: - RPI-RP2 drive doesn't appear - Thonny can't find Pico

Solutions: 1. Try a different USB cable (must be data cable, not charge-only) 2. Try a different USB port 3. Make sure you're holding BOOTSEL while connecting 4. Check Troubleshooting Guide

Upload Failed

Symptoms: - "Could not write to port" error - Upload hangs indefinitely

Solutions: 1. Reconnect the Pico 2. Restart Thonny 3. Check port permissions (Linux/macOS) 4. Re-flash MicroPython firmware

Code Runs Once Then Stops

Symptoms: - Program runs in Thonny but not on restart

Solutions: 1. Make sure file is saved as main.py 2. Check file is on Pico, not your computer 3. Add error handling to catch and print exceptions

Import Errors

Symptoms: - ImportError: no module named 'xxx'

Solutions: 1. Some modules are not available in MicroPython 2. Check MicroPython documentation 3. Use MicroPython-specific libraries


File Size Limitations

The Pico has 2MB of flash storage: - MicroPython firmware: ~500KB - Available for your code: ~1.5MB

Tips: - Keep code files small and modular - Delete unused files - Use .mpy compiled files for larger libraries


Next Steps

Now that you've flashed your Pico:

  1. Try Example Scripts - Run the provided examples
  2. src/pico_scripts/01_blink.py
  3. src/pico_scripts/02_wifi_connect.py

  4. Explore MicroPython - Learn the differences from standard Python

  5. MicroPython Documentation

  6. Build Projects - Try the seminar projects

  7. WiFi signal monitor
  8. API consumer
  9. Access point web server

Additional Resources


Troubleshooting

For more detailed troubleshooting, see the Troubleshooting Guide.