Skip to content

Commit 22aba82

Browse files
authored
Merge pull request #7 from KeithTheEE/add_one_shot_co2
Add one shot co2 measurement
2 parents ad1dbd3 + ed8180c commit 22aba82

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

adafruit_scd4x.py

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
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

6466
class 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()

examples/scd41_single_shot_example.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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)

0 commit comments

Comments
 (0)