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.
The MAX17048 battery monitor (highlighted in red) is immediately below the USB pin label. 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 code.py 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 code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py 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} %") print("") time.sleep(1)
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.
Text editor powered by tinymce.