PyRasp

Start here

This section is a course in MicroPython on a Raspberry Pi Pico: a real MicroPython interpreter driving a simulated board, in your browser. You do not install anything.

There are two places to build on a Pico:

  • The Sandbox — circuit.py describes the parts and the wires, main.py is the program. Choose New… → Raspberry Pi Pico (MicroPython) in the Sandbox's toolbar to start from a Pico.
  • Lab mode — drag a Pico from the Boards group onto the canvas and wire parts by hand.

The Raspberry Pi Pico (MicroPython) explains how the Pico differs from a Pi in both places.

The one-minute tour (Sandbox)

  • circuit.py describes the parts and the wires. It is code, not drag-and-drop: what you write is what appears on the board. The Shop tab inserts a part's line for you.
  • main.py is the program the Pico runs.
  • The board is on the right. It is live while a program runs: pins light up, wires carry current, the LED glows and the OLED shows what you draw. The console under it shows what your program prints.
  • Run powers the board and starts main.py; while it runs, the same button says Stop.

Fun fact. The Pico is smaller than a stick of gum and has two processor cores. The model on your screen is about 1.3 MB of real firmware — the same MicroPython that runs on the plastic board.

Your first program

  1. In the Sandbox, choose New… → Raspberry Pi Pico (MicroPython). Replace circuit.py with:
    from wiring import *
    
    pico = Pico()
    pico.GP13 >> Resistor(330) >> LED("red") >> pico.GND

    Read the chain before you run anything: GP13 → 330 Ω → the LED → ground.

  2. Replace main.py with:
    from machine import Pin
    import utime
    
    led = Pin(13, Pin.OUT)
    
    while True:
        led.on()
        utime.sleep(0.5)
        led.off()
        utime.sleep(0.5)
  3. Press Run. The LED blinks once a second. The console shows only the MicroPython banner, because nothing is printed.
  4. Press Stop, then change 0.5 to 0.1 and run again. Predict what happens before you press Run. (It blinks five times a second, too fast to look like a clean blink.)

>> means “connect to”. You can add parts to the circuit the same way.

Careful. The circuit is the source of truth, not the picture. If a part disappears when you press Run, look at circuit.py: the code builds the board again from scratch each run.

Your first print

print writes to the console — the dark panel under the board. It is the cheapest debugging tool you have:

from machine import Pin
import utime

button = Pin(12, Pin.IN, Pin.PULL_DOWN)
while True:
    print("button", button.value())
    utime.sleep_ms(250)

The console shows a new line four times a second. When something is not working, print the numbers you think are true and compare.

The five rules of the bench

  1. 3.3 V logic. A GPIO is not 5 V tolerant. 5 V on a pin damages it for the rest of the run.
  2. Every circuit needs a ground. A wire that ends nowhere does nothing.
  3. An LED needs a resistor. 220–330 Ω is right on this board.
  4. Every while True loop needs a sleep. A loop with no sleep never gives the rest of the board a turn.
  5. GP25 is the on-board LED, not a header pin. GP23 and GP24 are not on the header either.

When it does not work

What you seeWhat to check
Nothing happens when you press RunIs the program stuck before your first output? Add a print at the top
NameErrorA missing import, or a typo in a name. Pin comes from machine
SyntaxErrorLook at the line number; check : at the end of if/while/for, and == versus =
The board says a pin is damaged5 V or too much current reached it. Undo the wire, then press Run again
A test fails but the board looks rightRead the check's detail: it may be watching a different time window, pin or part
The console is emptyprint only shows what you actually print; the board does not narrate itself

If you are stuck for more than ten minutes, write down three things: what you expected, what happened, and the smallest change you tried. That note is usually enough to find the bug.

Where to go next

A last thought. Programming is mostly reading: reading the problem, reading the error, reading what the board actually did. The typing is the small part. Be patient with the reading and the rest gets faster.