-
Notifications
You must be signed in to change notification settings - Fork 0
Battery Snippets
In order to get the battery voltage, you will need to download this .zip file and extract its contents into your lib folder: battery_lib_cpy8.x.x_5-13-23.zip
Your ESP32 boards have been modified by Mr. Chin such that the battery can be plugged in and on simultaneous to the board being plugged into your computer via USB-C.
Battery monitoring will only work with the battery plugged in and on (if you are only powering from the computer, you will see an error)
Required imports in order to be able to use the voltage sensor:
import board
from adafruit_lc709203f import LC709203F
Initialize the voltage sensor
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
voltage_sensor = LC709203F(i2c)
If you have already initialized the i2c bus for use with your environmental sensor, you will only need the following
voltage_sensor = LC709203F(i2c)
The voltage sensor is on the microcontroller board, connected internally to the i2c bus (SDA and SCL) that you used to connect your environmental sensor.
You can treat voltage_sensor.cell_voltage
as a variable whose value (as a decimal) is always equal to the current battery voltage.
Print the current battery voltage to the terminal:
print(voltage_sensor.cell_voltage)
Importing the BatteryLevel
DataPoint
subclass...
from servercom import BatteryLevel
Assuming connection
is a properly initialized servercom.Connection()
instance and voltage_sensor
is initialized as described above...
connection.post(BatteryLevel(voltage_sensor.cell_voltage))
The adafruit_lc709203f
library has a feature for estimating the percent capacity remaining for lithium batteries, but it is not intended for doing these calculations for alkaline AA batteries such as the ones we are using. Keep in mind that you are using three cells
-
Check out this page for information on the voltage of Amazon Basics alkaline AA cells as they discharge: https://lygte-info.dk/review/batteries2012/Amazon%20basic%20AA%20UK.html
-
Check out this page for information on the voltage of Amazon Basics alkaline AAA cells as they discharge: https://lygte-info.dk/review/batteries2012/Amazon%20basic%20AAA%20UK.html
(This guy reviews all sorts of batteries and tests them under a handful of current conditions.)
If you seek further information, check these links out:
Copyright 2022-2023 Heather Brayer, Joseph R. Freeston, & Lucas Tousignant