Using the Thermal Unit (MLX90640) ・ 使用 Thermal Unit (MLX90640)
M5StackのThermal Unit (MLX90640)をコントローラーに接続する最小構成。配線とBOMつき。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| Thermal Unit (MLX90640) | unit | grove_i2c | official page — $65 |
M5Stack Core2とThermal Unit(MLX90640)で作る、非接触温度測定装置です。32×24ピクセルの赤外線サーモグラフィ画像をCore2の画面に表示します。I2C接続で簡単に配線でき、温度分布を可視化できます。
# M5Stack Core2 + Thermal Unit (MLX90640)
# Wiring: Thermal Unit -> Core2 red Port.A (I2C)
import time
from machine import Pin, I2C
from m5stack import lcd
from m5ui import setScreenColor
import struct
# I2C setup on Port.A (Core2: sda=21, scl=22)
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
MLX90640_ADDR = 0x33
# Initialize MLX90640
import mlx90640 # requires mlx90640.py driver (included in UIFlow2)
mlx = mlx90640.MLX90640(i2c)
mlx.refresh_rate = mlx90640.RefreshRate.REFRESH_2_HZ
# Color mapping helper
def map_color(temp, t_min, t_max):
# Map temperature to RGB (blue -> red)
ratio = (temp - t_min) / (t_max - t_min)
ratio = max(0, min(1, ratio))
r = int(ratio * 255)
b = int((1 - ratio) * 255)
g = 0
return (r, g, b)
lcd.clear()
lcd.setColor(0xFFFFFF)
lcd.print("Thermal Unit", 10, 10)
while True:
try:
frame = mlx.get_frame() # returns list of 768 temperatures (32x24)
t_min = min(frame)
t_max = max(frame)
# Draw 32x24 pixels scaled to screen (320x240 -> each pixel 10x10)
for y in range(24):
for x in range(32):
temp = frame[y * 32 + x]
r, g, b = map_color(temp, t_min, t_max)
color = (r << 16) | (g << 8) | b
lcd.fillRect(x * 10, y * 10 + 30, 10, 10, color)
time.sleep(0.5)
except Exception as e:
lcd.clear()
lcd.print("Error: " + str(e), 10, 10)
time.sleep(2)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。