Lesson plan

Firmware architecture lesson plan

How a whole device is put together on the Uno: a scheduler and state machines, ISRs that only record, drivers behind interfaces, checked settings in EEPROM, error codes and the watchdog, safe updates, and a layered multi-sensor boss.

4 chapters, 7 lessons, about 7 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • A superloop, a scheduler, a machine in a table, and ISRs that only record.
  • Drivers behind interfaces, and settings that survive a reset.
  • Error codes, fail-safe states, the watchdog, and updates that cannot brick.
  • A multi-sensor machine guard built from every layer in the course.

Materials for the whole unit

  • Arduino Uno R3
  • Character LCD with I2C backpack
  • Full-size breadboard
  • Half breadboard
  • Hall sensor, A3144
  • LED x 3
  • Photo interrupter, slot
  • Pushbutton
  • Resistor x 3
  • Temperature and humidity, DHT22
  • Temperature sensor, LM35

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 2 h

Structure

A superloop, a scheduler, a machine in a table, and ISRs that only record.

LessonTimeWhat students do
Superloops and state machinesA cooperative scheduler that runs tasks on their own periods, a state machine whose behavior lives in a transition table, and a stopwatch on every pass of loop() that catches a task breaking the one rule.60 min
  1. Run it: five tasks, one loop
  2. A task is a period and a deadline
  3. Measure the loop
  4. Drive the machine
  5. Events from anywhere
  6. Break the rule
  7. Change behavior by changing data
Interrupts and buffersAn ISR that only records each edge and its time into a ring, a main loop that drains and debounces it, volatile and atomic reads done right, and an overflow counter that tells you when the loop fell behind.60 min
  1. Run it: the ISR is armed
  2. One press, through both halves
  3. Count the bounce
  4. volatile, and reads that cannot tear
  5. Fall behind
  6. Read the damage
  7. Size the ring for the burst

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED x 3
  • Pushbutton
  • Resistor x 3

Check for understanding

Each student finishes "Interrupts and buffers" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Size the ring for the burst".

Chapter 2. About 2 h

Layers

Drivers behind interfaces, and settings that survive a reset.

LessonTimeWhat students do
Drivers and hardware abstractionA comfort monitor that only talks to a ClimateSensor and a Display interface: a DHT22 driver, an LCD driver, and a scripted fake that plays a heat wave, a dry room and a dead sensor on demand.60 min
  1. Run it: three layers
  2. The driver keeps the data sheet's promises
  3. Heat the room
  4. Swap in a fake
  5. Kill the sensor on demand
  6. What an interface costs
  7. Boot on the fake
Configuration and EEPROMSettings in an envelope: a magic number, a version, a size and a CRC-16, checked field by field at every boot, defaults when anything is off, only changed bytes written, and a watchdog reset to prove it all survives.60 min
  1. Run it: a blank chip
  2. Change a setting
  3. Write only what changed
  4. Reset, and it is still there
  5. Flip one bit
  6. A CRC checks bytes, not sense
  7. Ship a new default

Materials

  • Arduino Uno R3
  • Character LCD with I2C backpack
  • Full-size breadboard
  • Half breadboard
  • LED x 3
  • Pushbutton
  • Resistor x 3
  • Temperature and humidity, DHT22

Check for understanding

Each student finishes "Configuration and EEPROM" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Ship a new default".

Chapter 3. About 2 h

Survive the field

Error codes, fail-safe states, the watchdog, and updates that cannot brick.

LessonTimeWhat students do
Error handling and watchdogsA heater controller whose functions return error codes, a policy table that retries or trips a latched fail-safe, and the chip's real watchdog in its two-stage mode: task check-ins, last words saved to EEPROM, then a reset.60 min
  1. Run it: a heater with a guard dog
  2. Error codes, not made-up numbers
  3. Retries run out: fail safe
  4. A person clears the fault
  5. Hang it: the watchdog bites
  6. Stall it: check-ins catch what feeding misses
  7. Some errors trip at once
OTA and bootloader conceptsHow a device updates itself without ever bricking: A/B slots, an image header with a version, a length and a CRC-32, trial boots that must confirm, automatic rollback, and a minimum version that refuses a perfect copy of old firmware.60 min
  1. Run it: two slots, one decision
  2. Why two slots
  3. The header: trust nothing you cannot check
  4. Trial boots and rollback
  5. Confirm
  6. Refuse a perfect old image
  7. Give up sooner

Materials

  • Arduino Uno R3
  • Full-size breadboard
  • LED x 3
  • Pushbutton
  • Resistor x 3

Check for understanding

Each student finishes "OTA and bootloader concepts" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Give up sooner".

Chapter 4. About 1 h 5 min

Boss

A multi-sensor machine guard built from every layer in the course.

LessonTimeWhat students do
Boss: a layered machine guardThe sensor lab becomes a real device: drivers for an LM35, a Hall switch and a slotted wheel, a scheduler with check-ins, a table-driven machine, checked thresholds in EEPROM, error codes and a latched trip.65 min
  1. Run it: six layers, one device
  2. Ask the drivers
  3. Close the guard, start the spindle
  4. Open the guard: trip
  5. Clear it only when it is safe
  6. Warm, then too hot
  7. Cut the sensor wire
  8. Ship a cooler warning

Materials

  • Arduino Uno R3
  • Hall sensor, A3144
  • Photo interrupter, slot
  • Temperature sensor, LM35

Check for understanding

Each student finishes "Boss: a layered machine guard" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Ship a cooler warning".

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.