# Photon FW 4.4: i2c not reliable

**URL:** https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058
**Category:** Troubleshooting
**Created:** [September 3, 2015, 11:45am UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058 "2015-09-03T11:45:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![hl68fx](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hl68fx](https://community.particle.io/u/hl68fx)
#### Post date: [September 3, 2015, 11:45am UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/1 "2015-09-03T11:45:45Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

### Author: ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)
#### Post date: [September 3, 2015, 11:51am UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/2 "2015-09-03T11:51:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hl68fx](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hl68fx](https://community.particle.io/u/hl68fx)
#### Post date: [September 3, 2015, 11:59am UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/3 "2015-09-03T11:59:17Z")

</div>

sure, just give me a few minutes 😄

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

---

<div class="post-metadata">

### Author: ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)
#### Post date: [September 3, 2015, 12:36pm UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/4 "2015-09-03T12:36:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)
#### Post date: [September 3, 2015, 12:41pm UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/5 "2015-09-03T12:41:53Z")

</div>

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:

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

```

Any interest in trying that?

---

<div class="post-metadata">

### Author: ![hl68fx](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hl68fx](https://community.particle.io/u/hl68fx)
#### Post date: [September 3, 2015, 12:57pm UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/6 "2015-09-03T12:57:48Z")

</div>

hi @bko,

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

---

<div class="post-metadata">

### Author: ![Carsten4207](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/carsten4207/32/130_2.png) [@Carsten4207](https://community.particle.io/u/Carsten4207)
#### Post date: [September 3, 2015, 1:32pm UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/7 "2015-09-03T13:32:14Z")

</div>

I will try this too with my MCP23017. Thanks!

---

<div class="post-metadata">

### Author: ![hl68fx](https://avatars.discourse-cdn.com/v4/letter/h/ea5d25/32.png) [@hl68fx](https://community.particle.io/u/hl68fx)
#### Post date: [September 3, 2015, 5:58pm UTC](https://community.particle.io/t/photon-fw-4-4-i2c-not-reliable/15058/8 "2015-09-03T17:58:32Z")

</div>

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 😃  
First I tried it without the row Wire.begin(); but that did not change anything 😄  
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.
