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 board. Then you need to update code.py with the example script.
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.
# 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)
In the editor window in your browser, click the Open button to view the file dialog. Then, click the Upload button and select Upload Folders.
After the upload finishes, you can open the lib folder to view the library files required for the MAX17048 example.
In the editor window in your browser, click the Open button to view the file dialog. Then, click the Upload button and select Upload Files.
You'll be asked if you want to overwrite the previous code.py with the new code.py file from the Project Bundle. Click OK.
Open 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.