I have an Electron and connected the HTU21D temp and humidity sensor to it directly on the D0 and D1 pins.
When I run the sample sketch from https://build.particle.io/libs/53edeb4ccf314539c90003a4/tab/HTU21D.ino then it all works fine, but as soon as I use SLEEP_NETWORK_STANDBY to put the Electron to sleep, then the HTU21D reports 998 values - which is the equivalent of I2C connection errors. Even if after each sleep I use:
while(! htu.begin()){ Serial.println("HTU21D not found"); delay(1000); }
If I use normal sleep (which restarts), then it works.
See code below.
The sample sketch of HTU21D with normal sleep - which sleeps restarts and reconnects to the cloud at each iteration - works, at each iteration it reads the correct values from the HTU21D:
#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);
}
But when using the SLEEP_NETWORK_STANDBY then only the first reading of HTU21D shows the right values, then it shows 998 for each reading
#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(! htu.begin()){ Serial.println("HTU21D not found"); delay(1000); }
}
This seems to indicate that the SLEEP_NETWORK_STANDBY breaks I2C.
Any suggestions?