After a Wire.requestFrom() there should be no Wire.endTransmission().
After a Wire.requestFrom(), all the waiting may be removed, for example while (Wire.available() < 3); or delay(10);.
The waiting with millis() may also be removed. There is not timeout after a Wire.requestFrom(), so the variable did_timeout makes no sense.
It is possible to check if the data was received:
Wire.requestFrom(address, (byte)6);
if(Wire.available() != 6)
{
i2c_sensor_error = true; // a variable name that I made up
return;
}
That will detect if the sensor was connected or not, but the return value of Wire.endTransmission() could also be used for that.
The Wire library is used in the wrong way in the files:
Explanation: Common-mistakes, number 1 and 2.
After a
Wire.requestFrom()
there should be noWire.endTransmission()
. After aWire.requestFrom()
, all the waiting may be removed, for examplewhile (Wire.available() < 3);
ordelay(10);
. The waiting with millis() may also be removed. There is not timeout after aWire.requestFrom()
, so the variabledid_timeout
makes no sense.It is possible to check if the data was received:
That will detect if the sensor was connected or not, but the return value of
Wire.endTransmission()
could also be used for that.