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
Data_Ready is rarely ready (True) #17
Comments
The above question was answered via discord chat: No power is not removed from the sensor during any sleep period and a second Ok so roughly speaking you have two sections in the linked code where you call In the first one is right after initialization and you only wait 1 second: I think you need to wait 5 seconds before the CO2 measurement is ready to go. The second one is in the main loop, and the max time it could rest between the last attempted measurement in start up and that call is ~1.1 seconds + code execution time. When looping through that loop it looks like it normally has even less time to rest so it would be not ready most of the time. Adjusting the demo code for this sensor to look like this: scd4x.start_periodic_measurement()
print("Waiting for first measurement....")
old_time = time.monotonic_ns()
while True:
if scd4x.data_ready:
print((time.monotonic_ns()-old_time)/10**9)
old_time = time.monotonic_ns()
print("CO2: %d ppm" % scd4x.CO2)
print("Temperature: %0.1f *C" % scd4x.temperature)
print("Humidity: %0.1f %%" % scd4x.relative_humidity)
print()
time.sleep(.1) in my setup, it shows a time between loops of, Adjusting the So at sampling periods shorter than 5 seconds you're going to run into a lot of data not yet ready issues. The part that's throwing me is this,
Was the sensor initialized and set to |
I'm running this code on an adafruit esp32s2 reverse tft feather, with the scd4x connected (plus an SEN5x but it will gracefully accept not having one (hopefully). Code needs an adafruit io username + key and wifi, plus the SCD40/SCD41/SCD42.
https://github.com/good-enough-technology/Good-Enough_Air-Quality-Device_CO2-SCD4x_PM-SEN5x_CircuitPython
The symptom is that when I was calling
if scd4x_device.data_ready:
after sleeping for 30seconds it was false, but very often false, so my code wouldn't read the metrics that iteration. I never get this issue with the sen5x on same bus. When bug detecting I set it to check in a loop, with time.sleep 0.1, and it took between under a second to over 3seconds to become scd4x_device.data_ready == True. That's not expected behaviour according to my experience with other libraries for this sensor (arduino etc). I have the i2c bus initialised manually (instead of board.I2C) so I can set the frequency, to avoid the esp32s2 100kHz timing bug, but no noticable diference.Using Circuitpython 8.1.0-beta 2 (maybe, but the one with gifio), and now 8.2.0 beta 1.
My understanding from arduino land was data_ready meant new readings available for the read_measurements type function. This library doesn't have such a beastie so the meaning is unclear👹 Is it the same, should I wait until data_ready to read
scd4x_device.co2
? If so, then the sensor is meant to be comfortably pollable at 1Hz so it shouldnt take longer than that for data ready to become truthy. I'll try to get some more exact bug report / reproduction steps / a video.The text was updated successfully, but these errors were encountered: