-
Notifications
You must be signed in to change notification settings - Fork 533
Description
In the badger 2040 example launcher.py I noticed that the battery level was only shown correctly when the USB cable was also connected. This defeats the purpose of monitoring how much battery power is left.
The ADC and VREF pins don't seem to be getting initialised correctly for badger_os, so the call to:
badger_os.get_battery_level()
doesn't return anything useful when running only on batteries. Which is pretty useless.
The badger 2040 example battery.py works correctly running only on battery power. That example 'initialises' the ADC and VREF pins. I copied the following to the top of launcher.py and now it's all working as I'd expect with or without a connected battery which itself is either switched on or off:
import badger_os
from machine import Pin, ADC
vbat_adc = ADC(badger2040.PIN_BATTERY)
vref_adc = ADC(badger2040.PIN_1V2_REF)
vref_en = Pin(badger2040.PIN_VREF_POWER)
vref_en.init(Pin.OUT)
vref_en.value(0)
# Reduce clock speed to 48MHz
...
MAX_BATTERY_VOLTAGE = 3.2
MIN_BATTERY_VOLTAGE = 2.0
I completely nuked my badger and started again. I completely replaced the default main.py with the launcher.py code and I got the battery level working just with this additional code which is also in badger_os.py (see my commment below):
from machine import ADC
vbat_adc = ADC(badger2040.PIN_BATTERY)
Sorry for all the edits:
I nuked it all again and did another experiment, if you just add a simple dummy call to badger_os.get_battery_level() right at the 'top' of launcher.py after import badger_os, just ignore the returned value, who cares. It all then works on just battery power (no extra import of ADC and setting vbat_adc is needed). There's something fishy with some kind of initialisation somewhere, but I don't know what's really happening.
I think there is a least one other issue about badger battery level monitoring and which values are correct for various types of batteries. The comments in the code should be corrected and improved to clarify the min/max range for all types of batteries.