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 sensor 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 LC709203F library.

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

The LC709203 battery monitor (highlighted in red) is located towards the top of the board, near the center, below the USB and 13 pin labels on the silk. Its I2C address is 0x0B. (0xb, which is returned by I2C scan, is the same as 0x0B, which simply has leading zeros.)

Arduino Library Installation

You can install the necessary libraries from the Library Manager. To open, click Sketch > Include Library > Manage Libraries...

Search for LC709203F, and install the Adafruit LC709203F library.

When asked about installing dependencies, click Install all

LC709203 Simple Data Example

Click File > Examples > Adafruit LC709203F > LC709203F_demo to open the example.

#include "Adafruit_LC709203F.h"

Adafruit_LC709203F lc;

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println("\nAdafruit LC709203F demo");

  // For the Feather ESP32-S2, we need to enable I2C power first!
  // this section can be deleted for other boards
#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
  // turn on the I2C power by setting pin to opposite of 'rest state'
  pinMode(PIN_I2C_POWER, INPUT);
  delay(1);
  bool polarity = digitalRead(PIN_I2C_POWER);
  pinMode(PIN_I2C_POWER, OUTPUT);
  digitalWrite(PIN_I2C_POWER, !polarity);
#endif

  if (!lc.begin()) {
    Serial.println(F("Couldnt find Adafruit LC709203F?\nMake sure a battery is plugged in!"));
    while (1) delay(10);
  }
  Serial.println(F("Found LC709203F"));
  Serial.print("Version: 0x"); Serial.println(lc.getICversion(), HEX);

  lc.setThermistorB(3950);
  Serial.print("Thermistor B = "); Serial.println(lc.getThermistorB());

  lc.setPackSize(LC709203F_APA_500MAH);

  lc.setAlarmVoltage(3.8);
}

void loop() {
  Serial.print("Batt Voltage: "); Serial.println(lc.cellVoltage(), 3);
  Serial.print("Batt Percent: "); Serial.println(lc.cellPercent(), 1);
  Serial.print("Batt Temp: "); Serial.println(lc.getCellTemperature(), 1);

  delay(2000);  // dont query too often!
}

After opening the LC709203F_demo file, upload it to your microcontroller. Open the Serial Monitor at 115200 baud. You should see the following as the sketch starts up.

Once the sketch begins running, you should see something like the following.

That's all there is to reading battery data from the LC709203 using Arduino!

This guide was first published on Nov 25, 2021. It was last updated on 2022-04-07 18:37:23 -0400.

This page (LC709203 Simple Data) was last updated on May 19, 2022.

Text editor powered by tinymce.