Sensor dashboard display ・ 传感器仪表盘
CoreS3の画面に温度・湿度・CO2・照度をI2Cハブ経由で表示。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack CoreS3 | Controller with screen | grove_i2c, grove_analog, grove_uart, mbus, usb_c, sdcard | official page — $59.9 |
| Unit PaHub2 | I2C hub (1→6) | grove_i2c | official page — $7.95 |
| Unit ENV III | Temp / humidity / pressure | grove_i2c | official page — $5.95 |
| Unit CO2 | CO2 sensor | grove_i2c | official page — $33.9 |
| Unit DLight | Ambient light sensor | grove_i2c | official page — $5.5 |
M5Stack CoreS3とPaHub2 I2Cハブを使って、温度・湿度・CO2・照度を同時に計測・表示するマルチセンサーダッシュボードです。CoreS3の画面に各センサーの値をリアルタイムで表示します。
# M5Stack CoreS3 + PaHub2 + ENV III + CO2 + DLight
# Wiring: CoreS3 Port.A -> PaHub2 IN; PaHub2 OUT1 -> ENV III; OUT2 -> CO2; OUT3 -> DLight
import time
from machine import Pin, I2C
from m5stack import lcd
# Initialize I2C on CoreS3 Port.A (pins 2 and 1)
i2c = I2C(0, scl=Pin(2), sda=Pin(1), freq=100000)
# TCA9548A address (PaHub2)
TCA_ADDR = 0x70
def select_channel(channel):
"""Select a channel on the TCA9548A multiplexer."""
if 0 <= channel <= 7:
i2c.writeto(TCA_ADDR, bytes([1 << channel]))
def read_sht30():
"""Read temperature and humidity from SHT30 (addr 0x44)."""
try:
i2c.writeto(0x44, b'\x2C\x06')
time.sleep(0.5)
data = i2c.readfrom(0x44, 6)
if len(data) == 6:
temp_raw = (data[0] << 8) | data[1]
hum_raw = (data[3] << 8) | data[4]
temp = -45 + 175 * (temp_raw / 65535)
hum = 100 * (hum_raw / 65535)
return temp, hum
except:
pass
return None, None
def read_scd40():
"""Read CO2, temperature, humidity from SCD40 (addr 0x62)."""
try:
# Send read command
i2c.writeto(0x62, b'\xEC\x05')
time.sleep(0.5)
data = i2c.readfrom(0x62, 9)
if len(data) == 9:
co2 = (data[0] << 8) | data[1]
temp_raw = (data[3] << 8) | data[4]
hum_raw = (data[6] << 8) | data[7]
temp = -45 + 175 * (temp_raw / 65535)
hum = 100 * (hum_raw / 65535)
return co2, temp, hum
except:
pass
return None, None, None
def read_bh1750():
"""Read illuminance from BH1750 (addr 0x23)."""
try:
# Set measurement mode (continuous high-res mode)
i2c.writeto(0x23, b'\x10')
time.sleep(0.2)
data = i2c.readfrom(0x23, 2)
if len(data) == 2:
lux = (data[0] << 8) | data[1]
lux /= 1.2 # scale factor for high-res mode
return lux
except:
pass
return None
while True:
lcd.clear()
lcd.setCursor(0, 0)
lcd.print('Multi-Sensor Dashboard', 0, 0)
# Read ENV III (SHT30) on channel 1
select_channel(1)
temp, hum = read_sht30()
if temp is not None:
lcd.print('ENV III: %.1f C, %.1f%%' % (temp, hum), 0, 30)
else:
lcd.print('ENV III: error', 0, 30)
# Read CO2 (SCD40) on channel 2
select_channel(2)
co2, temp2, hum2 = read_scd40()
if co2 is not None:
lcd.print('CO2: %d ppm' % co2, 0, 60)
else:
lcd.print('CO2: error', 0, 60)
# Read DLight (BH1750) on channel 3
select_channel(3)
lux = read_bh1750()
if lux is not None:
lcd.print('Light: %.0f lux' % lux, 0, 90)
else:
lcd.print('Light: error', 0, 90)
time.sleep(2)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。