Electron: getVCell() returning unreliable values

Hello,

I’m trying to switch off the red battery light when the battery is disconnected, while enable it when the battery is reconnected.

Based on documentation and post I’ve find on the subject, I written the following code:

FuelGauge fuel;
boolean isBattery;

void setup() {

  fuel.reset(); //added in a second phase to trouble shoot the problem to no avail
  Serial.println(fuel.getVCell());
  if ( fuel.getVCell() < 1 ) {
    _pmic.disableCharging();
    isBattery = false;
    Serial.println( "Battery not installed: DISABLE BATTERY CHARGING" );
  } else {
    _pmic.enableCharging();
    isBattery = true;
    Serial.println( "Battery installed: ENABLED BATTERY CHARGING" );
  }

}

 void loop() {

   //I've added a timer to 1s (not shown here)
    fuel.reset(); // added at a later stage to try to solve the voltage issue.
    Serial.println(fuel.getVCell());
    if ( fuel.getVCell() < 1 && isBattery) {
      _pmic.disableCharging();
      isBattery = false;
      Serial.println( "Battery removed: DISABLE BATTERY CHARGING" );
    } else if ( fuel.getVCell() > 1 && !isBattery ){
      _pmic.enableCharging();
      isBattery = true;
      Serial.println( "Battery installed: ENABLE BATTERY CHARGING" );
    }
}

When I run this code, I always get 0.00 voltage whenever the battery is connected or not. What could be wrong in my code? I’m running firmware 0.6.0-rc.1.

You might have to remove the two fuel.reset() and place a fuel.quickStart() in the setup()

Hello kennethlimcp,

Thank for the advice, I’ve implemented it. Now it display the message “battery is installed” when it is not the case. Where could I find a more detailled documentation of those features than what is on the particle reference guide?

tks

@jrm

Here is the link to the Datasheet which I found helpful: http://www.ti.com/product/BQ24195

And take a look at this which may help get rid of the RED LED but depends on you not inserting a battery again: Disabling the Electron red charging LED when not using the LiPo

With some very long delay, thank you RWB & kennethlimcp,

I’ve finally had the time to continue investigate. And in fact the post provided by RWB did solve my issue on the mid-term. I’ll look at the fuel.getVCell issue later on.