Under the hood lesson plan
Take the Arduino wrapper off: DDR, PORT and PIN, Timer 1 by hand, the vector table and interrupts, cycle-counted delays in a .S file, a bug read off a halt in the debugger, and a UART drawn by hand on a pin.
Objectives and materials
By the end, students can
- Pins and a timer, written register by register.
- The vector table and handlers that run while loop() sleeps.
- Count cycles in a .S file, and read a halted board.
- A UART frame drawn by hand on a plain pin.
Materials for the whole unit
- Arduino Mega 2560 R3
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Logic analyzer, four channels
- Pushbutton
- Resistor x 3
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.
Registers
Pins and a timer, written register by register.
| Lesson | Time | What students do |
|---|---|---|
| DDR, PORT and PINThe three registers behind every digital pin: count in binary on three lamps with one write to PORTB, turn on a pull-up through PORTD, and read a button straight out of PIND. | 50 min |
|
| Timers by handTimer 1 set up register by register: a prescaler, CTC mode and OCR1A for a match every 500 ms, the compare flag polled and cleared by hand, and no millis() anywhere. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Timers by hand" 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 own period".
Interrupts
The vector table and handlers that run while loop() sleeps.
| Lesson | Time | What students do |
|---|---|---|
| The vector table and interruptsThe 26 jumps at the start of flash, read out of the chip itself: a Timer 1 interrupt that blinks while loop() sleeps, an INT0 handler that counts presses, volatile, and reading shared data safely. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "The vector table and interrupts" 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: "Which vector is which".
Assembly and the debugger
Count cycles in a .S file, and read a halted board.
| Lesson | Time | What students do |
|---|---|---|
| Cycle-counted delays in a .S fileCount a loop in CPU cycles from the data sheet and measure it with Timer 1, then write the delay as a function in its own assembly file and call it from C++. | 45 min |
|
| Reading a halt in the debuggerTen readings of 30 that average 4: stop the Uno on a breakpoint, watch a variable climb, step one instruction and read the carry flag in SREG, then fix the bug the halt showed you. | 50 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED x 3
- Pushbutton
- Resistor x 3
Check for understanding
Each student finishes "Reading a halt in the debugger" 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: "The lamp agrees".
Speak a protocol
A UART frame drawn by hand on a plain pin.
| Lesson | Time | What students do |
|---|---|---|
| Bit-banging a protocolDraw UART frames by hand on a plain pin with counted delays, let the Mega's real USART receiver judge them, read them on the logic analyzer, and break the baud rate on purpose. | 50 min |
|
Materials
- Arduino Mega 2560 R3
- Logic analyzer, four channels
Check for understanding
Each student finishes "Bit-banging a protocol" 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: "Say something else".
Teach this unit as a class
Start a class from this course and its 6 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.