Session 8: Serial commands and debugging
Learning outcomes
- Explain UART framing and why both ends need the same baud rate
- Read single-character commands with Serial.available() and Serial.read()
- Use temporary Serial traces to locate a logic fault
- Capture a transmitted character on the oscilloscope
Kit and components
- Uno, USB cable and lab PC
- Oscilloscope
Pre-reading about 25 min
Students read these on their phones before class. They are listed on the student Before class page.
Session plan
- 0:0010 minRecap
Quiz: switch and truth tables
- 0:1025 minDemo
Commands and the wire
Send 1 and 0 from the Serial Monitor to switch the LED. Put the scope on TX (D1), trigger on a falling edge at 1 ms/div and capture one character: start bit, eight data bits, stop bit, about 104 µs per bit at 9600 baud.
- 0:3535 minBuild
Worked sketch plus your own command
Students upload the worked sketch, then add a command of their own - for example b to blink five times - using a switch on the received character.
- 1:1035 minBuild
Trace the planted fault
Give pairs a sketch with a hidden logic fault in a mode chain. They add Serial traces, find the fault and log the symptom, the trace output and the fix.
- 1:4515 minWrap-up
Debugging steps
Students list the steps they followed; compare with the lesson's debugging strategy.
Checkpoint: ready to move on?
Students can control an output from the Serial Monitor and describe the steps they used to find the planted fault.
Extension for fast finishers
Add a help command that prints the menu, and one that reports the uptime.
Catch-up path
Keep the worked sketch unchanged and add a single command; practise reading the trace output.
Homework and practice
Pre-reading for S9, and Code Along 3.6 if not done.
Facilitator notes
- On some PCs the Serial Monitor must be closed before uploading.
- Probe D1 (TX), not D0, for the clearest UART capture.