Photon Power Shield - Power Indicator, question

Hello every one,
I am trying to get the Power Shield going, but I am not having the results I expect. Here is a little code that I wrote.



// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#include "PowerShield.h"

//#include "Particle.h" // C++ Preprocessor  will not need to add it automatically
//#include "Arduino.h"  // Added to support extended Arduino APIs

BlynkTimer timer;
char auth[] = "xyxyxyxyxyyxyxyx";
PowerShield batteryMonitor;

void setup() 
{
Blynk.begin(auth, IPAddress(111,222,333,444), 8080);
batteryMonitor.begin(); // This essentially starts the I2C bus
batteryMonitor.quickStart();   // This sets up the fuel gauge
timer.setInterval(1000, CheckBattery);
}


void CheckBattery() 
{
float cellVoltage = batteryMonitor.getVCell(); // Read the volatge of the LiPo
float stateOfCharge = batteryMonitor.getSoC();// Read the State of Charge of the LiPo
Blynk.virtualWrite(V0, "Voltage : ", cellVoltage, "\n");
Blynk.virtualWrite(V1, "Charge : ", stateOfCharge , "\n");
}

void loop()
{
Blynk.run();
timer.run(); 
}

This line:

Blynk.virtualWrite(V0, "Voltage : ", cellVoltage, "\n");

is suppose to show me the actual voltage of the battery, am I right? Instead, I get a permanent 5 volts indicator, then the battery runs out of power, and that’t it. How can I get the actual voltage?

Thanks.

I suspect what you are really looking for is the state of charge of the battery.

float stateOfCharge = batteryMonitor.getSoC();

This is not using Blynk but works as far reading battery stats is concerned
(notice, no extra library for the fuel gauge needed anymore)

FuelGauge batteryMonitor;

void CheckBattery();

Timer timer(1000, CheckBattery);
char msg[64];
volatile bool newData = false;

void setup() 
{
  Serial.begin();
  batteryMonitor.begin();                           // This essentially starts the I2C bus
  batteryMonitor.quickStart();                      // This sets up the fuel gauge
  timer.start();
}

void CheckBattery() 
{
  float cellVoltage = batteryMonitor.getVCell();    // Read the volatge of the LiPo
  float stateOfCharge = batteryMonitor.getSoC();    // Read the State of Charge of the LiPo
  snprintf(msg, sizeof(msg), "Voltage: %.2fV, Charge: %.2f%%", cellVoltage, stateOfCharge);
  Serial.println(msg);
  newData = true;
}

void loop()
{
  if (!newData) return;
  
  newData = false;
  Particle.publish("Battery", msg, PRIVATE);
}
1 Like

Thanks a lot, ScruffR. I will check it out using your suggestion, and report later.