Back

Debug Challenge: Circuits

Difficulty  

Optional — Extra Credit

divider

Objective

Four programs. All four are correct. Every one of them has been run on a board that does the wrong thing anyway.

Every debug challenge you have done so far had the bug in the code. These have the bug in the wiring — which is a different kind of hunt, because reading the program harder will never find it.

Skills to Practice

  • Deciding whether a fault is in the code or on the board
  • Reading a symptom for what it rules out
  • Checking polarity, power, and ground before suspecting logic
  • Knowing which mistakes produce silence and which produce nonsense

How to Work These

For each one, answer two questions: what is wrong on the board, and how would you confirm it without just rewiring everything and hoping.

Read the symptom carefully first. A part that does nothing at all is telling you something different from a part that does the wrong thing, and both are different again from a part that works but badly.


The Four Boards


Bug 1

Symptom: the program runs. No error appears. The LED never lights at all, not even faintly. A different LED swapped into the same holes works fine.

Bug 1
from machine import Pin
import time
led = Pin(28, Pin.OUT)
while True:
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(0.5)
[PHOTO PLACEHOLDER — Bug 1: The Board As Wired]

The last sentence of the symptom is the clue. If a fresh LED works in the same holes, the holes are fine and the pin is fine. So what is different about the first one?


Bug 2

Symptom: prints a mixture of 0s and 1s at random with nobody touching the button. Pressing it does make 1s more likely, but releasing it does not reliably give 0.

Bug 2
from machine import Pin
import time
button = Pin(33, Pin.IN)
while True:
print(button.value())
time.sleep(0.2)
[PHOTO PLACEHOLDER — Bug 2: The Board As Wired]

This one is half a code problem and half a wiring problem, which is why it is here. Compare line 4 against how you created every button in Activity 2.7, then ask what is holding that pin at a known value when the button is open. Nothing is.


Bug 3

Symptom: all five LEDs light in turn, as intended. But they are dim, and each one gets dimmer as the next one joins. By the fifth they are barely visible.

Bug 3
from machine import Pin
import time
leds = [
Pin(28, Pin.OUT),
Pin(29, Pin.OUT),
Pin(30, Pin.OUT),
Pin(31, Pin.OUT),
Pin(32, Pin.OUT),
]
for led in leds:
led.value(1)
time.sleep(0.4)
[PHOTO PLACEHOLDER — Bug 3: The Board As Wired]

Nothing is broken and nothing is backwards — the circuit works, it just works badly. The behavior changing as more LEDs come on is the whole clue. What could five LEDs be sharing that they should each have had one of?


Bug 4

Symptom: the program runs and finishes. No error. The motor does absolutely nothing — no movement, no sound, no twitch. The battery pack is fresh and the motor works when touched directly to it.

Bug 4
from machine import Pin, PWM
import time
a_in1 = Pin(31, Pin.OUT)
a_in2 = Pin(32, Pin.OUT)
a_pwm = PWM(Pin(33))
a_pwm.freq(1000)
a_in1.value(1)
a_in2.value(0)
a_pwm.duty_u16(40000)
time.sleep(2)
a_pwm.duty_u16(0)
[PHOTO PLACEHOLDER — Bug 4: The Board As Wired]

The motor is fine and the battery is fine, so the fault is between them. There are two classic culprits on this driver, and both produce exactly this silence: one is a pin that has to be HIGH before the chip will listen to anything, and the other is a connection two separate parts of the circuit both need to share.

divider

Submit

For each of the four, write down:

  1. What is wrong on the board
  2. How you would confirm it, in one step, before rewiring anything
  3. Which of the four could have been found by reading the code — and which could not

That last question is the point of the whole exercise. Getting used to asking is this even a code problem? will save you more time than any single fix.

Commence Challenge