From 66c0f577f05686c8ee51adfee1205e1286b455d7 Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:06:38 -0500 Subject: [PATCH 1/5] Added single shot co2 measurements and single shot humidity and temp measurement for the SCD41 --- adafruit_scd4x.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index d64d701..bf0097a 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -54,6 +54,8 @@ _SCD4X_PERSISTSETTINGS = const(0x3615) _SCD4X_GETASCE = const(0x2313) _SCD4X_SETASCE = const(0x2416) +_SCD4X_MEASURESINGLESHOT = const(0x219D) +_SCD4X_MEASURESINGLESHOTRHTONLY = const(0x2196) class SCD4X: @@ -142,6 +144,16 @@ def relative_humidity(self): self._read_data() return self._relative_humidity + def measure_single_shot(self): + """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): + """On-demand measurement of relative humidity and temperature for + SCD41 only""" + self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) + def reinit(self): """Reinitializes the sensor by reloading user settings from EEPROM.""" self.stop_periodic_measurement() From d44b6bf3174681fdd61b95984dab87949824f36c Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:16:14 -0500 Subject: [PATCH 2/5] Adjusted code for precommit --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index bf0097a..15ea601 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -145,12 +145,12 @@ def relative_humidity(self): return self._relative_humidity def measure_single_shot(self): - """On-demand measurement of CO2 concentration, relative humidity, and + """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): - """On-demand measurement of relative humidity and temperature for + """On-demand measurement of relative humidity and temperature for SCD41 only""" self._send_command(_SCD4X_MEASURESINGLESHOTRHTONLY, cmd_delay=0.05) From 5e11fbf4c385aa2ecfbce65ec0e9fe0a4793bbdd Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 11:42:42 -0500 Subject: [PATCH 3/5] Adding an example for the SCD41 which uses the single shot on demand measurement --- examples/scd41_single_shot_example.py | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/scd41_single_shot_example.py diff --git a/examples/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py new file mode 100644 index 0000000..d0ba9e3 --- /dev/null +++ b/examples/scd41_single_shot_example.py @@ -0,0 +1,41 @@ +# 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]) + +scd4x.measure_single_shot() +print("Waiting for single show CO2 measurement from SCD41....") + +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() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1) + + +scd4x.measure_single_shot_rht_only() +print("Waiting for single show Humidity and Temperature measurement from SCD41....") + +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() + sample_counter += 1 + else: + print("Waiting...") + time.sleep(1) \ No newline at end of file From 7d6aaff18b716438fb7115b2d7d29d787947901e Mon Sep 17 00:00:00 2001 From: CrakeNotSnowman Date: Fri, 27 Aug 2021 14:19:54 -0500 Subject: [PATCH 4/5] Fixed spelling and adjusted example design to more closely match the scd4x datasheet --- examples/scd41_single_shot_example.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/scd41_single_shot_example.py b/examples/scd41_single_shot_example.py index d0ba9e3..6b04d0d 100644 --- a/examples/scd41_single_shot_example.py +++ b/examples/scd41_single_shot_example.py @@ -9,8 +9,8 @@ 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() -print("Waiting for single show CO2 measurement from SCD41....") sample_counter = 0 while sample_counter < 3: @@ -19,23 +19,25 @@ 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() -print("Waiting for single show Humidity and Temperature measurement from SCD41....") sample_counter = 0 while sample_counter < 3: if scd4x.data_ready: - print("CO2: %d ppm" % scd4x.CO2) # Should be 0 ppm + 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) \ No newline at end of file + time.sleep(1) From ed8180c63783629b6ca75ce81e2575db8ea23a9a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 30 Jul 2023 14:19:34 -0500 Subject: [PATCH 5/5] merge main, add type info on new functions --- adafruit_scd4x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index b331af7..6d33c87 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -149,12 +149,12 @@ def relative_humidity(self) -> float: self._read_data() return self._relative_humidity - def measure_single_shot(self): + 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): + 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)