霜注意通知システム

ENV IIIで気温を監視し、低下時に霜注意を通知する。

By Ryuichiro Toyoshi

Parts

How to build

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.

  1. Gather your parts — You need: the M5Stack Core2, the ENV III unit, one Grove cable (usually included with the unit), and a USB-C cable to connect the Core2 to your computer.
  2. Connect the ENV III to the Core2 — The ENV III uses I2C communication. Plug one end of the Grove cable into the ENV III and the other end into the Core2's red Port.A (the I2C port). The connectors only fit one way, so don't force them.
  3. Connect to your computer and flash MicroPython — Connect the Core2 to your computer with the USB-C cable. Using a tool like UIFlow or Thonny, ensure MicroPython firmware is on the Core2, then copy the sketch below onto the device and run it.
  4. Verify the readings — After running the code, the Core2 screen should display temperature, humidity, and pressure values. If you see 'Sensor not found', check the wiring and I2C addresses.

Sample code (micropython)

# 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)

Tips

Likes: 0 · Views: 0