Embedded C that survives lesson plan
The rules that keep C alive on a chip with 2 KB of RAM, each one broken on the Uno first: 16-bit int overflow, a missing volatile on an interrupt flag, F() and PROGMEM saving SRAM, out-of-bounds writes and signed shifts, String running the heap dry, MISRA-style rules, and a satellite sketch to audit.
Objectives and materials
By the end, students can
- What an int really is, what volatile does, and where const data lives.
- Undefined behavior, the heap, and rules a tool can check.
- Audit a satellite telemetry sketch with three hidden bugs.
Materials for the whole unit
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- 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.
Data on a small chip
What an int really is, what volatile does, and where const data lives.
| Lesson | Time | What students do |
|---|---|---|
| Fixed-width typesAn int is 16 bits on an Uno: five minutes in milliseconds comes out negative, a uint8_t counter wraps to 4, and a millis() interval stays right across the 49-day wrap. Fixed-width types say what you mean. | 55 min |
|
| volatileThe button’s interrupt runs, toggles the lamp and sets a flag, and loop() never sees it, because the optimizer kept the flag in a register. One keyword fixes it, and noInterrupts() makes a 4-byte read safe. | 45 min |
|
| const and flashThe Uno has 32 KB of flash and only 2 KB of SRAM, and every string literal is copied into SRAM at boot. A sine table in PROGMEM costs nothing, and F() on one help text gives back 308 bytes. | 45 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- Resistor
Check for understanding
Each student finishes "const and flash" 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: "const everything".
Code that cannot surprise you
Undefined behavior, the heap, and rules a tool can check.
| Lesson | Time | What students do |
|---|---|---|
| Undefined behaviorA loop that runs one step too far writes the knob reading over the alarm limit next door, so the alarm can never fire; a shift into the sign bit goes negative. Both compile cleanly; both are undefined behavior. | 45 min |
|
| Static allocationA telemetry log built with String eats the heap line by line until concat() fails at line 120; the same log in a fixed buffer, sized at compile time, runs for ever with the same largest free block. | 45 min |
|
| Coding standardsA heater’s command parser written to MISRA-style rules: fixed-width types, named limits, every input range-checked, a static_assert, no heap, and a switch whose impossible case finally says something. | 55 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Potentiometer
- Pushbutton
- Resistor
Check for understanding
Each student finishes "Coding standards" 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 house rules".
Boss project
Audit a satellite telemetry sketch with three hidden bugs.
| Lesson | Time | What students do |
|---|---|---|
| Boss: audit the satelliteA CubeSat telemetry sketch that compiles without a warning and has three bugs: a mission clock that overflows, a ground station call that loop() never sees, and a checksum written one byte past its buffer into the battery reading. Find each one, then fix it. | 65 min |
|
Materials
- Arduino Uno R3
- Full-size breadboard
- LED
- Pushbutton
- Resistor
Check for understanding
Each student finishes "Boss: audit the satellite" 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: "Write up the review".
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.