adafruit / Adafruit_SCD30

Other
14 stars 22 forks source link

Sometimes not initializing #9

Closed caternuson closed 3 years ago

caternuson commented 3 years ago

Re this thread: https://forums.adafruit.com/viewtopic.php?f=19&t=175159

I can recreate this using the test example sketch: https://github.com/adafruit/Adafruit_SCD30/blob/master/examples/adafruit_scd30_test/adafruit_scd30_test.ino

It may initially work: Screenshot from 2021-02-09 12-08-18

but by simply re-uploading the sketch and re-opening serial monitor: Screenshot from 2021-02-09 12-08-32

Re-upload it again and it's back to working, etc.

caternuson commented 3 years ago

This seems like it is also related to reset behavior.

Here's a trace for a case that works as expected: RED = reset(), GREEN = startContinuousMeasurement() image

There's no hiccup between the call to reset() and the next call to startContinuousMeasurement(). Neat....but...wait....zoom in on that reset() call, enhance: image The reset call failed! It NAK'd after sending the first byte of the reset command, 0xD304. Not sure why that happens, but it does not reset as a result.

Here's a trace for a case that fails: CYAN = "the hiccup" image

And zooming in on reset call: image

In this case, the reset command actually went through. So it did its reset, made the weird hiccup, and the next I2C traffic is wonky.

caternuson commented 3 years ago

The serial debug feature of the BusIO library is pretty handy. Here's the serial monitor output for the same cases above with that enabled.

WORKS (reset fails)

Adafruit SCD30 test!
    I2CWRITE @ 0x61 :: 0xD3, 0x4, 
Failed to send!
    I2CWRITE @ 0x61 :: 0x0, 0x10, 0x0, 0x0, 0x81, 
    I2CWRITE @ 0x61 :: 0x46, 0x0, 0x0, 0x2, 0xE3, 
SCD30 Found!
Measurement Interval:   I2CWRITE @ 0x61 :: 0x46, 0x0, 
    I2CREAD  @ 0x61 :: 0x0, 0x2, 
2 seconds
    I2CWRITE @ 0x61 :: 0x2, 0x2, 
    I2CREAD  @ 0x61 :: 0x0, 0x1, 
Data available!
    I2CWRITE @ 0x61 :: 0x3, 0x0, 
    I2CREAD  @ 0x61 :: 0x44, 0xAC, 0xA, 0x1E, 0x28, 0xBD, 0x41, 0xD6, 0x5E, 0x24, 0x60, 0x65, 0x41, 0xF4, 0xBA, 0x6B, 0xE0, 0xF, 
Temperature: 26.77 degrees C
Relative Humidity: 30.55 %
CO2: 1376.942 ppm

    I2CWRITE @ 0x61 :: 0x2, 0x2, 
    I2CREAD  @ 0x61 :: 0x0, 0x0, 
    I2CWRITE @ 0x61 :: 0x2, 0x2, 
    I2CREAD  @ 0x61 :: 0x0, 0x0, 
    I2CWRITE @ 0x61 :: 0x2, 0x2, 
    I2CREAD  @ 0x61 :: 0x0, 0x0, 

FAILS (reset works)

Adafruit SCD30 test!
    I2CWRITE @ 0x61 :: 0xD3, 0x4, 
    I2CWRITE @ 0x61 :: 0x0, 0x10, 0x0, 0x0, 0x81, 
Failed to send!
Failed to find SCD30 chip
ladyada commented 3 years ago

wanna do same thing as before, skip reset?

caternuson commented 3 years ago

@ladyada yah, tried that and it didn't seem to work as well here. still got the works / doesn't work / works / doesn't work cycle with each upload.

caternuson commented 3 years ago

Gonna call this nominally fixed for now based on response in thread linked in first post.

kevinjwalters commented 3 years ago

This looks inconsistent with the approach taken in the CircuitPython library. It has a 100ms pause after reset()

https://github.com/adafruit/Adafruit_CircuitPython_SCD30/blob/f0501d0a6bcffd03e5696cdd53d90bba9672af5e/adafruit_scd30.py#L74-L77

And that reset() is not called in __init__().

caternuson commented 3 years ago

Is this causing an issue?

kevinjwalters commented 3 years ago

None that I'm aware of. I've not used this device myself.