adafruit / Adafruit_CircuitPython_SCD4X

CircuitPython/Python driver for Sensirion SCD40 & SCD41
MIT License
20 stars 10 forks source link

Add one shot co2 measurement #7

Closed KeithTheEE closed 1 year ago

KeithTheEE commented 3 years ago

This pull request probably isn't ready to merge because I haven't tested it on the SCD41.

There's an added example that should make it easy to setup and test on the SCD41. It should grab three samples of one shot co2 measurements, and then three samples of one shot relative humidity and temperature. I grab three samples because the datasheet suggests if the single shot is made right after powerup, it's better to grab three and drop the first two due to noise at start up.

I expected to get nonsense values on the SCD40, but it just returned 'kind of' accurate measurements. (I say kind of because there was a moderate amount of noise, but they were close to the expected values).

The measure_single_shot_rht_only should have a co2 value of 0 ppm, and if we don't get that on the SCD41, then there's a bug in the code I need to fix. I guessed the SCD40 would at least return a 0 there as well, but it did not, so I don't know how much of that is because of a bug vs because the 40 doesn't respond to that command.

In the event this is ready to be merged soon, it should address #5

kattni commented 3 years ago

Ah, yes! I knew this was incoming but did not see it had been submitted. I'll test it this week!

kattni commented 3 years ago

@KeithTheEE I haven't looked deeply at this PR yet, but did you ever really figure out how to differentiate between the chips? Or do we simply have to document the caveat that it isn't supported on the 40? I want to add the feature, but I'm hesitant to add something that will "work" on both, even though it's only supported on one.

KeithTheEE commented 3 years ago

I have not found out how to distinguish between the two. I have an idea, but it's dependent on measure_single_shot_rht_only for the moment.

Basically if it doesn't return '0' for the co2 ppm on the measure_single_shot_rht_only, it's an scd40, if it does it's an scd41. But that's assuming I even implemented that correctly. So if you don't get a 0 co2 ppm then when you call it on an SCD41, this code has a bug and shouldn't be merged.

I'm just at the stage where I'm understanding how the two sensors respond to the same call.

kattni commented 3 years ago

@KeithTheEE Noted! I'll let you know what I get once I get set up to test it.

kattni commented 3 years ago

@KeithTheEE Here are the results I get with your example. Please let me know if I should be trying something else.

code.py output:
Serial number: ['0x41', '0x6f', '0x5f', '0x7', '0x3b', '0x4a']
Waiting for single shot CO2 measurement from SCD41....
CO2: 660 ppm
Temperature: 18.5 *C
Humidity: 56.1 %

CO2: 718 ppm
Temperature: 18.7 *C
Humidity: 55.9 %

CO2: 691 ppm
Temperature: 19.0 *C
Humidity: 55.4 %

Waiting for single shot Humidity and Temperature measurement from SCD41....
CO2: 656 ppm
Temperature: 19.3 *C
Humidity: 54.7 %

CO2: 656 ppm
Temperature: 19.3 *C
Humidity: 54.7 %

CO2: 656 ppm
Temperature: 19.3 *C
Humidity: 54.6 %

Code done running.
KeithTheEE commented 3 years ago

Whelp that means I messed something up. Thank you for giving it a test, I'll have to dig in and see what's the cause of the bug.

kattni commented 3 years ago

@KeithTheEE We can keep this open and put it in draft status if you intend to continue working on it. That would keep someone from merging it, but still keep it open for collaboration and so on. Would that work better for you?

KeithTheEE commented 3 years ago

Oh yeah that would work! I didn't know I could keep it as a draft.

kattni commented 3 years ago

Yeah, it's a subtle suggestion in the menu on the right side of the PR. Not super obvious if you don't know to look for it. Also, I'm uncertain whether you, not having write access, can even see the option. Either way, bumped into draft status.

KeithTheEE commented 3 years ago

I recently got the scd41, so I should be able to start testing this more rapidly this week.

FoamyGuy commented 2 years ago

@KeithTheEE just checking in on this one, is this still something you are going to be looking into?

hopkapi commented 2 years ago

Hey, don't know if this is helpful/news to anyone, but it looks like Sensirion recently (May 2022) updated the datasheet to add info on power down and wake up commands specifically for the single-shot mode. I also now have a sensor to actually test with, though don't have anything that can measure µAs of power etc.

https://sensirion.github.io/python-i2c-scd/api.html?highlight=wake#sensirion_i2c_scd.scd4x.device.Scd4xI2cDevice.power_down too

litui commented 2 years ago

Just chiming in that this patch is confirmed working for me with @KeithTheEE's changes on the SCD41. It could probably be merged as-is.