Clock & weather display ・ 时钟天气显示
CoreS3 で時計と天気を表示するデスク端末。ENV III で温湿度・気圧を計測し、OLED に補足情報を表示。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack CoreS3 | Controller with screen | grove_i2c, grove_analog, grove_uart, mbus, usb_c, sdcard | official page — $59.9 |
| Unit PaHub2 | I2C hub | grove_i2c | official page — $7.95 |
| Unit ENV III | Temp / humidity / pressure | grove_i2c | official page — $5.95 |
| Unit OLED | OLED display | grove_i2c | official page — $10.95 |
M5Stack CoreS3とUnit PaHub2、ENV III、OLEDを使って、時計と天気を表示するデスクターミナルを作ります。ENV IIIが温度・湿度・気圧を測定し、OLEDに追加情報を表示します。PaHub2でI2Cユニットをまとめて接続します。
# M5Stack CoreS3 + PaHub2 + ENV III + OLED
# Wiring:
# CoreS3 Port.A (red I2C) -> PaHub2
# PaHub2 ch0 -> ENV III
# PaHub2 ch1 -> OLED
import time
from machine import Pin, I2C
from m5stack import lcd
import ntptime
import network
# I2C setup for CoreS3 (Port.A: sda=12, scl=11)
i2c = I2C(0, sda=Pin(12), scl=Pin(11), freq=400000)
# TCA9548A address (PaHub2)
TCA_ADDR = 0x70
def select_channel(ch):
i2c.writeto(TCA_ADDR, bytes([1 << ch]))
# ENV III: SHT30 (0x44), QMP6988 (0x70)
# OLED: SH1107 (0x3C)
# Initialize OLED (SH1107) via channel 1
select_channel(1)
import sh1107
display = sh1107.SH1107_I2C(128, 64, i2c)
# Connect to WiFi for NTP (optional, for time sync)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('your_ssid', 'your_password')
while not wlan.isconnected():
time.sleep(1)
ntptime.settime()
# Helper to read SHT30 (temperature, humidity)
def read_sht30():
select_channel(0)
i2c.writeto(0x44, b'\x2C\x06')
time.sleep_ms(50)
data = i2c.readfrom(0x44, 6)
temp = -45 + 175 * ((data[0] << 8 | data[1]) / 65535.0)
hum = 100 * ((data[3] << 8 | data[4]) / 65535.0)
return temp, hum
# Helper to read QMP6988 (pressure)
def read_qmp6988():
select_channel(0)
# Simplified: read raw pressure (requires calibration in full code)
i2c.writeto(0x70, b'\xF4\x34')
time.sleep_ms(10)
data = i2c.readfrom_mem(0x70, 0xF7, 3)
raw = (data[0] << 16 | data[1] << 8 | data[2]) & 0xFFFFFF
pressure = raw / 256.0 # approximate, real conversion needs calibration
return pressure
while True:
temp, hum = read_sht30()
press = read_qmp6988()
# Get local time (UTC+9 for Japan)
import machine
rtc = machine.RTC()
now = rtc.datetime()
# Format time string
time_str = "%04d-%02d-%02d %02d:%02d:%02d" % (now[0], now[1], now[2], now[4], now[5], now[6])
# Display on CoreS3
lcd.clear()
lcd.print(time_str, 10, 10)
lcd.print("Temp: %.1f C" % temp, 10, 40)
lcd.print("Hum: %.1f %%" % hum, 10, 70)
lcd.print("Press: %.1f hPa" % press, 10, 100)
# Display on OLED
display.fill(0)
display.text(time_str, 0, 0, 1)
display.text("Temp: %.1f C" % temp, 0, 16, 1)
display.text("Hum: %.1f %%" % hum, 0, 32, 1)
display.text("Press: %.1f hPa" % press, 0, 48, 1)
display.show()
time.sleep(10)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。