Electron's MAX17043 gives reading of SOC 256 at all times

Electron’s MAX17043 gives reading of SOC 256 at all times

I have a very similar issue to Issue with using Core in a new Sparkfun Battery Shield when trying to read the fuel gauge of the Electron.

I am using the SparkFunMAX17043 library and keep getting the following readings from the Electron’s fuel gauge at all times:
voltage: 5.12V
soc: 256%

This seems to be the same problem as described at Issue with using Core in a new Sparkfun Battery Shield affecting Photon, but that was supposed to be solved.
Only difference is that I never have seen a single correct reading - while most of the people reporting on that original problem stated that they have occasionally seen one.

I am using the most recent developer firmware from GitHub.

I also have a HTU21D connected, which also gives 998 readings on both humidity and temp, which is the code for I2C timeout (100ms), but there at least occasionally I get correct readings. With the fuel gauge I never do.

Might there be some I2C problems with the Electron?

Hmm, what’s the reason to use that library over Particles own functions for the on-board fuel gauge?

https://docs.particle.io/reference/firmware/electron/#fuelgauge

1 Like

You are absolutely right, as I switched to Particle’s own on-board fuel gauge function it worked and worked reliably.
Thanks!

Now, I still have the problem with the HTU21D, which shows correct reading only for the first or first 2 readings and then shows 998 values, indicating some I2C connection problems.

My code has 10 min sleeps with keeping the network on standby, then the HTU21D stops working after the first or first 2 rounds:
System.sleep(D1, RISING, sleepInterval*60, SLEEP_NETWORK_STANDBY)

But after every 10 standby sleeps I also have a SLEEP_MODE_DEEP sleep (because I believe this is the equivalent of a sofrt reboot), after which the HTU21D works again for a round and then back to showing 998 values:
System.sleep(SLEEP_MODE_DEEP, sleepInterval*60)

Any idea what might be going on here?
Would I need some kind of I2C reset between sleeps? Why could that be needed, would I2C connection not surviver a STANDBY sleep?

Thanks

Does the same happen when you just run the sample sketch that comes with the HTU21D library?
https://build.particle.io/libs/53edeb4ccf314539c90003a4/tab/HTU21D.ino

You also don’t need external pull-ups since they are on board already (unless you opened the onboard solder jumper).

How does your wiring look anyway?

Sorry about the late reply.

I don’t have any external pull-ups, I am connecting the board directly.
Wires are going to D0 and D1.

I have tried the sketch from https://build.particle.io/libs/53edeb4ccf314539c90003a4/tab/HTU21D.ino, it works reliably until I don’t add the sleep code - after that only the first one registers the right temperature and humidity value, the rest shows up as 998 (just like in my code).

So this (the original sketch) works fine:
#include “HTU21D/HTU21D.h”

HTU21D htu = HTU21D();

void setup()
{
	Serial.begin(9600);

	Serial.println("HTU21D test");

	while(! htu.begin()){
	    Serial.println("HTU21D not found");
	    delay(1000);
	}

	Serial.println("HTU21D OK");
}

void loop()
{
	Serial.println("===================");
	Serial.print("Hum:"); Serial.println(htu.readHumidity());
	Serial.print("Temp:"); Serial.println(htu.readTemperature());
	Serial.println();

	delay(1000);
    Particle.publish("L", String::format("2.1,2.22,2.22,%2.2f,%2.2f,1", htu.readHumidity(),htu.readTemperature()));
	
	System.sleep(D1, RISING, 10, SLEEP_NETWORK_STANDBY);
}

While this only works fine for the first iteration of the loop, for second, third and any additional iterations the temp and humidity registers 998:

#include "HTU21D/HTU21D.h"

HTU21D htu = HTU21D();

void setup()
{
	Serial.begin(9600);

	Serial.println("HTU21D test");

	while(! htu.begin()){
	    Serial.println("HTU21D not found");
	    delay(1000);
	}

	Serial.println("HTU21D OK");
}

void loop()
{
	Serial.println("===================");
	Serial.print("Hum:"); Serial.println(htu.readHumidity());
	Serial.print("Temp:"); Serial.println(htu.readTemperature());
	Serial.println();

	delay(1000);

    Particle.publish("L", String::format("2.1,2.22,2.22,%2.2f,%2.2f,1", htu.readHumidity(),htu.readTemperature()));
	System.sleep(D1, RISING, 10, SLEEP_NETWORK_STANDBY);
}

But if I do full restart instead of standby, then the HTU21D works - gets proper values instead of 998 at each iteration.

So this (full restart) works:

System.sleep(D1, RISING, 10);