TV IR remote ・ 电视红外遥控
M5Stack Core2 と IR Unit を使ってテレビを赤外線リモコンで操作します。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| M5Stack Core2 | Controller | grove_i2c, grove_analog, grove_uart, mbus | official page — $46.9 |
| Unit IR | IR Transceiver | grove_analog, gpio | official page — $3.95 |
M5Stack Core2とIR Unitでテレビのリモコン信号を送受信する装置です。IR Unitが赤外線リモコンの信号を学習し、Core2からその信号を再送信してテレビを操作できます。エアコンやオーディオ機器など、赤外線リモコン対応機器の制御にも応用できます。
# M5Stack Core2 + IR Unit (TV IR Remote Control)
# Wiring: IR Unit -> Core2 black Port.B (analog/IO)
# Uses GPIO pin 26 for IR data (Port.B on Core2)
import time
from machine import Pin
from m5stack import lcd, btnA, btnB, btnC
# IR Unit connected to Port.B (GPIO 26)
ir_pin = Pin(26, Pin.IN)
# Simple IR signal storage (raw timing data)
received_signal = []
# IR receiver parameters
IR_TIMEOUT = 100 # ms
def read_ir_signal():
"""Read IR signal and return list of pulse durations in microseconds"""
pulses = []
# Wait for first edge
start = time.ticks_us()
while ir_pin.value() == 1:
if time.ticks_diff(time.ticks_us(), start) > 1000000: # 1s timeout
return None
# Record edges
last_edge = time.ticks_us()
while True:
while ir_pin.value() == 0:
if time.ticks_diff(time.ticks_us(), last_edge) > 100000:
return pulses
pulses.append(time.ticks_diff(time.ticks_us(), last_edge))
last_edge = time.ticks_us()
while ir_pin.value() == 1:
if time.ticks_diff(time.ticks_us(), last_edge) > 100000:
return pulses
pulses.append(time.ticks_diff(time.ticks_us(), last_edge))
last_edge = time.ticks_us()
def send_ir_signal(pulses):
"""Send IR signal using GPIO 26 (output) with carrier 38kHz"""
ir_out = Pin(26, Pin.OUT)
for i, duration in enumerate(pulses):
if i % 2 == 0: # mark (carrier on)
# Generate 38kHz carrier for the duration
cycles = int(duration / 26.3) # 26.3us per cycle at 38kHz
for _ in range(cycles):
ir_out.on()
time.sleep_us(13)
ir_out.off()
time.sleep_us(13)
else: # space (carrier off)
time.sleep_us(duration)
ir_out.off()
# Main loop
lcd.clear()
lcd.print("IR Remote Control", 10, 20)
lcd.print("Press A to learn", 10, 60)
lcd.print("Press B to send", 10, 100)
while True:
if btnA.wasPressed():
lcd.clear()
lcd.print("Learning...", 10, 20)
lcd.print("Point remote at IR", 10, 60)
lcd.print("and press a button", 10, 100)
signal = read_ir_signal()
if signal:
received_signal = signal
lcd.clear()
lcd.print("Signal learned!", 10, 20)
lcd.print("Pulses: %d" % len(signal), 10, 60)
else:
lcd.clear()
lcd.print("No signal received", 10, 20)
if btnB.wasPressed():
if received_signal:
lcd.clear()
lcd.print("Sending...", 10, 20)
send_ir_signal(received_signal)
lcd.print("Sent!", 10, 60)
else:
lcd.clear()
lcd.print("No signal stored", 10, 20)
time.sleep(0.1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。