TVOC Unit

TVOCUnit is a hardware module for measuring Total Volatile Organic Compounds (TVOC) and equivalent CO2 (eCO2). It is based on the SGP30 sensor and communicates via the I2C interface. The class supports configuration and measurement operations.

Support the following products:

TVOCUnit

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

UIFLOW2 Example:

example.png

tvoc_cores3_example.m5f2

class TVOCUnit

Constructors

class TVOCUnit(i2c, address)

Initialize the TVOCUnit with the specified I2C interface and address.

Parameters:
  • i2c – The I2C interface or PAHUBUnit object for communication with the sensor.

  • address (int) – The I2C address of the TVOC unit. Defaults to 0x58.

UIFLOW2:

init.png

Methods

TVOCUnit.available()

Check whether the TVOC/eCO2 unit is available.

TVOCUnit.set_baseline_co2_tvoc(co2eq, tvoc)

Set the baseline values for CO2 and TVOC measurements.

Parameters:
  • co2eq (int) – The CO2 equivalent baseline value to be set.

  • tvoc (int) – The TVOC baseline value to be set.

UIFLOW2:

set_baseline_co2_tvoc.png

TVOCUnit.set_relative_humidity(humidity_per, temp_c)

Set the relative humidity and temperature for accurate air quality measurement.

Parameters:
  • humidity_per (float) – The relative humidity in percentage (%).

  • temp_c (float) – The ambient temperature in Celsius (°C).

UIFLOW2:

set_relative_humidity.png

TVOCUnit.iaq_init()

Initialize the IAQ (Indoor Air Quality) algorithm for the sensor.

TVOCUnit.measure_iaq()

Measure the CO2 equivalent (CO2eq) and TVOC values.

TVOCUnit.get_iaq_baseline()

Retrieve the IAQ algorithm baseline values for CO2eq and TVOC.

TVOCUnit.set_iaq_baseline(co2eq, tvoc)

Set the previously recorded IAQ algorithm baseline values for CO2eq and TVOC.

Parameters:
  • co2eq – The CO2 equivalent baseline value.

  • tvoc – The TVOC baseline value.

TVOCUnit.set_absolute_humidity(absolute_humidity)

Set the absolute humidity compensation for the sensor. To disable, set the value to 0.

Parameters:

absolute_humidity – The absolute humidity value to set.

TVOCUnit.measure_test()

Run the on-chip self-test.

TVOCUnit.get_feature_set()

Retrieve the feature set of the sensor.

TVOCUnit.measure_raw()

Return raw H2 and Ethanol signals for part verification and testing.

TVOCUnit.get_serial()

Retrieve the sensor serial ID.

TVOCUnit.co2eq()

Retrieve the Carbon Dioxide Equivalent (CO2eq) in parts per million (ppm).

UIFLOW2:

co2eq.png

TVOCUnit.baseline_co2eq()

Retrieve the baseline value for CO2eq.

UIFLOW2:

baseline_co2eq.png

TVOCUnit.tvoc()

Retrieve the Total Volatile Organic Compound (TVOC) in parts per billion (ppb).

UIFLOW2:

tvoc.png

TVOCUnit.baseline_tvoc()

Retrieve the baseline value for TVOC.

UIFLOW2:

baseline_tvoc.png

TVOCUnit.raw_h2()

Retrieve the raw H2 signal value.

UIFLOW2:

raw_h2.png

TVOCUnit.raw_ethanol()

Retrieve the raw Ethanol signal value.

UIFLOW2:

raw_ethanol.png

TVOCUnit.convert_r_to_a_humidity(temp_c, r_humidity_perc, fixed_point)

Convert relative humidity to absolute humidity based on the sensor's equation.

Parameters:
  • temp_c – The ambient temperature in Celsius (°C).

  • r_humidity_perc – The relative humidity in percentage (%).

  • fixed_point (bool) – Whether to return the value in 8.8 fixed-point format. Defaults to True.