diff options
| author | Joey232 <Joey@jsconsulting.com> | 2024-01-20 17:32:37 -0500 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-01-31 14:24:16 +1100 |
| commit | 3e48d24576f8a44a20e65a5782204944de2467b3 (patch) | |
| tree | 6f30d5bbfe45571b156e82665e1a838b833c549e | |
| parent | 81049edf7c67413527ba58a96a3ecfb963addbf9 (diff) | |
esp32/boards/UM_FEATHERS3: Use read_uv() for accurate battery voltage.
Use read_uv() to get the battery voltage because it uses the on-chip
calibraton values.
Signed-off-by: Joey232 <Joey@jsconsulting.com>
| -rw-r--r-- | ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py index b6f486f3d..57b15f9c0 100644 --- a/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py +++ b/ports/esp32/boards/UM_FEATHERS3/modules/feathers3.py @@ -65,10 +65,11 @@ def get_battery_voltage(): This is an approximation only, but useful to detect if the charge state of the battery is getting low. """ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read - adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation for max voltage of 1.116V w/batt of 4.2V - measuredvbat = adc.read() - measuredvbat /= 3657 # Divide by 3657 as we are using 2.5dB attenuation, which is max input of 1.25V = 4095 counts - measuredvbat *= 4.2 # Multiply by 4.2V, our max charge voltage for a 1S LiPo + # Max voltage on ADC input will be 4.2V divided by R2 (442K) & R5 (160K), 4.2 / (160+442) * 160 = 1.1163V + adc.atten(ADC.ATTN_2_5DB) # Needs 2.5DB attenuation to read a max voltage of 1.1163V + # Use read_uv() to get ADC reading as this will use the on-chip calibration data + measuredvbat = adc.read_uv() / 1000000 # Read micovolts and convert to volts + measuredvbat *= 3.7624 # Multiply by ratio of battery voltage to ADC pin voltage: 4.2/1.1163 return round(measuredvbat, 2) |
