← All posts

Bench notes · Debugging · MicroPython

What are you avoiding? The fault you won't name

11 Nov 20265 min read

Every project on my bench has one problem I'd rather not look at. Usually it's the one that matters most.

Carl Jung had a line of thinking about this. The direction we don't want to look in is almost always where we'll find what we need. He didn't ask anyone to face everything at once. He asked for something smaller: give a name to what you're avoiding. What isn't named can't be examined. And what isn't examined keeps running things from the shadows.

That's a psychology idea. It's also one of the most practical pieces of debugging advice I know.

The faults we walk around

In electronics, avoidance rarely looks like avoidance. It looks like being busy with something else. A few I see again and again, in my own builds and in projects people bring to me:

None of these are hard to look at. They're uncomfortable, because looking might mean a redesign. So they sit in the shadows and quietly decide how reliable the product is.

Naming it is the first fix

Before electronics, I worked as a clinical pharmacist. Hospitals have a habit I've carried to the bench: near-miss reporting. You write down the error that almost happened, while it's still small. Not to assign blame, but because a problem with a name and a date can be tracked. A vague unease can't.

Jung's advice maps neatly onto engineering:

  1. Name it. "The board resets" becomes "the board resets, cause unknown, roughly twice a day".
  2. Measure it. Log it, timestamp it, count it. Now it's data instead of a feeling.
  3. Examine it when you're ready. You don't have to fix it today. But once it's in a log, it stops governing the project from the shadows.

You'll often find the named problem is smaller than the one you were dreading. Sometimes it's bigger. Either way, you're deciding with your eyes open.

Try it: give your random reset a name

Here's a tiny first step for the most common avoided fault. This script records why the board restarted, every time it boots. It's MicroPython, loaded with Thonny, and runs on a Raspberry Pi Pico or an ESP32.

Save it to the board as boot.py so it runs before your main program:

boot.py
# AP Design Labs - "Name it" reset logger
# Records WHY the board restarted, every time it boots.
# MicroPython, save as boot.py with Thonny. Pico or ESP32.
import machine

# Look up the reset causes this board's firmware knows about
CAUSES = {}
for name in ("PWRON_RESET", "HARD_RESET", "WDT_RESET",
             "DEEPSLEEP_RESET", "SOFT_RESET"):
    if hasattr(machine, name):
        CAUSES[getattr(machine, name)] = name

code = machine.reset_cause()
label = CAUSES.get(code, "UNKNOWN_" + str(code))

# Count earlier boots so each entry gets a number
try:
    with open("resets.log") as f:
        boots = len(f.readlines())
except OSError:
    boots = 0

with open("resets.log", "a") as f:
    f.write("boot {}: {}\n".format(boots + 1, label))

print("Boot", boots + 1, "- last reset:", label)

Download the script Rename it to boot.py on the board.

Leave the board running in its real home for a few days. Then open Thonny's View → Files panel, open resets.log on the device, and read what it tells you:

Log saysWhat it means
PWRON_RESETIf you didn't cause it by unplugging the board, suspect the supply. On a Pico, a voltage dip usually shows up this way. Check your regulator, your battery under load, and what happens when the LoRa radio transmits.
WDT_RESETYour code hung and a watchdog caught it. Good news, because now you know to look for a blocking call or a stuck sensor read.
HARD_RESETThe reset pin or a hard fault. Check for a noisy RUN/EN line or long, unshielded wires.
SOFT_RESETUsually just you pressing Stop or Ctrl+D in Thonny. Ignore these while you're developing.
Two notes

Each boot adds one short line to flash, so delete resets.log now and then. And the exact constants vary between ports and firmware versions, which is why the script checks for each one rather than assuming it exists.

Name one thing this week

So, what are you avoiding on your bench? The flicker you haven't scoped. The current draw you haven't measured. The test you haven't run because you suspect how it ends.

You don't have to fix it this week. Just name it. Write it on the whiteboard, put it in your project notes, or add a line of code that logs it. Once it has a name, it's no longer running the project from the shadows. You are.

Got a gremlin?

A second set of eyes on your project

If you've got a gremlin in a LoRa, solar or sensor project and want a second set of eyes, get in touch with AP Design Labs. Naming the fault is half the job.

See Custom Design →Request a callback

#Debugging#MicroPython#ESP32#RaspberryPiPico#Reliability