Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4
5import time
6import board
7import adafruit_max1704x
8
9i2c = board.I2C() # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
11max17 = adafruit_max1704x.MAX17048(i2c)
12
13print(
14 "Found MAX1704x with chip version",
15 hex(max17.chip_version),
16 "and id",
17 hex(max17.chip_id),
18)
19
20# Quick starting allows an instant 'auto-calibration' of the battery. However, its a bad idea
21# to do this right when the battery is first plugged in or if there's a lot of load on the battery
22# so uncomment only if you're sure you want to 'reset' the chips charge calculator.
23# print("Quick starting")
24# max17.quick_start = True
25
26while True:
27 print(f"Battery voltage: {max17.cell_voltage:.2f} Volts")
28 print(f"Battery state : {max17.cell_percent:.1f} %")
29 print("")
30 time.sleep(1)