Skip to content

Commit 85ae353

Browse files
committed
make simple demo simpler
1 parent b090b23 commit 85ae353

File tree

2 files changed

+10
-60
lines changed

2 files changed

+10
-60
lines changed

adafruit_max1704x.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class MAX17048:
9595
SOC_change_alert = RWBit(_MAX1704X_STATUS_REG, 5)
9696

9797
_reset_voltage = RWBits(7, _MAX1704X_VRESET_REG, 1)
98+
comparator_disabled = RWBit(_MAX1704X_VRESET_REG, 0)
9899

99100
def __init__(self, i2c_bus, address=MAX1704X_I2CADDR_DEFAULT):
100101
# pylint: disable=no-member

examples/max1704x_simpletest.py

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
21
# SPDX-FileCopyrightText: Copyright (c) 2022 ladyada for Adafruit Industries
32
#
43
# SPDX-License-Identifier: Unlicense
@@ -7,69 +6,19 @@
76
import board
87
import adafruit_max1704x
98

10-
119
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)
1611

1712
print("Found MAX1704x with chip version", hex(max17.chip_version), "and id", hex(max17.chip_id))
1813

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
4019

4120
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("")
7524
time.sleep(1)

0 commit comments

Comments
 (0)