Python & GPIO: code meets circuit
420-302-VA · WEEK 4 · FALL 2026

Stage 6 of 6 · Logistics, evidence, next steps

Lab & hand-in

No graded demo today; the grade pressure returns with the midterm in three weeks. Instead the lab has a ladder: everyone reaches the toggle, and the rungs above it separate "it ran" from "I can build with it". Here is the clock, the evidence, and the road to Week 5.

The two hours

MinutesYou doCheckpoint before moving on
0–10Wire the station (Week 2 order), boot, SSH in from the lab PC.Key-based SSH prompt shows username@lastname-pi.
10–25Environment: create ~/iot/week4/.venv, activate, test pip, write .gitignore, first commit.(.venv) in the prompt; import gpiozero succeeds.
25–45Python warm-up: REPL arithmetic, hello.py with variables and an f-string, a loop with sleep(), one traceback caused and fixed.Both partners have typed and run code, not watched it.
45–55Wire the LED and button, powered down; trace aloud.Verifier signs off pin-by-pin against the diagram.
55–95First light: blink.py, press.py, events.py, toggle.py, committing after each.Toggle works; git log --oneline shows the four steps.
95–110The practice ladder, as far as time allows.Each rung committed separately.
110–120Assemble and upload the evidence, answer the exit ticket, clean shutdown, pack.Drive returned; kit packed; station restored.

Working as a pair

Same operator/verifier discipline as Weeks 2 and 3, with a twist suited to code: swap at the keyboard, not just at the checklist. Partner A types the Python warm-up while B verifies; B types the circuit scripts while A verifies the wiring and reads the diagrams. Both push commits from their own account where machines allow (the shared Pi user is fine; the commit author from Week 1's config is what traceability reads). The midterm is individual; a partner who only watched this lab will feel it in Week 7.

The practice ladder

In order of difficulty; each rung is a separate script and a separate commit. Rung 3 upward is excellent midterm preparation.

  1. Heartbeat

    Change blink.py to a while True: heartbeat: short on, long off. One variable controls the tempo. (Loop and variables.)

  2. SOS

    Blink the pattern three-short, three-long, three-short, using a function flash(duration) called from loops. (Functions with parameters.)

  3. Press counter

    Extend events.py: count presses in a variable and print the running total in the handler. (State that survives between events.)

  4. Hold-to-arm

    LED lights only while the button is held: when_pressed = led.on, when_released = led.off. Then invert it. (Two events, one system.)

  5. Double-blink acknowledge

    On each press, blink the LED twice quickly, then return to its previous state. Requires an if on led.is_lit, a loop, and thought. (Everything at once.)

What to hand in

Most of the evidence is your repository, which is the point. Assemble the rest with scp exactly as in Week 2's practice, then upload to Omnivox:

ItemHow to produce itShows that
Repository URLPaste into the Omnivox formhello.py, the four circuit scripts, ladder rungs, and .gitignore, with commits from both partners
env.txt(.venv) $ python --version > env.txt && which python >> env.txt && pip list 2>/dev/null | head -n 15 >> env.txtThe environment exists, is active, and can import the GPIO stack
circuit.jpgPhone photo of the breadboard with the LED lit, both loops visibleThe wiring matches the diagram and worked
station.txtTyped in nanoStation number, Pi model, boot-drive label, both names, exit-ticket answers if asked

Counts as completion of in-class work. Private keys never appear in evidence (Week 3's rule stands), and neither does the .venv folder (this week's).

Exit ticket

Answer without looking at the hub; write the answers at the end of station.txt if the teacher asks for them.

  1. What does the interpreter do with blink.py, line by line?
  2. Why did pip install fail outside the venv, and what made it work inside?
  3. Recompute the LED current with the resistor from your kit. Is it inside the pin budget?
  4. LED(17): which physical pin is that, and how do you check?
  5. Polling versus events: which did toggle.py use, and why does it need pause()?

Packing up

Homework and next week

This week's homework (2 h)

Make the syntax automatic

Finish any ladder rung left undone. Read chapters 1 and 2 of Automate the Boring Stuff (free online) and do their small exercises in the REPL, on any computer. Browse three gpiozero recipes that use parts from your kit and note, in your journal, one you want to build; the journal feeds the Week 7 reflection log.

Week 5 · September 28

Requirements and pseudocode

This week you built from a finished diagram and finished code. Next week you learn to produce those yourself: stating what a system must do as testable requirements, sketching how in pseudocode, and only then writing Python. It is the working method of Assignment 2 and the project. Bring the breadboard kit; the exercises stay hands-on.