FuelGauge library missing?

Looking to use the FuelGauge library and I can’t seem to find the library in the web IDE. Any ideas on what I should do?

awesome thanks!

I’d rather go for the Particle one hosted here

Or look in the docs


Thank you! That library was super easy to use. One problem, in getSoC() the docs say I should be getting a reading between 0 and 100 but Ubidots is displaying a value around 256. Any clues as to what might be causing this?

You’d need to show your code.
Also check the value before you send it to Ubidots - I guess you’ve got a type mismatch.

Switched between double and float and the value remains the same. I’m using D0 and D1 with 10k resistors for a TC74 temp sensor. I disconnected the sensor and bus to see if that was interfering with anything but the value still hasn’t changed. Here’s my sketch:

    #include <PowerShield.h>
    #include <Ubidots.h>

    #define TOKEN "A1E-bCUyFyjHa6Ht5Czi3sTlGoi6us9RmQ"  // Put ubidots token here
    Ubidots ubidots(TOKEN);

    const unsigned long postingRate = 20000; //Post rate to data.sparkfun.com (time in milliseconds)
    unsigned long lastPost = millis();

    const int Electron_Address = 0x48; //Address of TMP102
    const int BYTES_TO_READ = 2; //Number of bytes to read in from TMP102 (should always be 2)

    PowerShield batteryMonitor;

    void setup() {
        Wire.begin(); //Initialize serial communication library
         //ubidots.setDebug(true); //Uncomment this line for printing debug messages

    void message(char* m)

    void loop() {
        if (Wire.isEnabled()) //Check if receiving a signal from I2C pins
            if (lastPost + postingRate < millis()) //Wait to post until ~ 20s has lapsed
                Serial.print("Requesting from :");
                Wire.requestFrom(Electron_Address, BYTES_TO_READ);
                if (Wire.available() == BYTES_TO_READ)
                    byte MSB = Wire.read();
                    byte LSB = Wire.read();
                    int temp = ((( MSB << 8) | LSB) >> 4) * 0.0625; //Remove 4 empty bits from 2nd byte (see datasheet), 
                    //combine 1st byte and 2nd byte then use conversion factor to get temp in deg. C (see datasheet)
                    Serial.print("Temp is :"); 
                    ubidots.add("Temperature", temp);  
                    lastPost = millis();
                    Serial.println("Unable to read the temperature"); 
            Serial.println("Wire is not enabled make sure to call Wire.begin()"); //Used for debugging I2C protocol
        double cellVoltage = batteryMonitor.getVCell();
        double stateOfCharge = batteryMonitor.getSoC();
        float test = 25.25f;
        ubidots.add("test", test);
        ubidots.add("Voltage", cellVoltage);
        ubidots.add("Battery Percentage", stateOfCharge);

I'd rather go with 4k7 pull-ups and when I said this

I meant, you should print out the values locally like this

  Serial.printlnf("%.2f V / %.2f %%", cellVoltage, stateOfCharge);

Once you have confirmed whether the "raw" values are wrong or not, you know whether the problem should be searched in the library/fuel gauge or the use of Ubidots.

Oh duh. Sorry I’ve been a little laggy today. When I print the values through serial I get the same 5v and 256 as before.

These values indicate a communication error with the fuel gauge and the reason is that the PowerShield library is meant for the Photon PowerShield and hence uses the “wrong” I2C interface for the Electron.
I only provided the link for the library so you could see the implementation code.

For the Electron you don’t need the library since that’s already baked into the Electron code by default - no include required.
Hence I’ve also given you the link to the docs. If you use it as shown there you should get correct readings.

Well I feel like an idiot now lol. That was way easier that how I was going about it. Thanks for the info and help!

1 Like