Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions adafruit_scd4x.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
43 changes: 43 additions & 0 deletions examples/scd41_single_shot_example.py
Original file line number Diff line number Diff line change
@@ -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)