Your microcontroller board comes with an LC709203 lithium ion polymer (lipoly) battery monitor built right onto the board. The LC709203 is available over I2C.

The LC709203 comes with its own Adafruit CircuitPython library that makes it simple to write code to read data from it. This example will be using, among other things, the Adafruit CircuitPython LC709203F library.

The example simply reads data from the battery monitor and prints it to the serial console. It is designed to show you how to get data from the battery monitor.

LC709203 Location

The LC709203 battery monitor (highlighted in red) is located on the bottom of the board near the VBAT pin label. Its I2C address is 0x0B. (0xb, which is returned by I2C scan, is the same as 0x0B, which simply has leading zeros.)

LC709203 Simple Data Example

To run this example, you need to first install the LC709203F library into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.

Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.

Your CIRCUITPY/lib folder should contain at least the following folder and file:

  • adafruit_register/
  • adafruit_lc709203f.mpy
CIRCUITPY
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython Simple Example for LC709203 Sensor
"""
import time
import board
from adafruit_lc709203f import LC709203F, PackSize

# Create sensor object, using the board's default I2C bus.
battery_monitor = LC709203F(board.I2C())

# Update to match the mAh of your battery for more accurate readings.
# Can be MAH100, MAH200, MAH400, MAH500, MAH1000, MAH2000, MAH3000.
# Choose the closest match. Include "PackSize." before it, as shown.
battery_monitor.pack_size = PackSize.MAH400

while True:
    print("Battery Percent: {:.2f} %".format(battery_monitor.cell_percent))
    print("Battery Voltage: {:.2f} V".format(battery_monitor.cell_voltage))
    time.sleep(2)
This code will run without a battery plugged in, and voltage and charge level will be printed to the serial console, but this data does not correlate to anything. Plug in a battery to get useful data!

Now, connect to the serial console to see the battery data printed out!

That's all there is to reading the LC709203 data using CircuitPython!

For more details, check out the guide for the LC709203.

This guide was first published on Jan 12, 2022. It was last updated on 2022-04-13 12:04:15 -0400.

This page (I2C: On-Board Battery Monitor) was last updated on May 24, 2022.

Text editor powered by tinymce.