Any suggestions for how to estimate remaining battery percentage (both when charging and also when running on battery)?
I can do some estimates while running on battery ((current voltage - threshold voltage) / (4.2V - threshold voltage)), but not sure how to tackle it when the battery is charging.
There are some other USB devices (e.g. UPS-Lite) that return the remaining capacity via the i2c bus, but I'm not seeing a similar option for the Witty Pi 4 L3V7.
Witty Pi 4 L3V7 can only see the voltage of the battery when it is not being charged.
During the charging the battery is disconnected from Vin and the voltage on Vin is actually the voltage from USB-C connector (drops a little bit via the SS54 diode). In such case you can not know the actual voltage of the battery.
If you wonder why Witty Pi 4 L3V7 does not always monitor the voltage of battery, the answer is the MCU (ATtiny841) does not have any spare pin for this purpose.
@admin Thanks so much for the info. Can you confirm my calculation above makes sense for calculating remaining capacity while unplugged?
@billsidea Usually you can not calculate the remaining capacity in this way, because the voltage and remaining capacity are not changed in a linear way.
Different battery has different voltage-vs-remaining-energy curve. After you draw that curve, you may estimate the remaining energy by voltage.
You may read this https://meloyelo.nz/knowledge-base/voltage-vs-remaining-energy-of-lithium-ion-batteries/
@admin Ok, thanks. This is great info for the novice (i.e. me), so thank you very much!