add battery voltage monitoring

This commit is contained in:
Tomas Krejci 2024-05-29 22:17:52 +02:00
parent db0f4233fd
commit 820255925c

View File

@ -32,9 +32,9 @@ ESP32 = platform == "esp32"
RP2 = platform == "rp2"
PYBOARD = platform == "pyboard"
if ESP32:
battery_ADC = ADC(26)
battery_ADC = ADC(28)
elif RP2:
battery_ADC = ADC(26)
battery_ADC = ADC(28)
else:
battery_ADC = ADC("X2")
@ -49,8 +49,9 @@ async def battery_monitor(aadc):
# aadc.sense(normal=True)
# value = await aadc() # Wait until out of range
# logger.debug("Out of range:", value)
read = aadc.read_u16()
logger.debug(f"Battery Voltage: {read}")
voltage = aadc.read_u16() * (3.3 / 65535)
logger.debug(f"Battery Voltage: {voltage}")
await asyncio.sleep_ms(5000)