Source: https://mokxi.com/teachers/plans/concurrency-fundamentals
Updated: 2026-11-19

Lesson plan

# Concurrency: tasks, races and async lesson plan

Concurrency on one core in MicroPython on a Pico: superloops, interrupt races measured for real, critical sections, coroutines, asyncio, queues, and a responsive multi-sensor box.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi Pico. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- From a blocking loop to a superloop, then interrupts and the race they bring.
- Critical sections, the no-memory rule of hard interrupts, and micropython.schedule.
- Generators as coroutines, a scheduler by hand, asyncio, and queues with backpressure.
- A multi-sensor box that never stops answering, with its lag measured.

### Materials for the whole unit

- Clock
- LED
- Potentiometer
- Pushbutton
- Raspberry Pi Pico
- Resistor

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 20 min

## Two things at once

From a blocking loop to a superloop, then interrupts and the race they bring.

Lesson | Time | What students do

Doing two things Why one sleep() ruins a two-job program, and the superloop that fixes it: timestamps, ticks_diff and a debounced button. | 40 min

- Run it
- The button that does not listen
- The superloop
- A third job
- Why ticks_diff and ticks_add

Interrupt races A hard interrupt counts a 1 kHz wheel sensor. Put a little work in the wrong place and ticks vanish: a real race, measured. | 40 min

- An interrupt counts
- Spin it faster
- A little work in between
- Count what went missing
- Read, modify, write

### Materials

- Clock
- LED
- Potentiometer
- Pushbutton
- Raspberry Pi Pico
- Resistor

### Check for understanding

Each student finishes "Interrupt races" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Read, modify, write".

Chapter 2. About 40 min

## Sharing safely

Critical sections, the no-memory rule of hard interrupts, and micropython.schedule.

Lesson | Time | What students do

Critical sections Close the race for good with disable_irq, measure how long interrupts stay off, then meet the rule hard interrupts live by: no new memory. | 40 min

- The race again
- Shrink the window
- A critical section
- No new memory in a hard IRQ
- Schedule the heavy part

### Materials

- Clock
- LED
- Potentiometer
- Pushbutton
- Raspberry Pi Pico
- Resistor

### Check for understanding

Each student finishes "Critical sections" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Schedule the heavy part".

Chapter 3. About 2 h

## Cooperative tasks

Generators as coroutines, a scheduler by hand, asyncio, and queues with backpressure.

Lesson | Time | What students do

Coroutines Generators are functions that pause. Build a round-robin scheduler, then one that sleeps: the engine inside every async library. | 40 min

- Functions that pause
- A third task
- Tasks that sleep
- And the heartbeat beats
- The hog

asyncio in MicroPython Tasks with async and await, the blocking mistake that freezes them all (measured), and a hard IRQ waking a task through ThreadSafeFlag. | 40 min

- Two tasks, built in
- The button task
- A third task
- The blocking mistake
- An interrupt wakes a task

Queues A ring buffer an interrupt can fill without allocating, what happens when the consumer is too slow, and a queue class with backpressure for tasks. | 40 min

- A ring buffer
- One press, many edges
- Flood it
- Work in batches
- A queue for tasks

### Materials

- Clock
- LED
- Potentiometer
- Pushbutton
- Raspberry Pi Pico
- Resistor

### Check for understanding

Each student finishes "Queues" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A queue for tasks".

Chapter 4. About 50 min

## Boss

A multi-sensor box that never stops answering, with its lag measured.

Lesson | Time | What students do

Boss: a responsive multi-sensor box Everything at once: an IRQ-counted wheel with a critical section, a smoothed knob in slices, a flag-driven button, a heartbeat, an alarm and a lag watchdog. | 50 min

- Power it up
- Overspeed
- Turn the knob
- Change mode
- Measure the lag
- Your design review

### Materials

- Clock
- LED
- Potentiometer
- Pushbutton
- Raspberry Pi Pico
- Resistor

### Check for understanding

Each student finishes "Boss: a responsive multi-sensor box" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Your design review".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
