Read the UPS HAT's current with Waveshare's 32V_2A calibration #186

Merged
aluminum-ice merged 1 commit from ups-ws-calibration into main 2026-11-12 06:38:46 +00:00
Owner

What this PR does

Switches ups-ws (Waveshare UPS HAT / UPS HAT (B)) from the INA219's CAL_16V_5A calibration to CAL_32V_2A, the one Waveshare's own demo for these boards uses. With 16V_5A, which assumes a 0.01 ohm shunt, a real board's card read the current and power about ten times too high: an idle Pi 5 on battery showed around 28 W, while the time-to-shutdown estimate (worked out from the falling charge percent, not the current) fitted a draw of about 0.4 A. The 80 mV shunt range of 16V_5A would also clip above about 0.8 A of real draw. This settles the "Confirm the UPS HAT's INA219 calibration on hardware" entry, which is removed from deferred.md.

The charge percent, the charging/discharging state and the auto-shutdown come from the bus voltage and the current's sign, so they're unchanged. The one visible difference besides the numbers: the 30 mA band around zero that reads as "idle"/"full" is now 30 real milliamps, not 3.

Checklist

  • Lint passes — make lint (ansible --syntax-check, yamllint, shellcheck --severity=error, and the real-data check). The Lint workflow runs this on the PR.
  • Tests pass — make test (the kestrel_pi pytest suite and the real-data check's tests). The Test workflow runs this on the PR.
  • Nothing real: no secrets, no personal information, no real data. This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, .env files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you.
  • Consent gates intact. Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced.
  • Docs updated in the same PR, if this changes something an operator sees or configures: the README package table, the relevant page under docs/, and the on-device operator guide (GUIDE_MD in kestrel_pi/userguide.py) where it applies.
  • Commit messages are short and imperative.

Release impact

  • App-layer-safe — changes only files the in-place update engine carries: the kestrel_pi package, plugins/*.py, systemd units, the journald drop-in, a lib script already in the engine's LIB_SCRIPTS, or the CLI.
  • Reflash-class — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / config.txt / cmdline, kernel modules, the base image or partition size, builder/config.json, builder/config.yml, the Makefile, the Release workflow (.forgejo/workflows/main.yml), a shipped config default (config.toml / default.conf), or a brand-new lib script.

Notes for review

  • ups-ws goes to 0.1.1. ups-wsc/ups-wsd keep CAL_16V_5A, which is what Waveshare's (C) and (D) demos use; the library's two calibrations are unchanged.
  • Docs: plugin-libraries.md and CLAUDE.md now say ups-ws programs 32V_2A. No operator setting or guide text changes.
  • Lint and tests are left to CI: ansible-playbook isn't installed on the machine this was prepared on, though the real-data check passes there. Locally the pytest suite passes apart from five test_web.py potfile-import tests that fail identically on main in that environment.
  • To verify on a device after the update: on battery, an idle Pi 5's card should read roughly 0.3-0.4 A and 2.5-3 W, and the current should stay sensible under training load instead of saturating.

🤖 Generated with Claude Code

## What this PR does Switches `ups-ws` (Waveshare UPS HAT / UPS HAT (B)) from the INA219's `CAL_16V_5A` calibration to `CAL_32V_2A`, the one Waveshare's own demo for these boards uses. With 16V_5A, which assumes a 0.01 ohm shunt, a real board's card read the current and power about ten times too high: an idle Pi 5 on battery showed around 28 W, while the time-to-shutdown estimate (worked out from the falling charge percent, not the current) fitted a draw of about 0.4 A. The 80 mV shunt range of 16V_5A would also clip above about 0.8 A of real draw. This settles the "Confirm the UPS HAT's INA219 calibration on hardware" entry, which is removed from `deferred.md`. The charge percent, the charging/discharging state and the auto-shutdown come from the bus voltage and the current's sign, so they're unchanged. The one visible difference besides the numbers: the 30 mA band around zero that reads as "idle"/"full" is now 30 real milliamps, not 3. ## Checklist - [ ] **Lint passes** — `make lint` (ansible `--syntax-check`, `yamllint`, `shellcheck --severity=error`, and the real-data check). The **Lint** workflow runs this on the PR. - [ ] **Tests pass** — `make test` (the `kestrel_pi` pytest suite and the real-data check's tests). The **Test** workflow runs this on the PR. - [x] **Nothing real: no secrets, no personal information, no real data.** This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, `.env` files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you. - [x] **Consent gates intact.** Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced. - [x] **Docs updated in the same PR**, if this changes something an operator sees or configures: the README package table, the relevant page under `docs/`, and the on-device operator guide (`GUIDE_MD` in `kestrel_pi/userguide.py`) where it applies. - [x] Commit messages are short and imperative. ## Release impact - [x] **App-layer-safe** — changes only files the in-place update engine carries: the `kestrel_pi` package, `plugins/*.py`, systemd units, the journald drop-in, a lib script already in the engine's `LIB_SCRIPTS`, or the CLI. - [ ] **Reflash-class** — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / `config.txt` / `cmdline`, kernel modules, the base image or partition size, `builder/config.json`, `builder/config.yml`, the `Makefile`, the Release workflow (`.forgejo/workflows/main.yml`), a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. ## Notes for review - `ups-ws` goes to 0.1.1. `ups-wsc`/`ups-wsd` keep `CAL_16V_5A`, which is what Waveshare's (C) and (D) demos use; the library's two calibrations are unchanged. - Docs: `plugin-libraries.md` and `CLAUDE.md` now say `ups-ws` programs 32V_2A. No operator setting or guide text changes. - Lint and tests are left to CI: `ansible-playbook` isn't installed on the machine this was prepared on, though the real-data check passes there. Locally the pytest suite passes apart from five `test_web.py` potfile-import tests that fail identically on `main` in that environment. - To verify on a device after the update: on battery, an idle Pi 5's card should read roughly 0.3-0.4 A and 2.5-3 W, and the current should stay sensible under training load instead of saturating. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Read the UPS HAT's current with Waveshare's 32V_2A calibration
All checks were successful
Lint / lint (push) Successful in 28s
Lint / lint (pull_request) Successful in 30s
Test / test (push) Successful in 55s
Test / test (pull_request) Successful in 52s
929fbec225
ups-ws set the INA219 up for a 0.01 ohm shunt (16V_5A), but the UPS HAT
and UPS HAT (B) carry the 0.1 ohm shunt Waveshare's demo is written for
(32V_2A). On a board the card read the current and power about ten times
too high (an idle Pi 5 at ~28 W, while the charge trend fitted ~0.4 A),
and the 80 mV shunt range would clip above about 0.8 A. Percent, the
charging/discharging state and the auto-shutdown come from the bus
voltage and the current's sign, so they don't change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch ups-ws-calibration 2026-11-12 06:38:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aluminum-ice/kestrel!186
No description provided.