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.print(lc.cellVoltage(), 3); Serial.print("\t"); Serial.print("Batt_Percent:"); Serial.print(lc.cellPercent(), 1); Serial.print("\t"); 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.
The thermistor pin on the LC709203F, used to measure the battery temperature, is not broken out for connection to an external thermistor. So the temperature values printed out by the LC709203F_demo will not be meaningful.
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!
Text editor powered by tinymce.