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 history
Open Hardware → MuPiHAT → Battery history to view measurements from the past 24 hours or 7 days. Select battery level (%), voltage (V), charging or discharging current (mA), or temperature (°C). The page lists recorded charging and discharging sessions too.
The box records roughly one sample per minute and keeps it for up to eight days. Missing readings, such as after a restart, remain gaps. History is stored in the local database and included in database backups.
Estimated remaining runtime is only shown after at least 20 minutes of continuous discharge with a measured decline of at least two percentage points. Otherwise, no estimate is displayed.
Coloured bands behind the curve show what the box was doing: Playing, In use (display on, kids apps included), Idle (dimmed or screensaver), Display off and Standby. If music plays with the display off, the minute counts as "Display off". The Consumption by operating state table below lists the time, the average discharge current, the drain in percent per hour and the resulting runtime on a full battery for each state – so you can see what costs the most power. You can also choose CPU load as a metric (average of each last minute). States and CPU load are recorded from version 0.1.0-test.18 on; older samples stay uncoloured.
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 (2 seconds): With button standby enabled, MuPiBox requests a clean shutdown, including on MuPiHAT hardware. This can be disabled under Display & Power. An independent hardware emergency cut-off remains unaffected.
- 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.