Thonny is a small Python editor that speaks MicroPython over USB. It is the path of least resistance and it is what the official documentation assumes.




>>> print("hello from the Pico")
hello from the Pico
>>> from machine import Pin
>>> led = Pin(25, Pin.OUT)
>>> led.on()
>>> led.off()# blink.py - the on-board LED, on GPIO 25.
from machine import Pin
from time import sleep
led = Pin(25, Pin.OUT)
while True:
led.toggle()
sleep(0.5)# button.py - press to light an external LED.
#
# Wiring: GP15 -> 330 ohm resistor -> LED anode; LED cathode -> GND (pin 38).
# Button between GP14 and GND (pin 33).
#
# PULL_UP uses a resistor inside the RP2040, so the pin idles at 3.3V and
# reads 0 when pressed. Two wires, no extra components.
from machine import Pin
from time import sleep
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP)
while True:
if button.value() == 0: # 0 means pressed
led.on()
else:
led.off()
sleep(0.01) # crude debounce, and it keeps the loop calm# temperature.py - the RP2040 has a temperature sensor wired to ADC channel 4.
# No external parts at all.
import machine
import time
sensor = machine.ADC(4)
CONVERSION = 3.3 / 65535 # read_u16 returns 0-65535 across 0-3.3V
while True:
volts = sensor.read_u16() * CONVERSION
# Formula from the RP2040 datasheet: 0.706V at 27C, -1.721 mV per degree.
celsius = 27 - (volts - 0.706) / 0.001721
print("{:.1f} C".format(celsius))
time.sleep(1)