MuPiHAT – battery, charging and power button
Set up the MuPiHAT: battery profile, input current limit, battery alerts, protective shutdown, battery level, charger diagnostics, power button and standby.
The MuPiHAT is an add-on board for MuPiBox with a battery charger (BQ25792), an amplifier (MAX98357A), a power button and a power cut. You set it up under Hardware → MuPiHAT.
Enabling the MuPiHAT
Enable MuPiHAT switches on support for battery, I²C, power button and power cut. If no other sound card has been chosen, the box uses the MuPiHAT amplifier automatically. Without a MuPiHAT the battery display and battery options are hidden.
The box adds the required lines to its own block of config.txt (see GPIO reference). After enabling it the first time, a restart or power cycle is needed.
Battery profile
The profile describes at which voltage the battery is how full (0/25/50/75/100 %).
| Profile | Note |
|---|---|
| Ansmann 2S1P | calibration included |
| ENERpower 2S2P 10,000 mAh | calibration included |
| USB-C mode (no battery) | no voltage limits; battery functions off |
| Custom | your own voltages for other 2S batteries |
How the battery level is calculated
A battery's voltage depends on the current: while charging it is above, under load below the resting voltage. Without compensation the display therefore jumps when plugging in and out (e.g. 83 % on the cable, 44 % right after). MuPiBox takes the current into account:
- The box measures the battery's internal resistance itself as soon as you plug or unplug the USB-C cable. Until then it uses a default value. The diagnostics then show "internal resistance … (measured)".
- The level does not rise on battery and does not fall while charging.
- Implausible readings of the charger chip are discarded.
Power supply / charger
Input current limit (safe 1790 mA, medium 2200 mA, high 2700 mA) limits how much current the charger draws from the power supply. A higher value only brings more power with a strong enough power supply. In USB-C mode without a battery no limit is set – without a battery buffer the Pi could otherwise crash.
Battery alerts & protection
Only applies on battery:
| Setting | Effect |
|---|---|
| Battery warning from % | plays the warning sound, repeated every n minutes |
| "Battery empty" image from % | shows an image on the display that the box needs charging |
| Automatic protective shutdown from % | shuts the box down cleanly |
Order: warning > "battery empty" image > protective shutdown. The box only switches off after three confirmed critical readings; the battery only counts as recovered 2 % above the threshold. If even the voltage under load is at the bottom of the profile, the battery counts as empty – whatever the compensated display says. You upload your own warning sounds right here.
Battery icon
Style of the battery display in the status bar: minimal modern, child-friendly round or child-friendly MuPiBox. The icon can be hidden under Design.
MuPiHAT status
Shows charge level, charging/mains power, voltages, currents, temperature and under "More technical values" among others:
- resting voltage (estimated) and the uncompensated value,
- internal resistance (default or measured),
- discharge current sensing (EN_IBAT) – the box switches it on with a battery profile,
- watchdog, cell count, charge voltage, charge and input current limits.
With a battery profile the box configures the charger chip correctly by itself: 2 cells (2S), ADC on, discharge current sensing on and the I²C watchdog off (otherwise it reset the chip to its defaults every 40 seconds). Charge voltage, charge current and protection functions are not changed. Short glitches on the I²C bus are retried and do not cause a reset.
Charger recovery
The soft reset puts the charger back into its power-on state; afterwards the box restores the safe 2S configuration. The box does not restart, charging may pause briefly. Only use it for troubleshooting.
Technical base configuration
Shows whether the required lines are in config.txt. If an existing line contradicts them (e.g. from the MuPiHAT installer with a different clock or pin), the box reports a conflict and overwrites nothing.
Power button and power cut
The MuPiHAT's button is on BCM 17 (gpio-shutdown), the power cut on BCM 4 (gpio-poweroff). The Linux kernel manages both:
- Short press: shuts the box down – or sends it into standby when that is enabled.
- Long press: the MuPiHAT switches off hard by itself.
- After shutdown the MuPiHAT cuts the power via BCM 4 – the box is then really off.
In standby on battery the box still shuts down below the configured battery threshold (Display & power → Standby).
Audio
The MAX98357A amplifier needs the overlays max98357a,sdmode-pin=16 and i2s-mmap; the box sets them when needed and you choose the output under Audio.