Skip to main content

Module scd4x

Module scd4x 

Source
Expand description

Sensirion SCD40 and SCD41 CO2, temperature, and humidity sensor.

The SCD4x is a photoacoustic NDIR CO2 sensor with a built-in humidity and temperature sensor, driven over I2C by 16-bit command words. Every data word it sends or receives is followed by a CRC-8, and its measurement is three such words: CO2 in parts per million, then a temperature and a humidity ratio scaled over the 16-bit range. This module carries the command table, the checksum, the frame builders and parsers, and the datasheet’s conversion formulas, each anchored to the worked examples the datasheet prints beside its command descriptions.

A caller sends command::START_PERIODIC_MEASUREMENT once, polls data_ready on the command::GET_DATA_READY_STATUS word, and reads the nine bytes of command::READ_MEASUREMENT into Measurement::parse. Temperatures and humidities are returned in integer milli-units, with f32 conveniences beside them.

Modules§

command
The command words (Table 9), 16 bits each, most significant byte first, with no CRC after the command itself.

Structs§

Measurement
One SCD4x measurement, as the three words of read_measurement.

Constants§

CO2_MAX_PPM
The largest CO2 concentration the sensor reports, in ppm (Table 1: output range 0 to 40’000 ppm).
DEFAULT_TEMPERATURE_OFFSET_MILLI_CELSIUS
The factory temperature offset, in milli-degrees Celsius (section 3.6.1: “per default, the temperature offset is set to 4 °C”).
FORCED_RECALIBRATION_FAILED
The perform_forced_recalibration response that reports a failed recalibration (Table 18).
I2C_ADDRESS
The I2C address (Table 8); the part has no address pins.
LOW_POWER_PERIODIC_MEASUREMENT_INTERVAL_MS
The approximate signal update interval of low power periodic measurement, in milliseconds (section 3.8).
PERIODIC_MEASUREMENT_INTERVAL_MS
The signal update interval of periodic measurement, in milliseconds (section 3.5).
POWER_UP_TIME_MS
The time the sensor needs after power-up or reinit before it accepts a command, in milliseconds (Table 7).

Functions§

allowed_during_measurement
Returns whether a command may be sent while a periodic measurement is running.
ambient_pressure_pascals
Decodes an ambient pressure word back to pascals.
ambient_pressure_word
Encodes an ambient pressure as the set_ambient_pressure word.
automatic_self_calibration_enabled
Returns whether an automatic self-calibration word reports ASC enabled.
automatic_self_calibration_word
Builds the automatic self-calibration word for an enabled state.
celsius
Decodes the raw temperature word to degrees Celsius.
command_frame
Builds the two bytes of a command that carries no data word.
crc
Computes the CRC-8 that follows every data word.
data_ready
Returns whether the data ready word reports a measurement waiting to be read.
forced_recalibration_correction_ppm
Decodes the perform_forced_recalibration response to the correction applied.
forced_recalibration_word
Builds the perform_forced_recalibration response word for a correction.
humidity_milli_percent
Decodes the raw humidity word to thousandths of a percent relative humidity.
humidity_raw
Builds the raw humidity word the sensor reports for a relative humidity.
max_duration_ms
Returns the maximum command duration of a command word, in milliseconds.
milli_celsius
Decodes the raw temperature word to milli-degrees Celsius.
relative_humidity_percent
Decodes the raw humidity word to percent relative humidity.
self_test_passed
Returns whether the self-test word reports no malfunction.
serial_number
Decodes the nine bytes of get_serial_number to the 48-bit serial number.
serial_number_frame
Builds the nine bytes a sensor sends for a serial number.
temperature_offset_milli_celsius
Decodes the get_temperature_offset word to milli-degrees Celsius.
temperature_offset_word
Encodes a temperature offset as the set_temperature_offset word.
temperature_raw
Builds the raw temperature word the sensor reports for a temperature.
word
Decodes one data word from its three-byte frame, checking the CRC.
word_frame
Builds the three-byte frame of one data word: the word, most significant byte first, followed by its CRC.
write_frame
Builds the five bytes of a write command: the command word followed by one data word and its CRC.