Let it Glow, Day 2: One LED, One Resistor and a Folder I Shouldn't Have Moved
It’s the 3rd of December and I’m writing up Day 2. Before anyone sends a sympathy card: I’m not behind. The Let it Glow calendar has twelve boxes, and December has twenty-four days before Christmas, so I’m opening one every other day. On the days in between I’ve got a Star Wars advent calendar, because I’m a grown adult and that’s the deal I’ve made with myself. Lights one day, a tiny plastic X-wing the next.
If you missed it, Day 1 was the setup: The Pi Hut’s Let it Glow calendar, a Raspberry Pi Pico H, MicroPython, and me asking Claude Code to stop doing everything for me and teach me instead. That gave us a do-nothing lesson script for each day, and Day 2 is the first proper test of it, because today there’s actual wiring. With my actual hands.
What’s in box two
- One 15 mm diffused “blocky” red LED
- One 100 Ω resistor
- Two male-to-male jumper wires
That’s it. Three things, and one of them is a bit of wire. It’s the electronics equivalent of a satsuma in your stocking, but you can’t build a Christmas light show without first lighting one light, so in it goes.
The theory, with a brew
The lesson opens with five explain steps before you go anywhere near the breadboard. I’ll admit my first instinct was to skip them. My second instinct was that people who skip the theory are the reason electronics shops sell replacement parts in bags of ten.
LEDs have a right way round. LED stands for Light Emitting Diode, and a diode only lets current through in one direction. The positive leg is the anode and the negative leg is the cathode. Normally the anode is the longer leg, which is helpful right up until you get a blocky LED with two legs the same length. On this one, the anode is the leg on the side with the text printed on it. Wire it backwards and nothing breaks; it just sits there, unlit and quietly judging you.
The resistor stops things getting exciting. An LED on its own will try to draw as much current as it can get, which is bad for the LED and bad for the Pico pin feeding it. A resistor in series limits the flow. The Pi Hut guide compares it to a narrow bit of pipe, and it doesn’t matter which side of the LED it goes.
This is where Ohm’s law turns up, probably for the first time since school:
current = voltage / resistance The Pico pin gives 3.3 V A red LED uses about 2.0 V Left across resistor 1.3 V 1.3 V / 100 Ω = 0.013 A ≈ 13 mA A bigger resistor means less current and a dimmer LED. That’s genuinely all the maths today, so you can put the calculator down.
Breadboards are wired inside. Each numbered column has five holes on each side of the centre gap, and those five are joined. They aren’t joined across the gap. Two legs in the same lane are connected; two legs in different lanes aren’t. Simple when you know it, baffling when you don’t.
Physical pins aren’t GP numbers. The Pico has 40 physical pins, numbered round the board, and separate GPIO labels, GP0 to GP28. In code you use the GP number. Today’s LED goes on GP14, which is physical pin 19, with ground on physical pin 18 right next to it. This is exactly the sort of thing I’d get wrong at 7am without a pinout open.
The lesson grows up a bit
Two changes since Day 1, both from using the thing rather than admiring it.
Step 1 now opens the guide. The Pi Hut’s guides have lovely photos and wiring diagrams, and no amount of clever terminal text beats a picture of where the wire goes. So the lesson library gained a guide helper, and every lesson now starts with:
━━ Step 1: Open today's guide [command] The Pi Hut's guide has the photos and wiring diagrams. Keep it open beside the terminal and use it alongside these steps. $ open 'https://thepihut.com/blogs/raspberry-pi-tutorials/let-it-glow-maker-advent-calendar-day-2-lighting-leds' Like every command step, it waits for you to press r. It’s a do-nothing script; it’d be rude not to ask.
Each day gets its own README. The root README was turning into the bottom drawer in the kitchen, so it’s now a short table that links to a README in each day’s folder, with the wiring, the scripts and the troubleshooting for that day.
Day 2’s lesson has 24 steps in four parts: theory, build, code and save. The build part is all manual steps, the ones where the script prints instructions and waits for you to do something with your hands:
7. [manual] Unplug the Pico 8. [manual] Place the LED 9. [manual] Place the resistor 10. [manual] Wire it to the Pico 11. [manual] Check before you power up “Unplug the Pico” comes first, every time. A stray wire on a live board is how the magic smoke gets out, and you can’t put it back in.
And it went well. The instructions worked, the LED lit, and nobody had to google “what does burning plastic smell like”. Having the Pi Hut’s guide open next to the terminal turned out to be the real win: the steps told me what to do, and the photos told me I’d actually done it. That bit of reassurance is worth a lot when you’re squinting at a breadboard before your first brew of the day.
The code
Five activities from the guide, each adding one idea:
| Script | What it does | New idea |
|---|---|---|
01_light_led.py | Turn the LED on | Pin(14, Pin.OUT), value(1) |
02_both_leds.py | Onboard LED and the red one together | several pins at once |
03_flash_basic.py | Flash twice, written out longhand | time.sleep() |
04_flash_loop.py | Flash forever | while True:, indentation |
05_flash_count.py | Flash ten times | for i in range(10): |
Activity 3 is there on purpose. Writing on, wait, off, wait by hand is so tedious that by the end you’re begging for a loop, which is exactly when Activity 4 gives you one. Sneaky. I approve.
Then two extras. The first flashes Morse code, using a dictionary of letters and a little flash() function. Change MESSAGE and it’ll blink your name, which is the most fun you can have with one red LED in December. The second fades the LED with PWM, like Day 1’s breathing onboard LED, but on a circuit I built myself, and it tidies up after itself when you press Ctrl+C:
try: while True: for duty in range(0, 65536, 1024): # brighter... red.duty_u16(duty) time.sleep_ms(10) for duty in range(65535, -1, -1024): # ...and dimmer red.duty_u16(duty) time.sleep_ms(10) except KeyboardInterrupt: # Ctrl+C lands here, so we can tidy up red.duty_u16(0) red.deinit() print("Stopped, LED off") That except matters more than it looks. Pins keep their last state when a program stops, so without it you can leave the LED stuck half-lit, glowing at you like it knows something.
Things that tripped me up
As tradition now demands, most of these were self-inflicted.
I moved the folder. In a fit of tidiness I moved the project from ~/src/github.com/PiHut-advent to ~/src/github.com/abuxton/PiHut-advent, where it belongs. Next time I ran pip:
.venv/bin/pip: bad interpreter: /Users/abuxton/src/github.com/PiHut-advent/.venv/bin/python3.15: no such file or directory It turns out a Python virtualenv writes its own absolute path into the first line of every script in .venv/bin. Move the folder and they all point at a Python that isn’t there any more. Venvs aren’t meant to be moved; you recreate them:
python3 -m venv --clear .venv .venv/bin/python -m pip install mpremote The nice trick is that .venv/bin/python -m mpremote kept working throughout, because it starts Python directly and never reads those broken first lines. The lesson scripts all use that form now, so I can move the folder again, and knowing me, I will.
One-letter variables are a trap, even for robots. The lesson library kept its colour codes in variables called B, D and R. Day 2’s lesson used D for its folder name. Bash variables are global by default, so the two trod on each other and the dry run started printing “day02” where the dim-text colour code should have been. To be fair to Claude, its own testing caught this before I ever saw it, and the library’s variables now all start with DN_. Still, it was quietly reassuring that I’m not the only one who names things badly.
Issues and non-default branches. A blog-only one, this. The Day 1 post’s pull request said “Closes #113”, got merged, and the issue stayed open. GitHub only auto-closes issues when a PR merges into the default branch, and this blog publishes from gh-pages, not main. So I close them by hand now, like an animal.
What’s next
The lesson ends with a recap and an instruction in capitals: leave the circuit in place. Tomorrow belongs to the Star Wars calendar, so the LED gets a day off. Then Day 3 is buttons, so it finally gets something to react to, which means inputs, and probably me learning what “debouncing” means the hard way.
Everything’s in abuxton/pihut-advent if you’re playing along at home. Put the kettle on, mind the polarity, and I’ll see you in two days. May the Force be with you in the meantime.
References
- The Pi Hut: Day 2 – Lighting LEDs
- abuxton/pihut-advent, Day 2
- Let it Glow: Learning the Raspberry Pi Pico One Advent Box at a Time
- Pico pinout
- Python docs: venv
- GitHub Docs: Linking a pull request to an issue
🤖 AI co-author: Claude Code