Skip to content

Commit e105778

Browse files
authored
Merge pull request #2408 from adafruit/new_battery_test
Adding battery test code
2 parents 39c8bc7 + c18eab1 commit e105778

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

MAX17048_and_LC709203F_Battery_Monitor_Test/.feather_esp32s2_tft.test.only

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
//
5+
// Adafruit Battery Monitor Demo
6+
// Checks for MAX17048 or LC709203F
7+
8+
#include <Wire.h>
9+
#include "Adafruit_MAX1704X.h"
10+
#include "Adafruit_LC709203F.h"
11+
12+
Adafruit_MAX17048 maxlipo;
13+
Adafruit_LC709203F lc;
14+
15+
// MAX17048 i2c address
16+
bool addr0x36 = true;
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
while (!Serial) delay(10); // wait until serial monitor opens
21+
Serial.println(F("\nAdafruit Battery Monitor simple demo"));
22+
// if no max17048..
23+
if (!maxlipo.begin()) {
24+
Serial.println(F("Couldnt find Adafruit MAX17048, looking for LC709203F.."));
25+
// if no lc709203f..
26+
if (!lc.begin()) {
27+
Serial.println(F("Couldnt find Adafruit MAX17048 or LC709203F."));
28+
while (1) delay(10);
29+
}
30+
// found lc709203f!
31+
else {
32+
addr0x36 = false;
33+
Serial.println(F("Found LC709203F"));
34+
Serial.print("Version: 0x"); Serial.println(lc.getICversion(), HEX);
35+
lc.setThermistorB(3950);
36+
Serial.print("Thermistor B = "); Serial.println(lc.getThermistorB());
37+
lc.setPackSize(LC709203F_APA_500MAH);
38+
lc.setAlarmVoltage(3.8);
39+
}
40+
// found max17048!
41+
}
42+
else {
43+
addr0x36 = true;
44+
Serial.print(F("Found MAX17048"));
45+
Serial.print(F(" with Chip ID: 0x"));
46+
Serial.println(maxlipo.getChipID(), HEX);
47+
}
48+
}
49+
50+
void loop() {
51+
// if you have the max17048..
52+
if (addr0x36 == true) {
53+
max17048();
54+
}
55+
// if you have the lc709203f..
56+
else {
57+
lc709203f();
58+
}
59+
60+
delay(2000); // dont query too often!
61+
62+
}
63+
64+
void lc709203f() {
65+
Serial.print("Batt_Voltage:");
66+
Serial.print(lc.cellVoltage(), 3);
67+
Serial.print("\t");
68+
Serial.print("Batt_Percent:");
69+
Serial.print(lc.cellPercent(), 1);
70+
Serial.print("\t");
71+
Serial.print("Batt_Temp:");
72+
Serial.println(lc.getCellTemperature(), 1);
73+
}
74+
75+
void max17048() {
76+
Serial.print(F("Batt Voltage: ")); Serial.print(maxlipo.cellVoltage(), 3); Serial.println(" V");
77+
Serial.print(F("Batt Percent: ")); Serial.print(maxlipo.cellPercent(), 1); Serial.println(" %");
78+
Serial.println();
79+
}

0 commit comments

Comments
 (0)