TVOC air monitor ・ TVOC监测
SGP30 センサーで TVOC と eCO2 を測定します。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| Unit Mini TVOC/eCO2 (SGP30) | TVOC/eCO2 sensor | grove_i2c | official page — $10.95 |
M5Stack Core2とSGP30センサーを使って、室内の空気質(TVOCとeCO2)を測定するモニターです。Core2の画面に数値を表示し、空気の状態をひと目で確認できます。
# M5Stack Core2 + SGP30 TVOC/eCO2 Monitor
# Wiring: SGP30 Unit -> Core2 red Port.A (I2C)
import time
from machine import Pin, I2C
from m5stack import lcd
# I2C on Port.A: scl=22, sda=21
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
# SGP30 I2C address is 0x58
SGP30_ADDR = 0x58
# Initialize SGP30: send init command (0x20, 0x03)
i2c.writeto(SGP30_ADDR, bytes([0x20, 0x03]))
time.sleep(0.1)
# Read serial number (optional)
i2c.writeto(SGP30_ADDR, bytes([0x36, 0x82]))
time.sleep(0.01)
data = i2c.readfrom(SGP30_ADDR, 9)
print('Serial:', data.hex())
def read_sgp30():
# Trigger measurement: command 0x20, 0x08
i2c.writeto(SGP30_ADDR, bytes([0x20, 0x08]))
time.sleep(0.05) # wait for measurement
# Read 6 bytes: TVOC (2) + CRC (1) + eCO2 (2) + CRC (1)
data = i2c.readfrom(SGP30_ADDR, 6)
# CRC check skipped for simplicity
eco2 = (data[0] << 8) | data[1]
tvoc = (data[3] << 8) | data[4]
return tvoc, eco2
while True:
try:
tvoc, eco2 = read_sgp30()
lcd.clear()
lcd.print('TVOC: %d ppb' % tvoc, 10, 20)
lcd.print('eCO2: %d ppm' % eco2, 10, 60)
except Exception as e:
lcd.print('Error: %s' % e, 10, 20)
time.sleep(2)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。