Pico: get started with MicroPython on the Raspberry Pi Pico
Flash MicroPython to a Raspberry Pi Pico, connect over the REPL, and run your first script. The 10-minute Pico setup.
The Raspberry Pi Pico is the microcontroller I reach for when I want something cheap, fast, and easy to deploy. The W version adds Wi-Fi, which turns it into a $6 ESP32 alternative for projects where you do not need Bluetooth.
This tutorial gets MicroPython installed and runs a blink sketch in about 15 minutes.
What you need
- Raspberry Pi Pico or Pico W
- USB cable (micro-USB for the original Pico, USB-C for the Pico 2)
- A computer
Step 1: download MicroPython
Go to https://micropython.org/download/RPI_PICO/ (or RPI_PICO_W for the
W version). Download the latest .uf2 file.
There is no installer. The .uf2 file is the firmware image.
Step 2: flash the firmware
- Hold down the BOOTSEL button on the Pico.
- While holding the button, plug in the USB cable.
- Release the button.
The Pico appears as a USB drive called RPI-RP2.
- Drag the
.uf2file to that drive.
The Pico will reboot and the drive will disappear. The Pico is now running MicroPython.
Step 3: install Thonny
Thonny is the IDE I use for Pico + MicroPython. Download from https://thonny.org/.
Open Thonny. Configure the interpreter:
Tools>>Options>>Interpreter- Select
MicroPython (Raspberry Pi Pico)
You should see a >>> prompt in the Shell pane at the bottom. This is the
MicroPython REPL.
Step 4: blink the onboard LED
MicroPython (Pico)
Type this at the >>> prompt:
from machine import Pin
import time
led = Pin("LED", Pin.OUT)
while True:
led.toggle()
time.sleep(0.5)
The onboard LED on the Pico should blink at 1 Hz. Press Ctrl+C in the
Shell to stop the script.
Arduino (Pico)
The Pico’s Arduino core is maintained by Earle Philhower. It works through the regular Arduino IDE with a board package add-on.
- In the Arduino IDE:
File>>Preferences>>Additional boards manager URLs. Paste:https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json Tools>>Board>>Boards Manager>> searchpico>> install Raspberry Pi Pico/RP2040 by Earle Philhower.Tools>>Board>>Raspberry Pi Pico(select the one matching your board: Pico, Pico W, or Pico 2).- The Pico does not auto-reset for upload on every host. Hold the BOOTSEL button, plug in the USB, release. The IDE will then upload.
- Open the IDE’s Blink example (
File>>Examples>>01.BasicsBlink) and upload.
The sketch that gets uploaded:
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
On the Pico W, the onboard LED is on the Wi-Fi chip’s GPIO, accessed via
LED_BUILTIN. On the original Pico,LED_BUILTINmaps to GPIO 25. Either way the Blink example works without changes.
On the Pico W,
Pin("LED")is correct. On the original Pico (no W), you need to use the pin number:Pin(25, Pin.OUT)for the onboard LED.
Step 5: save a script to the Pico
In Thonny, write a file in the editor:
# main.py
from machine import Pin
import time
led = Pin("LED", Pin.OUT)
while True:
led.toggle()
time.sleep(0.5)
Save it to the Pico as main.py. This runs automatically when the Pico
boots.
What you learned
- The Pico has a BOOTSEL button for flashing firmware.
- MicroPython is a Python 3 interpreter for microcontrollers.
- The onboard LED is on pin 25 on the original Pico, on the Wi-Fi chip’s
GPIO on the Pico W (accessed via
Pin("LED")). main.pyruns automatically on boot.
Saving files to the Pico
You can save files directly to the Pico’s flash via Thonny:
File>>Save as>>MicroPython device
These files persist across reboots. The Pico has about 2 MB of usable flash after MicroPython.
Common file structure:
main.py # runs on boot
boot.py # runs before main.py (use for setup)
lib/ # additional modules (e.g. umqtt, network)
Working with the REPL
The REPL (Read-Eval-Print Loop) is your friend. You can:
- Test individual commands before putting them in a script.
- Inspect the state of variables.
- Recover from errors without rebooting.
Useful REPL shortcuts:
Ctrl+C: interrupt the running script.Ctrl+D: soft-reboot (re-runsmain.py).Ctrl+E: paste mode for multi-line code.
To see all available modules:
help('modules')
To see what’s available on a specific module:
from machine import Pin
help(Pin)
Why MicroPython vs. CircuitPython
Both are Python for microcontrollers. Differences:
- MicroPython: original, smaller footprint, official Pico port, more optimized. Default pick.
- CircuitPython: Adafruit’s fork, better peripheral support (more Adafruit boards), easier to use, includes a USB drive for editing.
For most projects, MicroPython on the Pico is fine. If you are using an Adafruit board (e.g. Feather, Qt Py), CircuitPython is usually easier.
When the Pico does not show up as a drive
- You did not hold BOOTSEL before plugging in. Try again.
- The USB cable is charge-only. Some cables have data lines missing. Use a different cable.
- The USB port is weak. Try a different port, especially on a desktop.
When Thonny cannot connect
- Wrong interpreter. Re-select
MicroPython (Raspberry Pi Pico). - The Pico crashed. Hold BOOTSEL, plug in, reflash MicroPython.
- The serial port is in use by another program. Close any other REPL connections.
What to build next
- A button that toggles the LED.
- A sensor reader (DHT22, DS18B20).
- A web server on the Pico W.
The Pico W web server is in the book Pico Wi-Fi Projects. The sensor reader is one of the next tutorials on this site.