PyRasp

The course

This is a complete first course in MicroPython on a Raspberry Pi Pico. You do not need any electronics experience. You need curiosity, patience, and a habit of pressing Run.

How the course works

The pages are listed in teaching order. Start with Start here, then work through the lessons. Each module guide ends with the problems that practise it. After lesson 6, Ten things to build puts the foundations together into small, complete projects.

The exercises are the Raspberry Pi Pico set in Practice: every problem named on these pages links to it, and the set also has console problems (input and output, no wiring) for practising plain MicroPython. Your solved problems are ticked there.

Every lesson follows the same loop:

  1. Predict — before you run anything, guess what the board will do.
  2. Build — type the program, or start from the problem's starter.
  3. Run — watch the board and the console.
  4. Test — press Run tests. Every problem has checks, and a failing one says what it saw.
  5. Explain — say out loud why it worked. If you cannot, that is the part to re-read.
  6. Remember — do the three-bullet recap at the end of the lesson, then look away and say it.

A note on mistakes. A program that does not work is not a failure; it is a measurement. The console tells you what happened, the checks tell you what was expected, and the board shows you the truth. Read those three before changing anything.

What this Pico can do

This is a real MicroPython interpreter running on a simulated Raspberry Pi Pico. The board has a 40-pin header, 3.3 V logic, and the RP2040's limits. Everything below works:

You canMicroPythonLesson
Switch a pin on and offPin(n, Pin.OUT), value, on, off, toggle1
Read a pin, with a pull-up or pull-downPin(n, Pin.IN, Pin.PULL_UP)3
Measure time and sleeputime.sleep, sleep_ms, ticks_ms, ticks_diff2
Dim an LED, drive a servo or a buzzerPWM(Pin(n), freq=…), duty_u16, duty_ns6
Read a voltageADC(26), read_u16, read — GP26, GP27, GP28 only5
Talk to I²C devicesI2C(0, sda=Pin(4), scl=Pin(5)), scan, readfrom_mem, writeto_mem7, 8
Talk to SPI devicesSPI(0, sck=…, mosi=…, miso=…), write_readinto9
Listen to a serial deviceUART(0, baudrate=…, tx=…, rx=…), readline, any10
Run code later or periodicallymachine.Timer (cooperative, after sleeps)11
React to a pin changePin.irq() (cooperative, checked during sleeps)12
Draw on a 128×64 OLEDfrom ssd1306 import SSD1306_I2C and the display methods8
Light the on-board LEDPin(25) — not on the header1

What this Pico cannot do — and why

Not availableWhyWhat to do instead
Wi-Fi and BluetoothThis is a plain Pico, not a Pico WKeep data on the board; print it
PIO (programmable I/O)Not modelledUse SPI, I²C or UART
USB devices and the hardware watchdogOutside the simulatorSay so in the docs; do not design around it
Files that survive a runThere is no flash on the simulated boardPrint results, or keep them in variables
CircuitPython libraries (adafruit_…)No package store for the PicoUse machine, framebuf and the standard MicroPython modules
16-bit register addresses on I²CThe simulated devices use 8-bit pointersUse 8-bit registers

Fun fact. The real RP2040 has two 133 MHz cores, 264 KB of RAM and 2 MB of flash — and it costs about four dollars. The simulator reports 133 MHz, but your program's speed is your browser's speed. That is why timing lessons use utime, never instruction counting.

The modules

Module 1 — The foundations (lessons 1–6)

LessonYou will be able toProblems to try
1. Switch a pinMake a pin high or low and explain what “high” meansFirst blink, The Pico’s own LED, Alternating lights
2. Time and patternsUse sleeps and ticks to make a timed patternDouble blink, Running lights, Countdown
3. Read a pinRead a button, choose a pull-up or pull-down, and explain floating pinsButton mirror, Reaction game
4. Remember stateKeep a variable across presses, debounce a button, build a small state machinePress to toggle, Two-way switch, Short or long?, Three-mode light, Alarm panel, Servo switch
5. Measure a voltageRead an analogue voltage and map it to a useful numberRead a voltage, Night light, Sticky dimmer
6. Dim and moveUse duty and frequency to control brightness, position and soundPWM fade, Servo sweep, A steady tone, Three notes, Point where you look, Motor speed

Module 2 — Devices (lessons 7–10)

Full guide: Devices on a bus — I²C, the OLED, SPI and UART, with worked examples and the device checklist.

LessonYou will be able toProblems
7. I²C: meet a sensorScan a bus, read and write a registerFind the sensor, Wake the sensor, Is the sensor there?
8. I²C: draw on an OLEDInitialise a display and draw text and shapesWrite on the OLED, Count on the screen, Press counter on screen, A small menu, Bar graph, Sensor on screen
9. SPI: read a fast ADCRead channels of an MCP3008Read a channel, Two channels
10. UART: listen to a GPSRead and parse NMEA sentencesListen to the GPS, Read the GPS type

Module 3 — Time and events (lessons 11–12)

Full guide: Time and events — timers, pin interrupts and the cooperative model.

LessonYou will be able toProblems
11. TimersRun a callback periodically or once, and explain why it waits for a sleepBlink with a timer, One-second glow
12. Pin interruptsReact to a pin edge without a busy loopUse the patterns from Press to toggle and Short or long?

Module 4 — Real loads (lessons 13–14)

Full guide: Real loads — relays, MOSFETs, the L298N and motor safety.

LessonYou will be able toProblems
13. Switch a real loadUse a relay or a MOSFET to switch a 5 V lamp, fan or pumpRelay lamp, One relay, two lamps, Fan thermostat, Transistor switch, Night lamp, Plant waterer
14. MotorsDrive a DC motor forward, backward and at a speed with an L298NMotor forward, Motor reverse, Forward and reverse, Motor speed

Module 5 — Capstone (lesson 15)

Full guide: Build a system — planning, integration order, three worked capstones and what “good” looks like.

LessonYou will be able toProblems
15. Build a systemCombine a sensor, a display and an actuator into one programKitchen timer, Reaction game, Doorbell, Plant waterer, Tilt alarm, Colour mixer, Follow the light

How your work is judged

  • Run shows you the board and the console. Nothing is graded here.
  • Run tests runs the problem's checks in your browser. A failing check says what it saw: “switched on 0 times”, “was 0.00 at 1.20 s”, “there is no OLED on the board”.

The checks are written to be honest: a check that passes for the wrong reason is a bug in the problem, and we fix it. If a check surprises you, read its detail before changing your code.

The rules of the bench

  • 3.3 V logic. A GPIO is not 5 V tolerant. 5 V on a pin damages it for the rest of the run.
  • GP26, GP27 and GP28 are the only ADC pins.
  • GP25 is the on-board LED, not a header pin. GP23 and GP24 are not on the header either.
  • Wire as many parts as the lesson needs. A practice problem may set a parts budget; the Sandbox and Lab have none.
  • The board keeps running after main.py ends — press Stop to power it down.

A study plan that works

WhenWhat
Before a lessonRead its “You will be able to” line; try to predict the diagram
DuringType the code yourself; do not paste. Change one thing at a time
AfterExplain the program to someone (or a rubber duck) in three sentences
Next dayRebuild the program from memory; check the three-bullet recap
End of modulePick one problem you have not tried and solve it without the starter

The word bank has every term in plain language.


Next: Start here · Lesson 1: Switch a pin