Fix I2C Error during wakeup, add retry logic #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #13
I've had a quick test on an Adafruit ESP32 Feather v2 with the sensor connected to the StemmaQT / qwiic connector (i2c cable) and can confirm recreating the issue of
NaN
being returned for subsequent reads with no delay.Adding the 100ms delay between reads gives me humidity too, but I see a spurious error on the first temperature reading with the basic example. The datasheet says to give 2seconds to stabilise after power-on, so adding a 2second wait at the end of setup removes the first temperature i2c #263 error, and the humidity errors remain, but the i2c bus detect does now show detected on the second call.
There is a similar report in circuitpython, with a 30ms delay minimum (I found that not enough in arduino). The datasheet mentions after having a read it will return to passive sleep mode until the next wake command, so it's possible we are attempting to communicate during this period.
I've increase the delay in readRegister32, from 10ms to 100ms upon failure, with a retry if the read command also fails.
The readings can now be called in a tight loop, and as expected they only change every two seconds.
@ladyada