33// SPDX-License-Identifier: MIT
44
55#include < Arduino.h>
6+ #include " Adafruit_MAX1704X.h"
67#include " Adafruit_LC709203F.h"
78#include < Adafruit_NeoPixel.h>
89#include " Adafruit_TestBed.h"
@@ -14,14 +15,19 @@ Adafruit_BME280 bme; // I2C
1415bool bmefound = false ;
1516extern Adafruit_TestBed TB;
1617
17- Adafruit_LC709203F lc;
18+ Adafruit_LC709203F lc_bat;
19+ Adafruit_MAX17048 max_bat;
20+
1821Adafruit_ST7789 display = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
1922
2023GFXcanvas16 canvas (240 , 135 );
2124
25+ bool maxfound = false ;
26+ bool lcfound = false ;
27+
2228void setup () {
2329 Serial.begin (115200 );
24- // while (! Serial) delay(10);
30+ // while (! Serial) delay(10);
2531
2632 delay (100 );
2733
@@ -43,14 +49,25 @@ void setup() {
4349 canvas.setFont (&FreeSans12pt7b);
4450 canvas.setTextColor (ST77XX_WHITE);
4551
46- if (!lc.begin ()) {
47- Serial.println (F (" Couldnt find Adafruit LC709203F?\n Make sure a battery is plugged in!" ));
48- while (1 );
52+ if (lc_bat.begin ()) {
53+ Serial.println (" Found LC709203F" );
54+ Serial.print (" Version: 0x" ); Serial.println (lc_bat.getICversion (), HEX);
55+ lc_bat.setPackSize (LC709203F_APA_500MAH);
56+ lcfound = true ;
4957 }
58+ else {
59+ Serial.println (F (" Couldnt find Adafruit LC709203F?\n Checking for Adafruit MAX1704X.." ));
60+ delay (200 );
61+ if (!max_bat.begin ()) {
62+ Serial.println (F (" Couldnt find Adafruit MAX1704X?\n Make sure a battery is plugged in!" ));
63+ while (1 ) delay (10 );
64+ }
65+ Serial.print (F (" Found MAX17048" ));
66+ Serial.print (F (" with Chip ID: 0x" ));
67+ Serial.println (max_bat.getChipID (), HEX);
68+ maxfound = true ;
5069
51- Serial.println (" Found LC709203F" );
52- Serial.print (" Version: 0x" ); Serial.println (lc.getICversion (), HEX);
53- lc.setPackSize (LC709203F_APA_500MAH);
70+ }
5471
5572 if (TB.scanI2CBus (0x77 )) {
5673 Serial.println (" BME280 address" );
@@ -73,11 +90,11 @@ void setup() {
7390uint8_t j = 0 ;
7491
7592void loop () {
76- Serial.println (" **********************" );
77-
78- TB.printI2CBusScan ();
7993
8094 if (j % 5 == 0 ) {
95+ Serial.println (" **********************" );
96+
97+ TB.printI2CBusScan ();
8198 canvas.fillScreen (ST77XX_BLACK);
8299 canvas.setCursor (0 , 25 );
83100 canvas.setTextColor (ST77XX_RED);
@@ -87,10 +104,18 @@ void loop() {
87104 canvas.setTextColor (ST77XX_GREEN);
88105 canvas.print (" Battery: " );
89106 canvas.setTextColor (ST77XX_WHITE);
90- canvas.print (lc.cellVoltage (), 1 );
91- canvas.print (" V / " );
92- canvas.print (lc.cellPercent (), 0 );
93- canvas.println (" %" );
107+ if (lcfound == true ) {
108+ canvas.print (lc_bat.cellVoltage (), 1 );
109+ canvas.print (" V / " );
110+ canvas.print (lc_bat.cellPercent (), 0 );
111+ canvas.println (" %" );
112+ }
113+ else {
114+ canvas.print (max_bat.cellVoltage (), 1 );
115+ canvas.print (" V / " );
116+ canvas.print (max_bat.cellPercent (), 0 );
117+ canvas.println (" %" );
118+ }
94119 canvas.setTextColor (ST77XX_BLUE);
95120 canvas.print (" I2C: " );
96121 canvas.setTextColor (ST77XX_WHITE);
@@ -107,6 +132,5 @@ void loop() {
107132 }
108133
109134 TB.setColor (TB.Wheel (j++));
110- delay (10 );
111135 return ;
112136}
0 commit comments