"The number that couldn't be true: when the code and its tests believe the same wrong thing"
The report said an idle Raspberry Pi 5, running on battery, was drawing 27.65 watts.
I read that line and said, more or less out loud, "no way." An idle Pi 5 draws a few watts. 27.65 W is a laptop charger working hard. Either the little board had found a way around physics, or the number was wrong.
It was the number. It had been wrong by a factor of ten since the first version of the code, and every automated test passed the whole time. The tests weren't broken. They agreed with the code perfectly, because the code and the tests had been written from the same wrong assumption.
This is the story of that number: how a hunch became evidence, then a fix, then a check that asks the physical world instead of the code. A small bug, with a lesson for any team that ships numbers people read.
Kestrel is my nights-and-weekends project, built with Claude as my AI teammate: an open-source Raspberry Pi device for authorized Wi-Fi security research, with a dashboard on your phone and optional add-ons like a battery board. It's unaffiliated with my employer, and the views here are my own.
The battery card
Kestrel can run from a Waveshare UPS HAT, a battery board with two lithium cells that sits on top of the Pi, so the device keeps going away from a wall socket while you test your own network. (Capture ships off, and turning it on takes an explicit confirmation that you're testing networks you own or have permission to test.)
A small chip on the board, the INA219, measures the battery. A Kestrel plugin reads it and puts a card on the dashboard: charge percent, charging or discharging, voltage, current and power. When the battery runs low, the same plugin shuts the Pi down cleanly, so a flat battery never corrupts the memory card.
Before every stable release, each beta runs on my test device, and a read-only check script produces a report that I read line by line. That's where the 27.65 W was.
From "no way" to evidence
A hunch isn't a bug report. So Claude and I looked for a second, independent measurement of the same battery.
The device had one. The card's time-to-shutdown estimate doesn't use the current at all: it watches the charge percent, which comes from the battery's voltage, fall over time. That falling trend fitted about 0.4 amps of real draw. The current reading said about ten times that, around 4,000 milliamps.
Two measurements of one battery, ten to one apart. That isn't noise. That's a scale.
A later run, with capture on, read about -4,994 mA and 35.5 W. Bigger, and just as impossible.
The assumption, in one line
The chip doesn't measure current directly. The current flows through a tiny resistor, called a shunt; the chip measures the small voltage across it and works out the current from the resistor's value. The software tells the chip what that resistor is, through a setting called the calibration.
Our code set the chip up for a 0.01 ohm resistor. The board carries a 0.1 ohm one, the one Waveshare's own example code for this board is written for. Divide by a resistor ten times too small and you get a current ten times too big. Power is current times voltage, so it was ten times too big as well.

That's the whole bug: one line in the plugin, choosing between two calibrations, each correct for some board, the wrong one for this board.
Why every test passed
Before the fix, the tests checked:
- that the plugin programs the 16V_5A calibration, the one for a 0.01 ohm resistor;
- that this calibration holds exactly the numbers from Waveshare's code for that setting;
- that a given chip reading turns into the right milliamps under each calibration.
All true. One test was even named for it: the 16V_5A calibration is what ups-ws programs. It was. The tests encoded the assumption, so they could only confirm it.
And no simulated chip could have caught it. A fake chip in a test suite has no resistor. The truth lived in one place only: a real board, with a real battery, under a real Pi.

We had written it down
Here's the part I like best: the doubt was already on paper. When this code moved into a shared library, less than two weeks earlier, we noticed that our setting didn't match Waveshare's example for this board and recorded it in the project's list of deferred work: confirm the calibration on hardware. The entry even predicted the symptom: if the board's resistor was 0.1 ohm, "the card's current and power read about ten times too high".
It also said why we didn't simply switch: there was no board on hand to measure, and changing shipped values blind could make them wrong instead. The code carried the same note, keeping the old setting "until a measurement on the board says otherwise".
That was a reasonable call, and it was only half the job. Writing an assumption down makes it visible. Checking it against the world is what settles it. In the end, the measurement that said otherwise wasn't a meter. It was a person who knew roughly what a Pi draws, reading a report and refusing to believe it.
What was never wrong
With any battery bug, the first question is whether anything was at risk. Here, no.
- The charge percent comes from the battery's voltage, not the current.
- Charging or discharging comes from which way the current flows, not how much. A Pi on battery draws hundreds of milliamps, far past the small dead zone around zero, so the direction read right at either scale.
- The low-battery shutdown uses exactly those two, plus three low readings in a row. It never looked at the size of the current.
- The time-to-shutdown estimate follows the voltage-based percent too, which is why it could serve as the cross-check.
Only the two numbers on the card, current and power, were wrong. Answering "what else uses this number?" means reading every path that touches it: work an AI teammate turns into minutes, not an anxious evening.
Hunch to fix, the same day
- Evidence: the voltage trend against the current reading, ten to one.
- Reference: Waveshare's example code for this board uses the 32V_2A calibration, made for a 0.1 ohm resistor.
- Fix: the plugin now programs 32V_2A. Its tests now pin that, and the old setting's test now says what that setting is really for: Waveshare's example code for two other boards in the family.
- Ship: reviewed, merged and out in 1.0.14-beta.4 on November 12, the same day.

To be clear: the fix isn't confirmed on the device yet. The arithmetic, the vendor's reference and the voltage trend all point the same way, but the proof is the board itself, and the next beta check is where that happens.
A test that asks physics
That check is the part I'd keep even if the fix had been trivial. The beta-check script now has three items for this:
- one confirms the installed plugin programs the new calibration (a check against the code, still worth having);
- one reads the dashboard and, when the device is on battery, requires the current to be under 3,000 mA, a generous ceiling for what a Pi draws from this board; the old setting's idle reading, about 4,000 mA, fails it;
- one stays a by-hand check: look at the card on battery.
The second is the new idea. It doesn't ask what the code says the number should be. It asks whether the number is physically possible. It's coarse on purpose: it can't tell 400 mA from 600 mA. But it doesn't share the code's assumptions, so it can't be fooled by them.
For the engineers in the room
- Both settings are named after Waveshare's demo functions and live in one shared INA219 library; the plugin picks one with a single constant. Per step of shunt voltage, 16V_5A works out to 26,868 / 4,096 x 0.1524 mA, about 1.0 mA, and 32V_2A to 4,096 / 4,096 x 0.1 mA = 0.1 mA. Ten to one: the resistor ratio.
- 16V_5A also sets an 80 mV shunt range. On a 0.1 ohm resistor, that runs out at 0.8 A.
- The capture-on reading was more telling than it looked: -4,994 mA is, to the milliamp, the most negative value the chip's 16-bit current register holds at 0.1524 mA a step (-32,768 x 0.1524). That reading wasn't just scaled wrong; it had run out of scale.
- 32V_2A uses a 320 mV range: about 3.2 A on this resistor, just above the check's 3,000 mA ceiling.
For engineering leaders
- Tests prove consistency, not truth. A test written from the same belief as the code checks that you built what you meant. Somewhere, a check has to come from outside: the vendor's reference, a second measurement, or physics.
- Put plausibility ranges on numbers people read. "Under 3,000 mA on battery" is one line, and it fails the old number on the first run.
- Cross-check with an independent signal. Two measurements of one battery turned "that looks wrong" into "it's ten times off" within minutes.
- A deferred item needs a check, not just a description. Ours described the risk perfectly. What it lacked was a step that runs on its own once a board is available, which is what the beta check now is.
- Keep the human glance in the loop. Claude read the code paths, did the arithmetic, traced everything that used the number, and wrote the fix and the checks in hours. Knowing that a Raspberry Pi doesn't idle at 27 watts came from experience. That's the combination: judgment raises the flag, and an AI teammate makes acting on it cheap.
For investors
Every company runs on numbers somebody's code produced: usage, revenue, model accuracy, battery life. Ask teams how they know those numbers are right, and listen for the difference between "our tests pass" and "we checked against something outside our own code". A team that can name its independent check, and tell you about the time it caught something, has a measurement culture. A team whose only proof is its own test suite is grading its own homework.
It's the same lesson as the model that never lost a contest, in hardware this time: a perfect record from a check that shares your assumptions isn't a record at all.
If posts like this are useful to you, subscribe and the next one lands in your inbox.
What number on your dashboard has never been checked against the physical world? 🪶
Kestrel is a personal, open-source project built on nights and weekends, unaffiliated with my employer, and for authorized testing only. The user guide and source are public.
Member discussion