How could I fix this runtime error? I'd like it to skip the reading and carry on with the program if it gets an error but it stops the program
I've got the Adafruit SCD-30 Co2 sensor and when reading the data using their example code I get this error
Traceback (most recent call last):
File "pm.py", line 43, in <module>
print("CO2:", scd.CO2, "PPM")
File "/usr/local/lib/python3.7/dist-packages/adafruit_scd30.py", line 183, in CO2
self._read_data()
File "/usr/local/lib/python3.7/dist-packages/adafruit_scd30.py", line 246, in _read_data
raise RuntimeError("CRC check failed while reading data")
RuntimeError: CRC check failed while reading data
This is the line it fails on
print("CO2:", scd.CO2, "PPM")
This is the crc checking section of their code
def _read_data(self):
self._send_command(_CMD_READ_MEASUREMENT)
with self.i2c_device as i2c:
i2c.readinto(self._buffer)
crcs_good = True
for i in range(0, 18, 3):
crc_good = self._check_crc(self._buffer[i : i + 2], self._buffer[i + 2])
if crc_good:
continue
crcs_good = False
if not crcs_good:
raise RuntimeError("CRC check failed while reading data")
self._co2 = unpack(">f", self._buffer[0:2] + self._buffer[3:5])[0]
self._temperature = unpack(">f", self._buffer[6:8] + self._buffer[9:11])[0]
self._relative_humidity = unpack(
">f", self._buffer[12:14] + self._buffer[15:17]
)[0]
Is there a way to tell it to do something like this
if not crcs_good:
skip reading and wait for the next one