Simple test

Ensure your device works with this simple test.

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