Using the Hat DLight ・ 使用 Hat DLight
M5StackのHat DLightをコントローラーに接続する最小構成。配線とBOMつき。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| ATOM Lite | Controller | grove_i2c, i2c, gpio | official page — $7.5 |
| Hat DLight | hat | i2c | official page — $4.5 |
ATOM LiteとHat DLightで作る、かんたんな明るさセンサーです。Hat DLightが周囲の明るさを測り、ATOM Liteがその値を表示します。USB給電だけで動作し、コードを書き込めばすぐに使えます。
# M5Stack ATOM Lite + Hat DLight (BH1750 ambient light sensor)
# Wiring: Hat DLight stacked directly on ATOM Lite (I2C via pins)
# I2C pins: ATOM Lite SDA=26, SCL=32 (default for Grove Port.A)
import time
from machine import Pin, I2C
from neopixel import NeoPixel
# Initialize I2C bus (id=0 for ATOM Lite)
i2c = I2C(0, scl=Pin(32), sda=Pin(26), freq=400000)
# BH1750 I2C address (0x23 when ADDR pin low, 0x5C when high)
# Hat DLight uses address 0x23
BH1750_ADDR = 0x23
# Initialize NeoPixel (built-in RGB LED on ATOM Lite, pin 27, 1 pixel)
np = NeoPixel(Pin(27), 1)
def read_light():
# Send measurement command (continuous high-res mode)
i2c.writeto(BH1750_ADDR, bytes([0x10]))
time.sleep_ms(120) # wait for measurement
data = i2c.readfrom(BH1750_ADDR, 2)
lux = (data[0] << 8) | data[1]
lux = lux / 1.2 # convert to lux (high-res mode factor)
return lux
def set_color(lux):
# Map lux to color: dim -> blue, bright -> red
if lux < 10:
np[0] = (0, 0, 50) # blue
elif lux < 100:
np[0] = (0, 50, 0) # green
else:
np[0] = (50, 0, 0) # red
np.write()
while True:
try:
lux = read_light()
print('Light: {:.1f} lux'.format(lux))
set_color(lux)
except Exception as e:
print('Error:', e)
time.sleep(1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。