Core2: Python API to get battery charge level
-
Is there a Python API to get battery charge level for the Core2 battery?
I found power.getChargeState() but it just returns true/false (charging/discharging). There is also power.getBatVoltage() which could be an indication of the charge level but would need some additional math to calculate the percentage.
-
I found table with voltage and according percentage on internet and make this code
https://github.com/stonatm/UiFlow-custom-blocks/blob/master/battery-capacity/battery.py
ewentually you could calculate with formula something like this, but it is not accurate.
percentage = int( (battery_voltage - 3.20) * 100)
-
I see that your code applies to the M5stickC. Do you think the table is the same for the M5 Core2?
-
Should work if you replace line
volt = axp.getBatVoltage()
with
volt = power.getBatVoltage()
Battery discharge characteristics should be the same +/- some small variations independently of battery capacity.
-
Thanks. I checked on the Core2 and here battery voltage also ranges from about 3.2V to 4.2V.