Photon FW 4.4: i2c not reliable

Hi, I am using my Photon with the new Power Shield, a MPL3115A2 and a HTU21D-F. Every 60 seconds I read the sensors and post the values to Thingspeak. This works great but after a few hours i2c stops working. I receive the value 998 from my HTU21D-F which indicates that i2c timed out.
First I thought it is because I control the power of my sensors with a NPN2222 transistor. But switching to continous power didn’t solve the issue.
After the 998 I do not receive any further data. Only disconnecting the power from the Photon helps.

My code:

if(millis() - lastPostTime > 60000L){
  //digitalWrite(powerPin, HIGH); 
  //delay(500); //wait to power up

  hum= htu.readHumidity();
  temp = htu.readTemperature();
  pressure = baro.getPressure();

  //digitalWrite(powerPin, LOW);

  sendValues(hum, temp, pressure, cellVoltage, stateOfCharge);
  lastPostTime = millis();
}

Could it be possible that there is still an issue with i2c?

Could you make sure your Photon is running 0.4.4 by upgrading it with the CLI using particle update?

sure, just give me a few minutes :smile:

Edit:
Particle CLI did not work: Cannot open DFU device 0a5c:217f
But I managed to use Particle Dev to connect to the Photon and press ‘v’ to get the system firmware version.
The output is: system firmware version: 0.4.4

I guess the version is okay then. Weird. Perhaps something for @mdma to look into.

Hi @hl68fx

The STM32F205 processor errata says there are problems with i2c and the 0.4.4 has the work-arounds that Particle thought would be the best, but there still could be problems, particularly with multiple i2c devices over a long period. The battery gauge thread also shows some problems even with 0.4.4.

Another user reported that they could get out of the bad state by doing this when it gets stuck:

Wire.beginTransmission(deviceAddress);
Wire.endTransmission();

Any interest in trying that?

1 Like

hi @bko,

thank you! I put your code into my sketch and report back asap.

1 Like

I will try this too with my MCP23017. Thanks!

1 Like

After a few hours of testing I can say that it works better now.

this is my code:

if(millis() - lastPostTime > 60000L){
//digitalWrite(powerPin, HIGH);
//delay(500); //wait to power up

hum= htu.readHumidity();
temp = htu.readTemperature();
pressure = baro.getPressure();

if (hum == 998){
Wire.beginTransmission(0x40);
Wire.endTransmission();
Wire.begin();
}

sendValues(hum, temp, pressure, cellVoltage, stateOfCharge);
lastPostTime = millis();
}

I am not sure if I did what I should do :smiley:
First I tried it without the row Wire.begin(); but that did not change anything :smile:
After adding Wire.begin(); it works better. When I receive the value 998 it takes about 5 to 10 minutes to continue sending correct values again.