|
1 |
| -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries |
2 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
|
3 | 2 | #
|
4 | 3 | # SPDX-License-Identifier: Unlicense
|
|
7 | 6 | import board
|
8 | 7 | import adafruit_max1704x
|
9 | 8 |
|
10 |
| - |
11 | 9 | i2c = board.I2C() # uses board.SCL and board.SDA
|
12 |
| - |
13 |
| -from adafruit_debug_i2c import DebugI2C |
14 |
| -debug_i2c = DebugI2C(i2c) |
15 |
| -max17 = adafruit_max1704x.MAX17048(debug_i2c) |
| 10 | +max17 = adafruit_max1704x.MAX17048(i2c) |
16 | 11 |
|
17 | 12 | print("Found MAX1704x with chip version", hex(max17.chip_version), "and id", hex(max17.chip_id))
|
18 | 13 |
|
19 |
| -#max17.reset_voltage = 2.5 |
20 |
| -print("MAX1704x reset voltage = %0.1f V" % max17.reset_voltage) |
21 |
| - |
22 |
| -#max17.activity_threshold = 0.15 |
23 |
| -#print("MAX1704x activity threshold = %0.2f V" % max17.activity_threshold) |
24 |
| - |
25 |
| -#max17.hibernation_threshold = 5 |
26 |
| -#print("MAX1704x hibernation threshold = %0.2f %%" % max17.hibernation_threshold) |
27 |
| - |
28 |
| -#max17.hibernate() |
29 |
| - |
30 |
| -#max17.enable_sleep = True |
31 |
| -#max17.sleep = True |
32 |
| - |
33 |
| -print("Quick starting") |
34 |
| -max17.quick_start = True |
35 |
| - |
36 |
| -max17.voltage_alert_min = 3.7 |
37 |
| -print("Voltage alert minimum = %0.2f V" % max17.voltage_alert_min) |
38 |
| -#max17.voltage_alert_max = 3.8 |
39 |
| -#print("Voltage alert maximum = %0.2f V" % max17.voltage_alert_max) |
| 14 | +# Quick starting allows an instant 'auto-calibration' of the battery. However, its a bad idea |
| 15 | +# to do this right when the battery is first plugged in or if there's a lot of load on the battery |
| 16 | +# so uncomment only if you're sure you want to 'reset' the chips charge calculator. |
| 17 | +# print("Quick starting") |
| 18 | +# max17.quick_start = True |
40 | 19 |
|
41 | 20 | while True:
|
42 |
| - print("Battery voltage:", max17.cell_voltage, "V") |
43 |
| - print("Battery state :", max17.cell_percent, "%") |
44 |
| - print("Charge rate :", max17.charge_rate, "%/hr") |
45 |
| - |
46 |
| - if max17.hibernating: |
47 |
| - print("Hibernating!") |
48 |
| - |
49 |
| - if max17.active_alert: |
50 |
| - print("Alert!") |
51 |
| - if max17.reset_alert: |
52 |
| - print(" Reset indicator") |
53 |
| - max17.reset_alert = False # clear the alert |
54 |
| - |
55 |
| - if max17.voltage_high_alert: |
56 |
| - print(" Voltage high") |
57 |
| - max17.voltage_high_alert = False # clear the alert |
58 |
| - |
59 |
| - if max17.voltage_low_alert: |
60 |
| - print(" Voltage low") |
61 |
| - max17.voltage_low_alert = False # clear the alert |
62 |
| - |
63 |
| - if max17.voltage_reset_alert: |
64 |
| - print(" Voltage reset") |
65 |
| - max17.voltage_reset_alert = False # clear the alert |
66 |
| - |
67 |
| - if max17.SOC_low_alert: |
68 |
| - print(" Charge low") |
69 |
| - max17.SOC_low_alert = False # clear the alert |
70 |
| - |
71 |
| - if max17.SOC_change_alert: |
72 |
| - print(" Charge changed") |
73 |
| - max17.SOC_change_alert = False # clear the alert |
74 |
| - |
| 21 | + print(f'Battery voltage: {max17.cell_voltage:.2f} Volts') |
| 22 | + print(f'Battery state : {max17.cell_percent:.1f} %') |
| 23 | + print("") |
75 | 24 | time.sleep(1)
|
0 commit comments