The Raspberry Pi Pico (MicroPython)
The Sandbox and Lab mode can run a Raspberry Pi Pico instead of a Pi. The board you build decides the language main.py runs in:
| Board | main.py runs in | Libraries |
|---|---|---|
| Pi 4 B, Pi 5, Pi Zero 2 W | Python 3 (Pyodide) | gpiozero, RPi.GPIO, smbus2 and the rest of the libraries |
| Pico | Real MicroPython (the RP2040 port) | machine, utime, micropython |
A Pico build runs in the Sandbox, in Lab mode and in the Raspberry Pi Pico set in Practice: 77 problems whose tests run your MicroPython on a simulated Pico. The daily problem and the other practice sets are judged on a Pi, so they need pi = Pi().
In the Sandbox
Choose New… → Raspberry Pi Pico (MicroPython) in the sandbox's toolbar. It replaces circuit.py and main.py with a Pico starter:
# circuit.py
from wiring import *
pico = Pico()
pico.GP15 >> Resistor(330) >> LED("red") >> pico.GND
# main.py
from machine import Pin
import utime
led = Pin(15, Pin.OUT)
onboard = Pin(25, Pin.OUT) # the Pico's own green LED
while True:
led.toggle()
onboard.toggle()
utime.sleep_ms(500)
Any sandbox whose circuit.py builds Pico() runs main.py in MicroPython, so you can also change pi = Pi() to pico = Pico() by hand. Pin names follow the Pico: pico.GP15, pico.GP26 (ADC0), pico.V3_3, pico.GND, pico.pin(15) (a GP number) or pico.pin("P20") (a physical pin).
In Lab mode
The Boards group at the top of the Parts panel holds the three Pis and the Pico. Delete the board on the canvas, drag a Pico in, wire it, and press Run: the console shows MicroPython on Raspberry Pi Pico · main.py and the program runs in MicroPython. Open the Pico dimmer example (Projects → Examples) for a ready-made board with a potentiometer on the ADC, a PWM LED and a button interrupt.
A board can also hold a Pico and a Pi (or two Picos), each running its own program: the first controller keeps main.py and each later one runs <its id>/main.py; see Several controllers on one board.
Going deeper
- MicroPython is the real interpreter, not a shim:
Pin.irq,machine.Timer,PWM.duty_u16,ADC.read_u16,I2C,SPIandUARTbehave as on the board, with the RP2040's defaults. - The Pico is 3.3 V only and its ADC is 12 bits read as 16 (
read_u16). 5 V on a GP pin damages it, as on the real board. machine.reset()restartsmain.pyfrom the top.- Not simulated: PIO (
rp2), Wi-Fi (network, the Pico W) and USB devices. - Exporting a build for a real board covers the Pi only.