ENV IIIで気温を監視し、低下時に霜注意を通知する。
By Ryuichiro Toyoshi
Build a simple environmental monitor with M5Stack Core2 and the ENV III unit. The ENV III measures temperature, humidity, and barometric pressure. The Core2 reads these values over I2C and displays them on the screen. No extra wiring is needed beyond a single Grove cable.
# M5Stack Core2 + ENV III (temperature, humidity, pressure)
# Wiring: ENV III -> Core2 red Port.A (I2C)
import time
from m5stack import lcd
from machine import Pin, I2C
# I2C on Port.A: scl=22, sda=21
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
# SHT30 address: 0x44, QMP6988 address: 0x70
SHT30_ADDR = 0x44
QMP6988_ADDR = 0x70
def read_sht30():
# Send measurement command (0x2C, 0x06) for high repeatability
i2c.writeto(SHT30_ADDR, bytes([0x2C, 0x06]))
time.sleep_ms(20)
data = i2c.readfrom(SHT30_ADDR, 6)
# Convert raw data
temp_raw = (data[0] << 8) | data[1]
hum_raw = (data[3] << 8) | data[4]
temperature = -45.0 + 175.0 * temp_raw / 65535.0
humidity = 100.0 * hum_raw / 65535.0
return temperature, humidity
def read_qmp6988():
# Read pressure from QMP6988 (simplified, requires calibration in practice)
# For demo, read temperature and pressure registers
# This is a placeholder; real code would use calibration coefficients
i2c.writeto(QMP6988_ADDR, bytes([0x07])) # pressure MSB register
data = i2c.readfrom(QMP6988_ADDR, 3)
pressure_raw = (data[0] << 16) | (data[1] << 8) | data[2]
pressure = pressure_raw / 100.0 # approximate, not calibrated
return pressure
while True:
try:
temp, hum = read_sht30()
press = read_qmp6988()
lcd.clear()
lcd.print('Temp: {:.1f} C'.format(temp), 10, 20)
lcd.print('Hum: {:.1f} %'.format(hum), 10, 60)
lcd.print('Press: {:.1f} hPa'.format(press), 10, 100)
except Exception as e:
lcd.clear()
lcd.print('Sensor error', 10, 20)
time.sleep(2)
Likes: 0 · Views: 0