CO2L Unit

UNIT CO2L 是一款数字空气 CO2 浓度检测 Unit,支持单次测量低功耗模式,内置 Sensirion 的 SCD41 传感器和降压电源电路,并通过 I2C 通信。该 Unit 适用于空气环境条件测量,CO2 测量范围为 400 ppm – 5000 ppm,在同时测量环境温度和湿度的情况下,CO2 测量的典型精度为 ±(40 ppm + 5 % 读数)。

支持以下产品:

CO2LUnit

MicroPython 应用示例

 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 *
 9from unit import CO2LUnit
10
11
12title0 = None
13label0 = None
14label1 = None
15label2 = None
16label3 = None
17i2c0 = None
18co2l_0 = None
19
20
21def setup():
22    global title0, label0, label1, label2, label3, i2c0, co2l_0
23
24    M5.begin()
25    Widgets.fillScreen(0x222222)
26    title0 = Widgets.Title(
27        "CO2LUnit CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
28    )
29    label0 = Widgets.Label("label0", 1, 44, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
30    label1 = Widgets.Label("label1", 1, 95, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
31    label2 = Widgets.Label("label2", 1, 146, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
32    label3 = Widgets.Label("label3", 1, 198, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
33
34    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
35    co2l_0 = CO2LUnit(i2c0)
36    co2l_0.set_start_periodic_measurement()
37
38
39def loop():
40    global title0, label0, label1, label2, label3, i2c0, co2l_0
41    if co2l_0.is_data_ready():
42        label0.setText(str("Data is ready."))
43        label1.setText(str((str("CO2 ppm:") + str((co2l_0.co2)))))
44        label2.setText(str((str("Humidity:") + str((co2l_0.humidity)))))
45        label3.setText(str((str("Temperature:") + str((co2l_0.temperature)))))
46    else:
47        label0.setText(str("Data not ready."))
48
49
50if __name__ == "__main__":
51    try:
52        setup()
53        while True:
54            loop()
55    except (Exception, KeyboardInterrupt) as e:
56        try:
57            from utility import print_error_msg
58
59            print_error_msg(e)
60        except ImportError:
61            print("please update to latest firmware")

UiFlow2 应用示例

example.png

co2l_cores3_example.m5f2

class CO2LUnit

“””Constructors”””

class CO2LUnit(i2c, address)

使用 I2C 接口和地址初始化 CO2LUnit。

参数:
  • i2c – 用于通信的 I2C 接口或 PAHUBUnit 实例。

  • address (int) – CO2 传感器的 I2C 地址,默认为 0x62。

UIFLOW2:

init.png

Methods

CO2LUnit.available()

检查 CO2 单元是否在 I2C 总线上可用。

CO2LUnit.set_start_periodic_measurement()

将传感器设置为工作模式,每次测量大约需要 5 秒。

UIFLOW2:

set_start_periodic_measurement.png

CO2LUnit.set_stop_periodic_measurement()

停止传感器的测量模式。

UIFLOW2:

set_stop_periodic_measurement.png

CO2LUnit.get_sensor_measurement()

从传感器获取温度、湿度和 CO2 浓度。

CO2LUnit.is_data_ready()

检查传感器的数据(温度、湿度、CO2)是否已准备就绪。

UIFLOW2:

is_data_ready.png

CO2LUnit.get_temperature_offset()

获取要加到已上报测量值上的温度偏移量。

UIFLOW2:

get_temperature_offset.png

CO2LUnit.set_temperature_offset(offset)

设置温度偏移的最大值为 374°C。

参数:

offset (int) – 要设置的温度偏移量,默认值为 0。

UIFLOW2:

set_temperature_offset.png

CO2LUnit.get_sensor_altitude()

获取测量位置的海拔高度值,单位为 m(相对于海平面)。

UIFLOW2:

get_sensor_altitude.png

CO2LUnit.set_sensor_altitude(height)

设置测量位置相对于海平面的海拔高度值,单位为米。

参数:

height (int) – 要设置的海拔高度(单位:米)。必须在 0 到 65535 米之间。

UIFLOW2:

set_sensor_altitude.png

CO2LUnit.set_ambient_pressure(ambient_pressure)

可随时以 hPa 为单位设置环境气压,以调整 CO2 计算。

参数:

ambient_pressure (int) – 环境压力,单位为 hPa,取值范围限制为 [0, 65535]。

UIFLOW2:

set_ambient_pressure.png

CO2LUnit.set_force_calibration(target_co2)

强制传感器使用给定的当前 CO2 水平重新校准。

参数:

target_co2 (int) – 用于重新校准的当前 CO2 浓度。

UIFLOW2:

set_force_calibration.png

CO2LUnit.get_calibration_enabled()

获取自动自校准(ASC)是启用还是禁用。

UIFLOW2:

get_calibration_enabled.png

CO2LUnit.set_calibration_enabled(enabled)

启用或禁用自动自校准(ASC)。

参数:

enabled (bool) – 设置为 True 以启用 ASC,或设置为 False 以禁用它。

UIFLOW2:

set_calibration_enabled.png

CO2LUnit.set_start_low_periodic_measurement()

将传感器设置为低功耗工作模式,每次测量间隔约 30 秒。

UIFLOW2:

set_start_low_periodic_measurement.png

CO2LUnit.data_isready()

检查是否有来自传感器的新数据可用。

CO2LUnit.save_to_eeprom()

将温度偏移量、海拔偏移量以及自校准启用设置保存到 EEPROM。

UIFLOW2:

save_to_eeprom.png

CO2LUnit.get_serial_number()

获取该传感器的唯一序列号。

UIFLOW2:

get_serial_number.png

CO2LUnit.set_self_test()

执行自检,可能需要长达 10 秒。

UIFLOW2:

set_self_test.png

CO2LUnit.set_factory_reset()

重置 EEPROM 中存储的所有配置设置,并清除 FRC 和 ASC 算法历史记录。

UIFLOW2:

set_factory_reset.png

CO2LUnit.reinit()

通过从 EEPROM 重新加载用户设置来重新初始化传感器。

UIFLOW2:

reinit.png

CO2LUnit.set_single_shot_measurement_all()

将传感器设置为对 CO2、湿度和温度执行单次测量。

CO2LUnit.set_single_shot_measurement_ht()

将传感器设置为对湿度和温度执行单次测量。

CO2LUnit.set_sleep_mode()

将传感器置于睡眠模式以降低电流消耗。

CO2LUnit.set_wake_up()

将传感器从睡眠模式唤醒到空闲模式。

CO2LUnit.write_cmd(cmd_wr, value)

向传感器写入命令。

参数:
  • cmd_wr (int) – 用于向传感器写入的命令。

  • value (int) – 如果有的话,使用该命令发送的值。

CO2LUnit.read_response(num)

读取传感器的响应。

参数:

num (int) – 从传感器读取的字节数。

CO2LUnit.check_crc(buf)

检查接收到的数据的 CRC,以确保其正确。

参数:

buf (bytearray) – 用于检查 CRC 的字节缓冲区。

CO2LUnit.crc8(buffer)

计算给定缓冲区的 CRC-8 校验和。

参数:

buffer (bytearray) – 用于计算 CRC 的字节缓冲区。