File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 5959_SCD4X_PERSISTSETTINGS = const (0x3615 )
6060_SCD4X_GETASCE = const (0x2313 )
6161_SCD4X_SETASCE = const (0x2416 )
62+ _SCD4X_MEASURESINGLESHOT = const (0x219D )
63+ _SCD4X_MEASURESINGLESHOTRHTONLY = const (0x2196 )
6264
6365
6466class SCD4X :
@@ -147,6 +149,16 @@ def relative_humidity(self) -> float:
147149 self ._read_data ()
148150 return self ._relative_humidity
149151
152+ def measure_single_shot (self ) -> None :
153+ """On-demand measurement of CO2 concentration, relative humidity, and
154+ temperature for SCD41 only"""
155+ self ._send_command (_SCD4X_MEASURESINGLESHOT , cmd_delay = 5 )
156+
157+ def measure_single_shot_rht_only (self ) -> None :
158+ """On-demand measurement of relative humidity and temperature for
159+ SCD41 only"""
160+ self ._send_command (_SCD4X_MEASURESINGLESHOTRHTONLY , cmd_delay = 0.05 )
161+
150162 def reinit (self ) -> None :
151163 """Reinitializes the sensor by reloading user settings from EEPROM."""
152164 self .stop_periodic_measurement ()
Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2021 by Keith Murray, written for Adafruit Industries
2+ #
3+ # SPDX-License-Identifier: Unlicense
4+ import time
5+ import board
6+ import adafruit_scd4x
7+
8+ i2c = board .I2C ()
9+ scd4x = adafruit_scd4x .SCD4X (i2c )
10+ print ("Serial number:" , [hex (i ) for i in scd4x .serial_number ])
11+
12+ print ("Waiting for single shot CO2 measurement from SCD41...." )
13+ scd4x .measure_single_shot ()
14+
15+ sample_counter = 0
16+ while sample_counter < 3 :
17+ if scd4x .data_ready :
18+ print ("CO2: %d ppm" % scd4x .CO2 )
19+ print ("Temperature: %0.1f *C" % scd4x .temperature )
20+ print ("Humidity: %0.1f %%" % scd4x .relative_humidity )
21+ print ()
22+ scd4x .measure_single_shot ()
23+ sample_counter += 1
24+ else :
25+ print ("Waiting..." )
26+ time .sleep (1 )
27+
28+
29+ print ("Waiting for single shot Humidity and Temperature measurement from SCD41...." )
30+ scd4x .measure_single_shot_rht_only ()
31+
32+ sample_counter = 0
33+ while sample_counter < 3 :
34+ if scd4x .data_ready :
35+ print ("CO2: %d ppm" % scd4x .CO2 ) # Should be 0 ppm
36+ print ("Temperature: %0.1f *C" % scd4x .temperature )
37+ print ("Humidity: %0.1f %%" % scd4x .relative_humidity )
38+ print ()
39+ scd4x .measure_single_shot_rht_only ()
40+ sample_counter += 1
41+ else :
42+ print ("Waiting..." )
43+ time .sleep (1 )
You can’t perform that action at this time.
0 commit comments