공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
저항 불필요. ESP32는 3.3V로 동작합니다 — 미니 MP3 플레이어의 UART가 기대하는 전압과 동일합니다.
미니 MP3 플레이어 모듈
DIYables 미니 MP3 플레이어는 YX5200-24SS 칩을 기반으로 한 소형 보드입니다. 마이크로 SD 카드에서 MP3 파일을 디코딩하며, 내장 3W 앰프를 통해 스피커를 직접 구동할 수 있습니다. 또는 더 큰 출력을 위해 DAC 핀을 외부 앰프에 연결할 수 있습니다.
모든 것은 9600 보드의 시리얼 명령으로 제어됩니다:
전송: 재생, 일시정지, 재개, 중지, 다음, 이전
볼륨: 31단계 (0–30)
이퀄라이저: 일반, 팝, 록, 재즈, 클래식, 베이스
반복: 단일 트랙 반복, 폴더 반복, 전체 트랙 반복, 랜덤 셔플
폴더: 카드의 번호가 매겨진 디렉토리에서 재생
광고: 재생을 일시 중단 후 계속
쿼리: 트랙 번호, 볼륨, 재생 상태, 트랙 수 읽기
핀 설명
핀
용도
VCC
3.2V~5.0V 전원 입력
GND
접지
RX
시리얼 데이터 입력 (ESP32 TX 핀에 연결)
TX
시리얼 데이터 출력 (ESP32 RX 핀에 연결)
SPK_1
스피커 + (내장 앰프, 최대 3W)
SPK_2
스피커 -
DAC_R
오른쪽 채널 라인 출력
DAC_L
왼쪽 채널 라인 출력
BUSY
LOW = 재생 중, HIGH = 중지됨
IO_1
짧게 누르기 → 이전 트랙; 길게 누르기 → 볼륨 감소
IO_2
짧게 누르기 → 다음 트랙; 길게 누르기 → 볼륨 증가
배선
ESP32는 3.3V 로직을 기본으로 사용하므로 시리얼 라인을 직접 연결합니다 — 레벨 변환이나 저항이 필요 없습니다.
대부분의 ESP32 DevKit 보드에서 기본으로 사용 가능한 Serial2를 권장합니다:
/* * DIYables Mini Mp3 Player - Play One Track * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Plays track 001 once, then stops. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;voidsetup(){Serial.begin(9600);Serial2.begin(9600); mp3.begin(Serial2);delay(1000); // Wait for the module to initialize mp3.setVolume(25); // Set volume (0 to 30)Serial.println("Playing track 1..."); mp3.play(1); // Play track 001.mp3}voidloop(){// Nothing to do here}
사용해보기
SD 카드를 로드하고, 모듈을 연결하고, USB로 ESP32를 연결합니다.
IDE에서 ESP32 보드를 선택하고 업로드합니다.
재생 제어
메서드
동작
코드 예시
play(n)
트랙 n 재생
mp3.play(1)
playNext()
다음 트랙으로 이동
mp3.playNext()
playPrevious()
이전 트랙으로 이동
mp3.playPrevious()
pause()
재생 일시 정지
mp3.pause()
resume()
중단된 위치에서 재개
mp3.resume()
stop()
재생 완전히 종료
mp3.stop()
ESP32 코드 — 다중 트랙
/* * DIYables Mini Mp3 Player - Play Multiple Tracks * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Plays tracks one after another with a delay between them. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, 003.mp3 */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;int currentTrack = 1;int totalTracks = 3; // Change this to match your SD cardunsignedlong lastTrackTime = 0;unsignedlong trackDuration = 5000; // Wait 5 seconds between tracks (adjust as needed)voidsetup(){Serial.begin(9600);Serial2.begin(9600); mp3.begin(Serial2);delay(1000); mp3.setVolume(20);Serial.println("Playing track 1..."); mp3.play(currentTrack); lastTrackTime = millis();}voidloop(){// After trackDuration, play the next trackif (millis() - lastTrackTime >= trackDuration) { currentTrack++;if (currentTrack > totalTracks) currentTrack = 1; // Loop back to first trackSerial.print("Playing track ");Serial.println(currentTrack); mp3.play(currentTrack); lastTrackTime = millis(); }}
ESP32 코드 — 볼륨 버튼
/* * DIYables Mini Mp3 Player - Volume Control * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Use two buttons to increase/decrease the volume. * Press button on pin GPIO1 to volume up, pin GPIO3 to volume down. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button UP -> Pin GPIO1 (other leg to GND) * Button DOWN -> Pin GPIO3 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;constint BUTTON_VOL_UP = 1;constint BUTTON_VOL_DOWN = 3;int volume = 15; // Start at half volumevoidsetup(){Serial.begin(9600);Serial2.begin(9600);pinMode(BUTTON_VOL_UP, INPUT_PULLUP);pinMode(BUTTON_VOL_DOWN, INPUT_PULLUP); mp3.begin(Serial2);delay(1000); mp3.setVolume(volume); mp3.loopTrack(1); // Play track 1 on repeatSerial.print("Volume: ");Serial.println(volume);}voidloop(){// Volume Up button (pressed = LOW because of INPUT_PULLUP)if (digitalRead(BUTTON_VOL_UP) == LOW) {if (volume < 30) { volume++; mp3.setVolume(volume);Serial.print("Volume: ");Serial.println(volume); }delay(200); // Simple debounce }// Volume Down buttonif (digitalRead(BUTTON_VOL_DOWN) == LOW) {if (volume > 0) { volume--; mp3.setVolume(volume);Serial.print("Volume: ");Serial.println(volume); }delay(200); // Simple debounce }}
볼륨 API
메서드
동작
예시
setVolume(v)
v 레벨로 점프
mp3.setVolume(20)
volumeUp()
1 증가
mp3.volumeUp()
volumeDown()
1 감소
mp3.volumeDown()
getVolume()
현재 레벨 읽기
mp3.getVolume()
ESP32 코드 — 다음/이전
/* * DIYables Mini Mp3 Player - Next/Previous with Buttons * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Use two buttons to play next/previous tracks. * Displays the current track number on the Serial Monitor. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button NEXT -> Pin GPIO1 (other leg to GND) * Button PREV -> Pin GPIO3 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;constint BUTTON_NEXT = 1;constint BUTTON_PREV = 3;voidsetup(){Serial.begin(9600);Serial2.begin(9600);pinMode(BUTTON_NEXT, INPUT_PULLUP);pinMode(BUTTON_PREV, INPUT_PULLUP); mp3.begin(Serial2);delay(1000); mp3.setVolume(20); mp3.play(1); // Start with track 1Serial.println("Press NEXT or PREV button to change track");}voidloop(){if (digitalRead(BUTTON_NEXT) == LOW) {Serial.println("Next track"); mp3.playNext();delay(300); // Simple debounce }if (digitalRead(BUTTON_PREV) == LOW) {Serial.println("Previous track"); mp3.playPrevious();delay(300); // Simple debounce }}
ESP32 코드 — 일시정지/재개
/* * DIYables Mini Mp3 Player - Pause and Resume * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Demonstrates pausing and resuming playback using a single button. * Press the button to toggle between pause and resume. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * Button -> Pin GPIO1 (other leg to GND) * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;constint BUTTON_PIN = 1;bool paused = false;voidsetup(){Serial.begin(9600);Serial2.begin(9600);pinMode(BUTTON_PIN, INPUT_PULLUP); mp3.begin(Serial2);delay(1000); mp3.setVolume(20); mp3.play(1);Serial.println("Playing. Press button to pause/resume.");}voidloop(){if (digitalRead(BUTTON_PIN) == LOW) {if (paused) { mp3.resume();Serial.println("Resumed"); }else { mp3.pause();Serial.println("Paused"); } paused = !paused;delay(300); // Simple debounce }}
ESP32 코드 — 트랙 반복
/* * DIYables Mini Mp3 Player - Loop Track * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Loops (repeats) a track continuously with EQ setting. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card file structure: * /001.mp3 * /002.mp3 * ... */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;voidsetup(){Serial.begin(9600);Serial2.begin(9600); mp3.begin(Serial2);delay(1000); // Wait for the module to initialize mp3.setVolume(25); // Volume: 0 to 30 mp3.setEQ(DIYables_MiniMp3::EQ_NORMAL);Serial.println("Playing track 1 on loop..."); mp3.loopTrack(1);}voidloop(){// Your code here}
반복 및 셔플
메서드
동작
예시
loopTrack(n)
트랙 n을 무한 반복
mp3.loopTrack(1)
loopFolder(f)
폴더 f의 모든 트랙 반복
mp3.loopFolder(1)
loopAll()
모든 트랙 반복
mp3.loopAll()
stopLoop()
활성 반복 취소
mp3.stopLoop()
shuffle()
재생 무작위화
mp3.shuffle()
ESP32 코드 — 폴더 재생
/* * DIYables Mini Mp3 Player - Play from Folder * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Plays tracks from specific folders on the SD card. * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card file structure: * /01/001.mp3 <- playFolder(1, 1) * /01/002.mp3 <- playFolder(1, 2) * /02/001.mp3 <- playFolder(2, 1) * /02/002.mp3 <- playFolder(2, 2) * * IMPORTANT: * - Numbering starts from 1, NOT 0 * - Folder names must be 2-digit zero-padded (01-99) * - Track names must be 3-digit zero-padded (001-255) * - Format SD card as FAT32, then copy files one by one in order * - Track order is determined by the order files were copied, * NOT by filename. So copy them in the correct sequence. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;voidsetup(){Serial.begin(9600);Serial2.begin(9600); mp3.begin(Serial2);delay(1000); mp3.setVolume(20);// Play track 1 from folder 01Serial.println("Playing folder 01, track 001..."); mp3.playFolder(1, 1);delay(5000);// Play track 2 from folder 01Serial.println("Playing folder 01, track 002..."); mp3.playFolder(1, 2);delay(5000);// Play track 1 from folder 02Serial.println("Playing folder 02, track 001..."); mp3.playFolder(2, 1);}voidloop(){// Nothing to do here}
폴더 API
메서드
설명
예시
playFolder(f, t)
폴더 f에서 트랙 t 재생
mp3.playFolder(1, 1)
playLargeFolder(f, t)
대용량 폴더 (15개 폴더, 3000개 트랙)
mp3.playLargeFolder(1, 2000)
playFromMP3Folder(t)
/mp3 폴더에서 재생
mp3.playFromMP3Folder(1)
ESP32 코드 — 시리얼 모니터 제어
/* * DIYables Mini Mp3 Player - Serial Command Control * * Product: DIYables Mini Mp3 Player Module * https://diyables.io/products/mini-mp3-player-module * * Control the Mp3 player by typing commands in the Serial Monitor. * Great for testing all functions without extra hardware. * * Commands (type in Serial Monitor, then press Enter): * 1-9 Play track 1 to 9 * + Volume up * - Volume down * p Pause * r Resume * s Stop * n Next track * b Previous track (back) * ? Show current status * * Wiring (Arduino Uno): * Mini Mp3 RX -> ESP32 pin GPIO 17 (TX2) * Mini Mp3 TX -> ESP32 pin GPIO 16 (RX2) * Mini Mp3 VCC -> 5V * Mini Mp3 GND -> GND * Speaker connected to SPK_1 and SPK_2 pins * * SD Card: Put mp3 files in root, named 001.mp3, 002.mp3, etc. */#include <DIYables_MiniMp3.h>DIYables_MiniMp3 mp3;voidsetup(){Serial.begin(9600);Serial2.begin(9600); mp3.begin(Serial2);delay(1000); mp3.setVolume(20);Serial.println("=== DIYables Mini Mp3 Player ===");Serial.println("Commands:");Serial.println(" 1-9 Play track number");Serial.println(" + Volume up");Serial.println(" - Volume down");Serial.println(" p Pause");Serial.println(" r Resume");Serial.println(" s Stop");Serial.println(" n Next track");Serial.println(" b Previous track");Serial.println(" ? Show status");Serial.println("================================");}voidloop(){if (Serial.available()) {char cmd = Serial.read();switch (cmd) {case'1': case'2': case'3':case'4': case'5': case'6':case'7': case'8': case'9':Serial.print("Playing track ");Serial.println(cmd - '0'); mp3.play(cmd - '0');break;case'+':Serial.println("Volume up"); mp3.volumeUp();break;case'-':Serial.println("Volume down"); mp3.volumeDown();break;case'p':Serial.println("Paused"); mp3.pause();break;case'r':Serial.println("Resumed"); mp3.resume();break;case's':Serial.println("Stopped"); mp3.stop();break;case'n':Serial.println("Next track"); mp3.playNext();break;case'b':Serial.println("Previous track"); mp3.playPrevious();break;case'?': {Serial.println("--- Status ---");int16_t vol = mp3.getVolume();Serial.print("Volume: ");Serial.println(vol);int16_t track = mp3.getCurrentTrack();Serial.print("Current track: ");Serial.println(track);bool playing = mp3.isPlaying();Serial.print("Playing: ");Serial.println(playing ? "Yes" : "No");int16_t total = mp3.getTrackCount();Serial.print("Total tracks: ");Serial.println(total);Serial.println("--------------");break; }default:break; } }}
명령
효과
1–9
트랙 재생
+ / −
볼륨
p / r / s
일시정지 / 재개 / 중지
n / b
다음 / 이전
?
상태
이퀄라이저 옵션
상수
ID
특성
DIYables_MiniMp3::EQ_NORMAL
0
중립
DIYables_MiniMp3::EQ_POP
1
밝음
DIYables_MiniMp3::EQ_ROCK
2
힘참
DIYables_MiniMp3::EQ_JAZZ
3
따뜻함
DIYables_MiniMp3::EQ_CLASSIC
4
균형
DIYables_MiniMp3::EQ_BASS
5
저음
mp3.setEQ(DIYables_MiniMp3::EQ_BASS);
모듈 상태 확인
이 함수들은 모듈의 응답을 기다리는 동안 최대 100ms 동안 블록됩니다. 응답이 없으면 -1을 반환합니다.