Raspberry Pi — Pico
MicroPython on Raspberry Pi Pico
MicroPython is the fastest way to start coding on the Raspberry Pi Pico. Flash the firmware once, and you're ready to write Python code directly on the board.
Step 1 — Download MicroPython Firmware
Go to the official MicroPython downloads page:
Select the firmware for your board:
| Board | Firmware File |
|---|---|
| Raspberry Pi Pico (RP2040) | RPI_PICO-*.uf2 |
| Raspberry Pi Pico W (Wi-Fi) | RPI_PICO_W-*.uf2 |
| Raspberry Pi Pico 2 (RP2350) | RPI_PICO2-*.uf2 |
| Raspberry Pi Pico 2 W (Wi-Fi) | RPI_PICO2_W-*.uf2 |
Download the latest stable .uf2 file.
Step 2 — Enter BOOTSEL Mode
- Disconnect the Pico from USB
- Hold the BOOTSEL button (white button on the board)
- Plug in the USB cable while holding BOOTSEL
- Release the button
The Pico appears as a USB drive named RPI-RP2 on your computer.
Step 3 — Flash the Firmware
Drag and drop the downloaded .uf2 file onto the RPI-RP2 drive.
The Pico will automatically reboot and disconnect. After a few seconds, it reconnects as a serial device — this means MicroPython is running.
Step 4 — Install Thonny IDE
Thonny is the recommended IDE for MicroPython development. It includes a built-in serial terminal and file manager for the Pico.
Windows: Download from thonny.org — run the .exe installer.
Ubuntu:
sudo apt install -y thonny
# Or for the latest version:
pip install thonny
macOS:
brew install --cask thonny
# Or download from thonny.org
Step 5 — Connect Thonny to the Pico
- Open Thonny
- Go to Tools → Options → Interpreter (or Run → Configure interpreter)
- In the dropdown, select "MicroPython (Raspberry Pi Pico)"
- Leave the Port as "Try to detect port automatically" or select it manually
Click OK. The Thonny shell at the bottom should show:
MicroPython v1.xx.x on 2025-xx-xx; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>>
Step 6 — Write Your First Program
In the Thonny editor (top area), type:
1from machine import Pin2import time34# Built-in LED is on GP25 (Pico) or 'LED' (Pico W)5led = Pin(25, Pin.OUT) # Use Pin('LED') for Pico W67count = 08while True:9 led.toggle()10 print(f"Blink #{count}")11 count += 112 time.sleep(0.5)Click Run (green play button) or press F5.
You should see the LED blinking and the counter printing in the Thonny shell:
Blink #0
Blink #1
Blink #2
...
Step 7 — Save Code to the Pico
To run your code automatically when the Pico powers on:
- Go to File → Save As...
- When asked where to save, select "Raspberry Pi Pico"
- Save the file as
main.py
The main.py file runs automatically every time the Pico boots.
Pico File System Management
Use the View → Files panel in Thonny to see files on both your computer and the Pico.
Key files:
| File | Purpose |
|---|---|
main.py | Runs automatically on boot |
boot.py | Runs before main.py (for hardware init) |
Any .py file | Can be imported as a module |
Useful MicroPython Modules for Pico
1from machine import Pin, ADC, I2C, SPI, UART, PWM2import time3import utime4import network # For Pico W Wi-Fi5import ubinascii67# GPIO8led = Pin(25, Pin.OUT)9button = Pin(15, Pin.IN, Pin.PULL_UP)1011# ADC (Analog input on GP26, GP27, GP28)12adc = ADC(Pin(26))13raw = adc.read_u16() # 0–6553514voltage = raw * 3.3 / 65535 # Convert to volts1516# PWM17pwm = PWM(Pin(0))18pwm.freq(1000)19pwm.duty_u16(32768) # 50% duty cycle2021# I2C22i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)23devices = i2c.scan() # Returns list of addresses2425# UART26uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))27uart.write('Hello UART!\n')Pico W — Wi-Fi Connection
1import network2import time34ssid = 'YourWiFi'5password = 'YourPassword'67wlan = network.WLAN(network.STA_IF)8wlan.active(True)9wlan.connect(ssid, password)1011# Wait for connection12while not wlan.isconnected():13 print('Connecting...')14 time.sleep(0.5)1516print('Connected! IP:', wlan.ifconfig()[0])
