아두이노
아두이노 Serial MP3 모듈 -#1
오징어땅콩2
2020. 2. 6. 23:16
반응형
아두이노 하다가 이론 공부만 한것 같아서, 간단하게 집에 있는 모듈을 찾다 보니,
MP3 모듈이 두개 있다.
한개는 시리얼 방식이고 한개는 I2C 방식 같다.
물론 나도 아직 연결을 해보지는 않았다.
조금씩 공부하기로 하자.
아무래도 시리얼 방식이 연결할것이 많이 없어서 만만해 보인다.
딱히 어려운것은 없으니 따라서 해보자.
그리고 어떻게 아두이노 모듈을 공부하는지 방법도 중간 중간 기술 할까 한다.
1. 일단은 구글에서 Serial MP3 Player로 검색하자.
아래 주소로 쓸만한 내용과 소스코드가 있다.
https://www.hackster.io/javier-munoz-saez/arduino-mp3-player-catalex-2effef
나도 처음이나 그냥 읽어 보자.
그리고 소스코드를 카피해서 아두이노에 업로드 하자. 시키는 데로 하면 잘된다.
여기서 주의 할 것은
1. 시리얼 통신 속도를 9600으로 해야 한다는것, 115200으로 하니 안된다.
2. SD카드의 포멧을 fat32로 해야 한다는것 fat16은 사용하는 사람 없을것 같고.
3. mp3 파일의 이름을 001xxx.mp3, 0002xxx.mp3 처럼 0001 로 시작해야 한다.
그 이외에는 딱히 어려운것이 없다.
다시 이야기 하지만 이것을 작성하는 시점에 나도 처음 해보는것이다.
//code rearranged by Javier Muñoz 10/11/2016 ask me at javimusama@hotmail.com
#include <SoftwareSerial.h>
#define ARDUINO_RX 2//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 3//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
////////////////////////////////////////////////////////////////////////////////////
//all the commands needed in the datasheet(http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf)
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
//0X7E FF 06 command 00 00 00 EF;(if command =01 next song order)
#define NEXT_SONG 0X01
#define PREV_SONG 0X02
#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)
#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed 0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
#define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B
#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED
#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3
#define STOP_PLAY 0X16
#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)
#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close
#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output
////////////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);//Start our Serial coms for serial monitor in our pc
mySerial.begin(9600);//Start our Serial coms for THE MP3
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
delay(200);//wait for 200ms
}
void loop()
{
sendCommand(CMD_PLAY_WITHVOLUME, 0X0F02);//play the first song with volume 15 class
delay(1000000);//the programm will send the play option each 100 seconds to the catalex chip
}
void sendCommand(int8_t command, int16_t dat)
{
delay(20);
Send_buf[0] = 0x7e; //starting byte
Send_buf[1] = 0xff; //version
Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
Send_buf[3] = command; //
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
Send_buf[5] = (int8_t)(dat >> 8);//datah
Send_buf[6] = (int8_t)(dat); //datal
Send_buf[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)//
{
mySerial.write(Send_buf[i]) ;//send bit to serial mp3
Serial.print(Send_buf[i],HEX);//send bit to serial monitor in pc
}
Serial.println();
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|