Low cost Lithium Polymer batteries have revolutionized electronics - they're thin, they're light, they can be regulated down to 3.3V and they're easy to charge. On your phone, there's a little image of a battery cell that tells you the percentage of charge - so you know when you absolutely need to plug it in and when you can stay untethered. The Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor does the same thing. Connect it to your Lipoly or LiIon battery and it will let you know the voltage of the cell, it does the annoying math of decoding the non-linear voltage to get you a valid percentage as well!

Since this nice chip is I2C, it works with any and all microcontroller or microcomputer boards, from the Arduino UNO up to the Raspberry Pi. And you don't have to worry about logic level, as the gauge runs with 3.3V or 5.0V power and logic equally fine.

To use, connect the single-cell battery to one of the JST 2 PH ports (either one). Then use the included JST PH jumper cable to connect to your boost converter, Feather, whatever! Use the I2C interface and our Arduino or CircuitPython/Python library code to set the pack size (this helps tune the calculation) and read the voltage and percentage whenever you like. If you connect a 10K thermistor to the THERM pin you can also use it to read the battery pack temperature - our packs do not come with a built in thermistor but many do.

To get you going fast, we spun up a custom made PCB in the STEMMA QT form factor, making it easy to interface with. The STEMMA QT connectors on either side are compatible with the SparkFun Qwiic I2C connectors. This allows you to make solderless connections between your development board and the LC709203 or to chain it with a wide range of other sensors and accessories using a compatible cable.

Power Pins

  • VIN - The chip can safely run from 3-5VDC. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
  • GND - common ground for power and logic

I2C Logic Pins

  • SCL - This is the I2C clock pin SCL, connect to your microcontroller's I2C clock line. There's a 10K pullup on this pin.
  • SDI - This is the I2C data pin SDA, connect to your microcontroller's I2C data line. There's a 10K pullup on this pin.
  • STEMMA QT - These connectors allow you to connect to dev boards with STEMMA QT connectors or to other things with various associated accessories

JST Ports

Theres are two JST ports, they are equivalent. Connect the battery to either one, then the load/charger to the other. Watch out for battery polarity if not using an Adafruit battery!

The two ports simply connect together, and to the battery. You can use/charge the battery while connected by having the battery on one port, and then connecting a charger/project to the other

Other Pins

  • INT - Interrupt signal out, you can set this up to pull low when the voltage or percentage drops below a threshold. Pulled up to VIN with a 10K resistor
  • Therm - Connect a 10K thermistor to the THERM pin to read the battery pack temperature - our packs do not come with a built in thermistor but many do. The other side of the thermistor goes to ground.

LED Trace on the Back of the Breakout

There are two pads connected by a trace on the back of the board, labeled LED. If you want to conserve power when running only on battery, you can cut this trace to disable the LED on the breakout.

Using the LC709203F with Arduino is a simple matter of wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit LC709203F library we've written, and running the provided example code.

I2C Wiring

Use this wiring to connect via I2C interface. The LC709203F uses I2C address 0x0B and it cannot be changed

Here is how to wire up the sensor using one of the STEMMA QT connectors. The examples show a Metro but wiring will work the same for an Arduino or other compatible board.

  • Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
  • Connect board GND (black wire) to Arduino GND
  • Connect board SCL (yellow wire) to Arduino SCL
  • Connect board SDA (blue wire) to Arduino SDA

Plug a 3.7/4.2V lithium polymer or lithium ion rechargable battery into either of the JST battery ports.

Watch out for battery polarity! A reversed battery will damage the monitor. There are + and - symbols on the PCB to indicate which is which.

Library Installation

You can install the Adafruit LC709203F library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for Adafruit LC709203F , and select the Adafruit LC709203F library.

Follow the same process for the Adafruit BusIO library.

Load Example

Open up File -> Examples -> Adafruit LC709203F -> LC709203F_demo

After opening the demo file, upload to your Arduino wired up to the battery breakout.

Make sure a battery is plugged into the board, it must be powered by the battery to function!

Once you upload the code, you will see the Battery Voltage, Charge Percentage, and Temperature values being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:

The battery temperature will not be accurate UNLESS you have connected a 10K ohm thermistor to the THERM input pin! If you don't have the thermistor attached, ignore the temp reading!

The LC chip works best when queried every few seconds at the fastest. Don't disconnect the LiPo battery, it is used to power the LC chip!

You can tweak the calculation for the battery pack size, by changing the line setPackSize(LC709203F_APA_500MAH);

Pick the closest of the following values for your battery size:

LC709203F_APA_100MAH,
LC709203F_APA_200MAH,
LC709203F_APA_500MAH,
LC709203F_APA_1000MAH,
LC709203F_APA_2000MAH,
LC709203F_APA_3000MAH,

You can  set an alarm for voltage or percent with setAlarmRSOC (percent) or setAlarmVoltage (floating point voltage), and check the INT pin going low

It's easy to use the LC709203F and the Adafruit CircuitPython LC709203F module. This library allows you to easily write Python code that provides information about the connected battery including voltage, charge percentage, and temperature.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.

CircuitPython Microcontroller Wiring

Wire up a LC709203F to your board and a battery exactly as shown below. Here's an example of wiring a Feather M4 to the sensor with I2C using STEMMA QT and a solderless breadboard.

  • Connect board VIN (red wire) to Feather 3V
  • Connect board GND (black wire) to Feather GND
  • Connect board SCL (yellow wire) to Feather SCL
  • Connect board SDA (blue wire) to Feather SDA
  • Plug a 3.7/4.2V lithium polymer or lithium ion rechargeable battery into either of the JST battery ports on the board.
  • Plug the other board JST Battery port into the Feather JST port using the cable included with the board.
Watch out for battery polarity! A reversed battery will damage the monitor. There are + and - symbols on the PCB to indicate which is which.

Python Computer Wiring

Since there's dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported

Here's the Raspberry Pi wired to the sensor with I2C using STEMMA QT and a solderless breadboard.

  • Connect board VIN (red wire) to Pi 3V
  • Connect board GND (black wire) to Pi GND
  • Connect board SCL (yellow wire) to Pi SCL
  • Connect board SDA (blue wire) to Pi SDA

Plug a 3.7/4.2V lithium polymer or lithium ion rechargeable battery into either of the JST battery ports.

CircuitPython Installation of LC709203F Library

You'll need to install the Adafruit CircuitPython LC709203F library on your CircuitPython board.

First make sure you are running the latest version of Adafruit CircuitPython for your board.

Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle

Our CircuitPython starter guide has a great page on how to install libraries from the bundle.

Load the the following libraries into the lib folder on your CIRCUITPY drive:

  • adafruit_lc709203f.mpy
  • adafruit_bus_device

Before continuing make sure your board's lib folder or root filesystem has the adafruit_lc709203f.mpy file and adafruit_bus_device folder copied over.

Next connect to the board's serial console so you are ready to see the example output.

Python Installation of LC709203F Library

You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.

Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready!

Once that's done, from your command line run the following command:

pip3 install adafruit-circuitpython-lc709203f

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

The LC709203 uses clock stretching, so on older Pi's (Pi 1, 2, 3, Zero) you will need to slow down the I2C clock to 10KHz https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/i2c-clock-stretching

CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the battery voltage and percentage from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

import board
from adafruit_lc709203f import LC709203F

sensor = LC709203F(board.I2C())

Now you're ready to use the following properties:

  • ic_version - Read-only chip version
  • cell_voltage - Floating point voltage
  • cell_percent - Percentage of cell capacity
  • power_mode - Current power mode (operating or sleeping)
  • pack_size - current battery pack size

For example to print the board version, and battery voltage and percentage values:

print("IC version:", hex(sensor.ic_version))
print("Battery voltage: %0.3f Volts" % (sensor.cell_voltage))
print("Battery percentage: %0.1f %%" % (sensor.cell_percent))

That's all there is to using the LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor with CircuitPython!

Full Example Code

# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense

import time
import board
from adafruit_lc709203f import LC709203F

print("LC709203F simple test")
print("Make sure LiPoly battery is plugged into the board!")

sensor = LC709203F(board.I2C())

print("IC version:", hex(sensor.ic_version))
while True:
    print(
        "Battery: %0.3f Volts / %0.1f %%" % (sensor.cell_voltage, sensor.cell_percent)
    )
    time.sleep(1)

This guide was first published on Sep 09, 2020. It was last updated on Sep 09, 2020.