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:

micropython.org/download

Select the firmware for your board:

BoardFirmware 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

  1. Disconnect the Pico from USB
  2. Hold the BOOTSEL button (white button on the board)
  3. Plug in the USB cable while holding BOOTSEL
  4. 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:

shell
sudo apt install -y thonny
# Or for the latest version:
pip install thonny

macOS:

shell
brew install --cask thonny
# Or download from thonny.org

Step 5 — Connect Thonny to the Pico

  1. Open Thonny
  2. Go to Tools → Options → Interpreter (or Run → Configure interpreter)
  3. In the dropdown, select "MicroPython (Raspberry Pi Pico)"
  4. Leave the Port as "Try to detect port automatically" or select it manually

Click OK. The Thonny shell at the bottom should show:

text
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:

python
1from machine import Pin
2import time
3
4# Built-in LED is on GP25 (Pico) or 'LED' (Pico W)
5led = Pin(25, Pin.OUT) # Use Pin('LED') for Pico W
6
7count = 0
8while True:
9 led.toggle()
10 print(f"Blink #{count}")
11 count += 1
12 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:

text
Blink #0
Blink #1
Blink #2
...

Step 7 — Save Code to the Pico

To run your code automatically when the Pico powers on:

  1. Go to File → Save As...
  2. When asked where to save, select "Raspberry Pi Pico"
  3. 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:

FilePurpose
main.pyRuns automatically on boot
boot.pyRuns before main.py (for hardware init)
Any .py fileCan be imported as a module

Useful MicroPython Modules for Pico

python
1from machine import Pin, ADC, I2C, SPI, UART, PWM
2import time
3import utime
4import network # For Pico W Wi-Fi
5import ubinascii
6
7# GPIO
8led = Pin(25, Pin.OUT)
9button = Pin(15, Pin.IN, Pin.PULL_UP)
10
11# ADC (Analog input on GP26, GP27, GP28)
12adc = ADC(Pin(26))
13raw = adc.read_u16() # 0–65535
14voltage = raw * 3.3 / 65535 # Convert to volts
15
16# PWM
17pwm = PWM(Pin(0))
18pwm.freq(1000)
19pwm.duty_u16(32768) # 50% duty cycle
20
21# I2C
22i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)
23devices = i2c.scan() # Returns list of addresses
24
25# UART
26uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))
27uart.write('Hello UART!\n')

Pico W — Wi-Fi Connection

python
1import network
2import time
3
4ssid = 'YourWiFi'
5password = 'YourPassword'
6
7wlan = network.WLAN(network.STA_IF)
8wlan.active(True)
9wlan.connect(ssid, password)
10
11# Wait for connection
12while not wlan.isconnected():
13 print('Connecting...')
14 time.sleep(0.5)
15
16print('Connected! IP:', wlan.ifconfig()[0])

Next Steps

Previous
Introduction (Pico & Pico 2)