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

The MAX17048 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 MAX1704x 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.

MAX17048 Location

The MAX17048 battery monitor (highlighted in red) is immediately above the STEMMA QT port in the middle of the board. Its I2C address is 0x36.

MAX17048 Simple Data Example

To run this example, you need to first install the MAX1704x library into the lib folder on your CIRCUITPY drive. Then you need to update 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 file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the file to your CIRCUITPY drive.

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

  • adafruit_bus_device/
  • adafruit_register/
  • adafruit_max1704x.mpy
# SPDX-FileCopyrightText: Copyright (c) 2023 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: Unlicense

import time
import board
import adafruit_max1704x

monitor = adafruit_max1704x.MAX17048(board.I2C())

while True:
    print(f"Battery voltage: {monitor.cell_voltage:.2f} Volts")
    print(f"Battery percentage: {monitor.cell_percent:.1f} %")
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 MAX17048 data using CircuitPython!

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

This guide was first published on Mar 03, 2023. It was last updated on May 24, 2024.

This page (I2C: Onboard MAX17048) was last updated on Mar 08, 2024.

Text editor powered by tinymce.