Raspberry Pi Pico first steps in MicroPython
Build it step by step
0 of 5 doneInstall MicroPython
Hold BOOTSEL, plug in the Pico and install MicroPython from Thonny's interpreter settings.
Wire the LED
GP15 through 330 Ω to the LED's long leg, short leg to GND.
Wire the button
GP14 to one side, GND to the other.
Run
Paste the code into Thonny and press Run. Then save it to the Pico as main.py.
Try the shell
In the shell, type led.value(1) while it is stopped to switch the LED by hand.
How do you build a raspberry Pi Pico first steps in MicroPython?
Flash MicroPython onto a Raspberry Pi Pico, blink an external LED with a timer, and toggle it with a button using an interrupt. You need Raspberry Pi Pico H, LED 5 mm red, Resistor 330 Ω, Tactile push button 6 mm, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 5 steps and about 40 minutes.
- Level
- Beginner
- Time
- About 40 min
- Parts
- 7
Parts list
- Development BoardsBuyThe H version has headers soldered
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 330 Ω × 1
- SwitchesBuy
- PrototypingBuy
- PrototypingBuy
- Cables & WiresBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Pico GP15 | 330 Ω, LED anode, LED cathode to GND | LED |
| Pico GP14 | Button, other side to GND | Button with internal pull-up |
| Pico GND (pin 38) | Breadboard ground rail | Ground |
Code
MicroPython in Thonny. Hold BOOTSEL while plugging the Pico in, then in Thonny choose Tools > Options > Interpreter > MicroPython (Raspberry Pi Pico) > Install or update MicroPython. Save as main.py on the Pico to run at power-up.
from machine import Pin, Timer
import time
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP)
blinking = True
last_press = 0
def tick(t):
if blinking:
led.toggle()
def pressed(pin):
global blinking, last_press
now = time.ticks_ms()
if time.ticks_diff(now, last_press) > 200: # debounce
blinking = not blinking
led.value(0)
print("Blinking" if blinking else "Stopped")
last_press = now
Timer(freq=2, mode=Timer.PERIODIC, callback=tick)
button.irq(trigger=Pin.IRQ_FALLING, handler=pressed)
while True:
time.sleep(1) # the timer and interrupt do the workTest checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| After Run | LED blinks: 2 timer ticks per second, so one full on-off per second |
| Button press | Blinking stops and the shell prints "Stopped" |
| Second press | Blinking resumes |
| Unplug and replug (saved as main.py) | Starts blinking on its own |
If it does not work
Thonny cannot find the Pico
Use a data cable, and select the Pico's port at the bottom right of Thonny.
LED never lights
Check its long leg goes to the resistor side, and that you used GP15 (physical pin 20).
One press counts twice
Raise the 200 ms debounce to 300.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the raspberry Pi Pico first steps in MicroPython?
Raspberry Pi Pico H, LED 5 mm red, Resistor 330 Ω, Tactile push button 6 mm, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). Raspberry Pi Pico H: The H version has headers soldered.
How long does the raspberry Pi Pico first steps in MicroPython take to build?
About 40 minutes for a beginner maker, in 5 steps.
How do I know the raspberry Pi Pico first steps in MicroPython works?
After Run: LED blinks: 2 timer ticks per second, so one full on-off per second. Button press: Blinking stops and the shell prints "Stopped". Second press: Blinking resumes.
Thonny cannot find the Pico: what should I check?
Use a data cable, and select the Pico's port at the bottom right of Thonny.
LED never lights: what should I check?
Check its long leg goes to the resistor side, and that you used GP15 (physical pin 20).
One press counts twice: what should I check?
Raise the 200 ms debounce to 300.
