SCD40

The SCD4x is Sensirion’s next generation miniature CO2 sensor. On-chip signal compensation is realized with the build-in SHT4x humidity and temperature sensor.

The specific support of the host for SCD40 is as follows:

Controller

SCD40

AirQ

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9
10
11label0 = None
12rotary = None
13
14
15def btnA_wasClicked_event(state):  # noqa: N802
16    global label0, rotary
17    rotary.reset_rotary_value()
18    label0.setText(str(rotary.get_rotary_value()))
19
20
21def setup():
22    global label0, rotary
23
24    M5.begin()
25    Widgets.fillScreen(0x222222)
26    label0 = Widgets.Label("0", 96, 80, 1.0, 0xFFA000, 0x222222, Widgets.FONTS.DejaVu72)
27
28    BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
29
30    rotary = Rotary()
31
32
33def loop():
34    global label0, rotary
35    M5.update()
36    if rotary.get_rotary_status():
37        label0.setText(str(rotary.get_rotary_value()))
38
39
40if __name__ == "__main__":
41    try:
42        setup()
43        while True:
44            loop()
45    except (Exception, KeyboardInterrupt) as e:
46        try:
47            from utility import print_error_msg
48
49            print_error_msg(e)
50        except ImportError:
51            print("please update to latest firmware")

UIFLOW2 Example:

example.png

airq_scd40_example.m5f2

class SCD40

Constructors

class SCD40

Initialize the SCD40 with the I2C interface and address.

UIFLOW2:

init.png

Methods

SCD40.available()

Check if the SCD40 sensor is available on the I2C bus.

SCD40.set_start_periodic_measurement()

Set the sensor into working mode, which takes about 5 seconds per measurement.

UIFLOW2:

set_start_periodic_measurement.png

SCD40.set_stop_periodic_measurement()

Stop the measurement mode for the sensor.

UIFLOW2:

set_stop_periodic_measurement.png

SCD40.get_sensor_measurement()

Get temperature, humidity, and CO2 concentration from the sensor.

SCD40.is_data_ready()

Check if the data (temperature, humidity, CO2) is ready from the sensor.

UIFLOW2:

is_data_ready.png

SCD40.get_temperature_offset()

Get the temperature offset to be added to the reported measurements.

UIFLOW2:

get_temperature_offset.png

SCD40.set_temperature_offset(offset)

Set the maximum value of 374°C temperature offset.

参数:

offset (int) – The temperature offset to set, default is 0.

UIFLOW2:

set_temperature_offset.png

SCD40.get_sensor_altitude()

Get the altitude value of the measurement location in meters above sea level.

UIFLOW2:

get_sensor_altitude.png

SCD40.set_sensor_altitude(height)

Set the altitude value of the measurement location in meters above sea level.

参数:

height (int) – The altitude in meters to set. Must be between 0 and 65535 meters.

UIFLOW2:

set_sensor_altitude.png

SCD40.set_ambient_pressure(ambient_pressure)

Set the ambient pressure in hPa at any time to adjust CO2 calculations.

参数:

ambient_pressure (int) – The ambient pressure in hPa, constrained to the range [0, 65535].

UIFLOW2:

set_ambient_pressure.png

SCD40.set_force_calibration(target_co2)

Force the sensor to recalibrate with a given current CO2 level.

参数:

target_co2 (int) – The current CO2 concentration to be used for recalibration.

UIFLOW2:

set_force_calibration.png

SCD40.get_calibration_enabled()

Get whether automatic self-calibration (ASC) is enabled or disabled.

UIFLOW2:

get_calibration_enabled.png

SCD40.set_calibration_enabled(enabled)

Enable or disable automatic self-calibration (ASC).

参数:

enabled (bool) – Set to True to enable ASC, or False to disable it.

UIFLOW2:

set_calibration_enabled.png

SCD40.set_start_low_periodic_measurement()

Set the sensor into low power working mode, with about 30 seconds per measurement.

UIFLOW2:

set_start_low_periodic_measurement.png

SCD40.data_isready()

Check if new data is available from the sensor.

SCD40.save_to_eeprom()

Save temperature offset, altitude offset, and self-calibration enable settings to EEPROM.

UIFLOW2:

save_to_eeprom.png

SCD40.get_serial_number()

Get a unique serial number for this sensor.

UIFLOW2:

get_serial_number.png

SCD40.set_self_test()

Perform a self-test, which can take up to 10 seconds.

UIFLOW2:

set_self_test.png

SCD40.set_factory_reset()

Reset all configuration settings stored in the EEPROM and erase the FRC and ASC algorithm history.

UIFLOW2:

set_factory_reset.png

SCD40.reinit()

Reinitialize the sensor by reloading user settings from EEPROM.

UIFLOW2:

reinit.png

SCD40.set_single_shot_measurement_all()

Set the sensor to perform a single-shot measurement for CO2, humidity, and temperature.

SCD40.set_single_shot_measurement_ht()

Set the sensor to perform a single-shot measurement for humidity and temperature.

SCD40.set_sleep_mode()

Put the sensor into sleep mode to reduce current consumption.

SCD40.set_wake_up()

Wake up the sensor from sleep mode into idle mode.

SCD40.write_cmd(cmd_wr, value)

Write a command to the sensor.

参数:
  • cmd_wr (int) – The command to write to the sensor.

  • value (int) – The value to send with the command, if any.

SCD40.read_response(num)

Read the sensor’s response.

参数:

num (int) – The number of bytes to read from the sensor.

SCD40.check_crc(buf)

Check the CRC of the received data to ensure it is correct.

参数:

buf (bytearray) – The buffer of bytes to check the CRC.

SCD40.crc8(buffer)

Calculate the CRC-8 checksum for a given buffer.

参数:

buffer (bytearray) – The buffer of bytes to calculate the CRC for.