This device, based on the MAX1704 chip, uses I2C communications to report battery voltage and battery percent-remaining.
It works correctly in my project, using an ATmega328P powered by a LiPo cell.
That's good.
Without the FuelGauge hooked up, my project draws 30 microamps or less while sleeping.
WITH the device hooked up, it draws 1,037 microamps.
That's bad.
If I remove all software references to the fuelgauge and its library, and simply hook up the device physically (only four connections: Power, ground, SDA, SCL), it draws 1,037 microamps.
If I restore the software bits, which includes a "FuelGauge.sleep()" function, it draws 1,007 microamps. (I'm measuring this with an INA226, FYI. Calibrated, tested, I believe it.)
So I guess it's the SDA and SCL lines that are pulling some current. I've done what I can in my sleep code to shut the I2C system down, but haven't found the magic bullet yet. Maybe I have to physically cut some traces on the board to disable some pullup resistors?
Not a total newbie but clearly there's SOMETHING I'm missing. Any advice appreciated, and thanks.
Here's my code for the GoToSleep() function:
void GoToSleep() {
digitalWrite(MOTOR_ENABLE_PIN, LOW); // turns a voltage booster on and off with this pin
pinMode (CLOCK_POWER_PIN, OUTPUT); // turn off RTC
digitalWrite (CLOCK_POWER_PIN, LOW);
digitalWrite(LEDPIN, LOW);
#ifdef fuelgauge
Serial.println(F("sleep: Fuelgauge about to sleep")); delay(10);
//FuelGauge.sleep();
Serial.print(F("sleep: Fuelgauge Sleeping: ")); Serial.println(FuelGauge.isSleeping());delay(10);
#endif
Wire.end(); // shouldnt need it but ...
// turn off I2C pullups
// but is this what is sucking up power while sleeping? 45 mA?
digitalWrite (A4, LOW);
digitalWrite (A5, LOW);
byte adcsra = ADCSRA;
ADCSRA = 0; // disable ADC
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable (); // ready to sleep
noInterrupts (); // timed sequence follows
power_all_disable (); // power off ADC, Timer 0 and 1, serial interface
resetWatchdog (); // get watchdog ready, 8-second timer
// Note we commented out pullups in Wire-master/libraries/utility/twi.c for extra power savings.
// per http://forum.arduino.cc/index.php?topic=296269.0 comment #7
// turn off brown-out enable in software
// BODS must be set to one and BODSE must be set to zero within four clock cycles
MCUCR = bit (BODS) | bit (BODSE);
// The BODS bit is automatically cleared after three clock cycles
MCUCR = bit (BODS);
interrupts (); // interrupts are required now
sleep_cpu (); // sleep
// now we are sleeping
// when we wake, continue from here
sleep_disable (); // precaution
power_all_enable (); // power everything back on// allow changes, disable reset
ADCSRA = adcsra;
// turn on I2C pullups
digitalWrite (A4, HIGH);
digitalWrite (A5, HIGH); delay(10);
#ifdef fuelgauge
//FuelGauge.awake();
Serial.print(F("wake: Fuelgauge Sleeping: ")); Serial.println(FuelGauge.isSleeping());delay(10);
#endif
}