Your microcontroller board comes with a MAX17048 lithium ion polymer (lipoly) battery monitor built right onto the board. The MAX17048 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_MAX1704X 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 MAX17048 battery monitor (highlighted in red) is located on the front of the board, directly below the USB pin label. Its I2C address is 0x36

Arduino Library Installation

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

Search for MAX17048, and install the Adafruit MAX1704X library.

When asked about installing dependencies, click Install all

MAX17048 Simple Data Example

Click File > Examples > Adafruit MAX1704X > MAX17048_basic to open the example.

#include "Adafruit_MAX1704X.h"

Adafruit_MAX17048 maxlipo;

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);    // wait until serial monitor opens

  Serial.println(F("\nAdafruit MAX17048 simple demo"));

  while (!maxlipo.begin()) {
    Serial.println(F("Couldnt find Adafruit MAX17048?\nMake sure a battery is plugged in!"));
    delay(2000);
  }
  Serial.print(F("Found MAX17048"));
  Serial.print(F(" with Chip ID: 0x")); 
  Serial.println(maxlipo.getChipID(), HEX);
}

void loop() {
  float cellVoltage = maxlipo.cellVoltage();
  if (isnan(cellVoltage)) {
    Serial.println("Failed to read cell voltage, check battery is connected!");
    delay(2000);
    return;
  }
  Serial.print(F("Batt Voltage: ")); Serial.print(cellVoltage, 3); Serial.println(" V");
  Serial.print(F("Batt Percent: ")); Serial.print(maxlipo.cellPercent(), 1); Serial.println(" %");
  Serial.println();

  delay(2000);  // dont query too often!
}
Make sure to press the reset button after uploading code from the Arduino IDE to the ESP32-S3.

After opening the MAX17048_basic file, upload it to your microcontroller. Open the Serial Monitor at 115200 baud. Plug in a lipo battery to the JST-PH battery port. You should see the battery voltage and percentage data print to the Serial Monitor as the sketch runs.

This guide was first published on Apr 20, 2022. It was last updated on Jun 16, 2024.

This page (MAX17048 Simple Data) was last updated on Mar 08, 2024.

Text editor powered by tinymce.