Using the HMI Module ・ 使用 HMI Module
M5StackのHMI Moduleをコントローラーに接続する最小構成。配線とBOMつき。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack CoreS3 | Controller | grove_i2c, grove_analog, grove_uart, mbus, usb_c, sdcard | official page — $59.9 |
| HMI Module | module | i2c, mbus, other:PORT.B, other:PORT.C | official page — $9.95 |
M5Stack CoreS3とHMI ModuleをM-Busで接続し、ロータリーエンコーダーとボタンで操作できるヒューマンマシンインターフェースを構築します。HMI ModuleはCoreS3の底面に重ねて固定するだけで配線不要。I2C通信で制御します。
# M5Stack CoreS3 + HMI Module (via M-Bus, I2C)
# Wiring: HMI Module stacked on CoreS3 via M-Bus (I2C)
import time
from machine import Pin, I2C
from m5stack import lcd
# HMI Module I2C address (default 0x24)
HMI_ADDR = 0x24
# Initialize I2C on CoreS3 (Port.A is I2C, but M-Bus uses internal I2C)
i2c = I2C(0, scl=Pin(1), sda=Pin(2), freq=400000) # CoreS3 I2C pins
# Helper functions to read encoder and buttons
def read_encoder():
data = i2c.readfrom_mem(HMI_ADDR, 0x00, 2) # read 2 bytes from register 0x00
value = (data[0] << 8) | data[1]
return value
def read_buttons():
data = i2c.readfrom_mem(HMI_ADDR, 0x02, 1) # read 1 byte from register 0x02
return data[0] # bit0: button1, bit1: button2
def set_led(led1, led2):
# led1, led2: 0=off, 1=on
val = (led2 << 1) | led1
i2c.writeto_mem(HMI_ADDR, 0x03, bytes([val]))
while True:
encoder = read_encoder()
buttons = read_buttons()
btn1 = (buttons & 0x01) == 0 # active low
btn2 = (buttons & 0x02) == 0
lcd.clear()
lcd.print('Encoder: %d' % encoder, 10, 20)
lcd.print('Btn1: %d Btn2: %d' % (btn1, btn2), 10, 50)
# Turn on LED when button pressed
set_led(btn1, btn2)
time.sleep(0.1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。