Simple test

Ensure your device works with this simple test.

examples/lc709203f_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5import time
 6
 7import board
 8
 9from adafruit_lc709203f import LC709203F
10
11print("LC709203F simple test")
12print("Make sure LiPoly battery is plugged into the board!")
13
14i2c = board.I2C()  # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16sensor = LC709203F(i2c)
17
18print("IC version:", hex(sensor.ic_version))
19while True:
20    try:
21        print(f"Battery: {sensor.cell_voltage:.3f} Volts / {sensor.cell_percent:.1f} %")
22    except OSError:
23        print("retry reads")
24
25    time.sleep(1)

Thermistor test

Example showing the use of thermistors over I2C

examples/lc709203f_thermistortest.py
 1# SPDX-FileCopyrightText: 2021 Daniel Griswold
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6
 7import board
 8
 9from adafruit_lc709203f import LC709203F
10
11print("LC709203F thermistor test")
12print("Make sure a thermistor is connected to the board!")
13
14i2c = board.I2C()  # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16sensor = LC709203F(i2c)
17
18# check your NTC thermistor datasheet for the appropriate B-Constant
19sensor.thermistor_bconstant = 3950
20sensor.thermistor_enable = True
21
22print("IC version:", hex(sensor.ic_version))
23while True:
24    print(f"Cell Temperature: {sensor.cell_temperature:.2f} C")
25    time.sleep(1)