I have a wittypy4 l3.7
Is there any way to get the battery voltage in a python program?
--Thanks
The VIN on Witty Pi 4 L3V7 is close to what you need, but it is not always the battery voltage.
If USB power is connected, the VIN equals to 5V (from USB power) minus the voltage drop on an diode. When USB power is remove, the VIN is the battery voltage. Although not 100% sure, you can still tell by seeing the voltage value, if it is higher than 4.2V, then most probably it is the voltage from USB power.
With that said, it is impossible to know the battery voltage when USB power is connected.
VIN can be obtained from two I2C registers, and you can port the get_input_voltage function (written in BASH) to Python.
I used this code to read the battery voltage on the witty pi 4 using the bash script. Should be similar/identical for the l3v7:
@buzzer_boy FYI: Maybe this is useful: https://github.com/Eagleshot/WittyPi4Python