Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix I2C Error during wakeup, add retry logic #14

Merged
merged 2 commits into from
Aug 25, 2023
Merged

Conversation

tyeth
Copy link
Contributor

@tyeth tyeth commented Aug 21, 2023

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

@tyeth tyeth requested a review from ladyada August 21, 2023 17:29
@tyeth
Copy link
Contributor Author

tyeth commented Aug 21, 2023

Seen the clang failure, just down at the duck pond, will fix when back

Fixes #13

Updated after feedback from @ladyada
@tyeth
Copy link
Contributor Author

tyeth commented Aug 25, 2023

@ladyada ready for re-review. Took your suggestion of a 3 retry for-loop, and retested with varying delays.
(Always no delay in read loop to test worst case).

@ladyada
Copy link
Member

ladyada commented Aug 25, 2023

lgtm but not tested on hardware - im going to assume you did that part :)

@ladyada ladyada merged commit 61cfe5a into master Aug 25, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Humidity data I2C Error - ESP32
2 participants