Using the Unit AudioPlayer ・ 使用 Unit AudioPlayer
M5StackのUnit AudioPlayerをコントローラーに接続する最小構成。配線とBOMつき。
この構成をエディタで開く・編集する →| 部品 | 役割 | ポート | リンク・価格 |
|---|---|---|---|
| AtomS3 | Controller | grove_i2c, i2c, spi, gpio, usb_c | official page — $15.5 |
| Unit AudioPlayer | unit | grove_uart, sdcard, audio_jack | official page — $3.95 |
AtomS3とUnit AudioPlayerで作る、かんたんな音楽再生装置です。microSDカードに入れたMP3/WAVファイルを、UART経由で制御して再生します。AtomS3の画面をタッチして再生・停止・次の曲などの操作ができます。
# M5Stack AtomS3 + Unit AudioPlayer (UART control)
# Wiring: Unit AudioPlayer -> AtomS3 blue Port.C (UART)
import time
import os
from machine import UART, Pin
from m5stack import lcd, btn
# UART on Port.C: TX=1, RX=2 (AtomS3)
uart = UART(1, baudrate=115200, tx=1, rx=2)
# List MP3/WAV files on SD card (assumes files in root)
files = [f for f in os.listdir('/sd') if f.endswith('.mp3') or f.endswith('.wav')]
files.sort()
if not files:
lcd.print('No audio files found!', 10, 20)
raise SystemExit
current = 0
def play_file(index):
global current
if index >= len(files):
index = 0
elif index < 0:
index = len(files) - 1
current = index
fname = files[current]
lcd.clear()
lcd.print('Play: ' + fname, 10, 20)
# Send play command: CMD_PLAY_WITH_NAME (0x07) + filename + newline
cmd = bytes([0x7E, 0x07, 0x00, 0x00]) + fname.encode() + b'\r\n'
uart.write(cmd)
time.sleep(0.1)
# Start playing first file
play_file(0)
# Button (screen tap) to next track
while True:
if btn.wasPressed():
play_file(current + 1)
time.sleep(0.1)
この作り方はAIが構成から生成したものです(未検証)。通電前に配線とコードをご確認ください。
この構成はAIが実在するM5Stack部品から設計し、ポート互換をサーバで検証したものです。編集・共有できます。
エディタで開く →UnitKit は M5Stack® 製品向けの非公式ツール。作りたいものを書くと、部品リストと配線図が出ます。