Lesson plan

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.

4 chapters, 6 lessons, about 5 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

  • 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.

Chapter 1. About 1 h 40 min

Registers

Pins and a timer, written register by register.

LessonTimeWhat 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
  1. Run it: no pinMode anywhere
  2. PORT on an input is the pull-up
  3. One write, three lamps
  4. Read PIN
  5. Count faster
  6. Find it in the data sheet
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
  1. Run it: a blink with no millis()
  2. The arithmetic
  3. Wait for the flag
  4. Read the counter
  5. Ten times a second
  6. Your own period

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".

Chapter 2. About 50 min

Interrupts

The vector table and handlers that run while loop() sleeps.

LessonTimeWhat 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
  1. Run it: read the table
  2. An interrupt blinks while loop() sleeps
  3. Count presses in INT0
  4. volatile, and reading safely
  5. Switch one interrupt off
  6. Which vector is which

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".

Chapter 3. About 1 h 35 min

Assembly and the debugger

Count cycles in a .S file, and read a halted board.

LessonTimeWhat 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
  1. Run it: 202 cycles
  2. Count it yourself
  3. Write it in a .S file
  4. Blink with your function
  5. When counting cycles lies
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
  1. Run it: a wrong answer, no error
  2. Stop on a line
  3. Watch it climb, and fall
  4. Read the carry flag
  5. Fix it
  6. The lamp agrees

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".

Chapter 4. About 50 min

Speak a protocol

A UART frame drawn by hand on a plain pin.

LessonTimeWhat 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
  1. Run it: a UART with no UART
  2. Draw a frame
  3. The hardware agrees
  4. See it on the analyzer
  5. Break the baud rate
  6. Say something else

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".

Your class

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.