I am building a portable Temp/Humidity sensor with DHT22, a small Nokia5110 Lcd, a Spark Battery Shield and our beloved Photon.
For now it seems to work fine but since I added the battery detection function I saw a very strange behaviour: the LCD led turns almost immediately off.
I tried initializing the Shield in setup but the result is the same.
“Spark Battery Shield” is a bit ambiguous.
Do you really mean the mustache shaped one, or is it the SparkFunPhoton Battery Shield, or is it the Particle Power Shield?
We’d need to know. Maybe you’ve got a pin collision.
I’m using that SparkFun battery shield with Photon with no issues getting updates on I2C.
You are right taking these calls out of getBatteryData() and put them into setup.
// Set up the MAX17043 LiPo fuel gauge:
lipo.begin(); // Initialize the MAX17043 LiPo fuel gauge
// Quick start restarts the MAX17043 in hopes of getting a more accurate
// guess for the SOC.
lipo.quickStart();
// We can set an interrupt to alert when the battery SoC gets too low.
// We can alert at anywhere between 1% - 32%:
lipo.setThreshold(20); // Set alert threshold to 20%.
Have you tested that POST to be sure it isn’t locking things up? I’d try commenting out the POST in the function to rule out any issues there as well (print to serial instead?). That interrupt may need clearing so you may be making that POST on startup, even if your battery is charged above the interrupt threshold.
Anyways, more serial debug is always better to try to see where things have gone pear-shaped.
My main bugaboo with that battery charging breakout is that there is no way to tell if the circuit is charging (in software or hardware). They missed that…