diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 5fc3f95..6d33c87 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -59,6 +59,8 @@ _SCD4X_PERSISTSETTINGS = const(0x3615) _SCD4X_GETASCE = const(0x2313) _SCD4X_SETASCE = const(0x2416) +_SCD4X_MEASURESINGLESHOT = const(0x219D) +_SCD4X_MEASURESINGLESHOTRHTONLY = const(0x2196) class SCD4X: @@ -147,6 +149,16 @@ def relative_humidity(self) -> float: self._read_data() return self._relative_humidity + def measure_single_shot(self) -> None: + """On-demand measurement of CO2 concentration, relative humidity, and + temperature for SCD41 only""" + self._send_command(_SCD4X_MEASURESINGLESHOT, cmd_delay=5) + + def measure_single_shot_rht_only(self) -> None: + """On-demand measurement of relative humidity and temperature for + SCD41 only""" + self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) + def reinit(self) -> None: """Reinitializes the sensor by reloading user settings from EEPROM.""" self.stop_periodic_measurement() diff --git a/examples/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py new file mode 100644 index 0000000..6b04d0d --- /dev/null +++ b/examples/scd41_single_shot_example.py @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2021 by Keith Murray, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense +import time +import board +import adafruit_scd4x + +i2c = board.I2C() +scd4x = adafruit_scd4x.SCD4X(i2c) +print("Serial number:", [hex(i) for i in scd4x.serial_number]) + +print("Waiting for single shot CO2 measurement from SCD41....") +scd4x.measure_single_shot() + +sample_counter = 0 +while sample_counter < 3: + if scd4x.data_ready: + print("CO2: %d ppm" % scd4x.CO2) + print("Temperature: %0.1f *C" % scd4x.temperature) + print("Humidity: %0.1f %%" % scd4x.relative_humidity) + print() + scd4x.measure_single_shot() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1) + + +print("Waiting for single shot Humidity and Temperature measurement from SCD41....") +scd4x.measure_single_shot_rht_only() + +sample_counter = 0 +while sample_counter < 3: + if scd4x.data_ready: + print("CO2: %d ppm" % scd4x.CO2) # Should be 0 ppm + print("Temperature: %0.1f *C" % scd4x.temperature) + print("Humidity: %0.1f %%" % scd4x.relative_humidity) + print() + scd4x.measure_single_shot_rht_only() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1)