How do I get battery status of my particle?

I am using a battery Polymer Lithium Ion Battery - 400mAh and Photon Battery Shield.

I would like to send a webhook publish of the battery power left to my device. How would I find this out?

Iā€™m able to get this through the following in my code, all from a previous post:

Include the library PowerShield/PowerShield.h. I accomplished this through the include library function of the Particle web IDE. Then call PowerShield batteryMonitor;. The top of my file reads:

#include "PowerShield/PowerShield.h"
PowerShield batteryMonitor;

Then, in setup:

void setup() {
Serial.begin(9600);
    // This essentially starts the I2C bus
    batteryMonitor.begin();
    // This sets up the fuel gauge
    batteryMonitor.quickStart();
    // Wait for it to settle down
    delay(500); //delay 0.5 second

Then in void loop()

// Read the volatge of the LiPo
float cellVoltage = batteryMonitor.getVCell();
    // Read the State of Charge of the LiPo
float stateOfCharge = batteryMonitor.getSoC();

I then publish with the following:

Particle.publish("ps-voltage", String(cellVoltage));
Particle.publish("ps-soc", String(stateOfCharge));

Hope that helps.

1 Like

Can I use this to determine battery charge of an external battery that is powering my unit?
When I built sensor units from scratch, I powered the unit using a boost from (2) AA batteries (low current draw for a short period of time). I was able to use an analog pin to report the battery charge ahead of the booster.
Iā€™d like to have an easy way to report back the power on the batteries, then use the boost output on 3v3 to power the board.