It took me long time (few hours a day for few days) to find out how this mp3 works. Let me tell you what really happened. I just wanted to play some sound tracks on command in Arduino, so I thought let me buy a serial mp3 player and put all the sound tracks in a micro SD card and then play them on command which ever I want.
That's why I bought the mp3 player above, but unfortunately they didn't send an user manual with it. So I started searching on the net as usual, but couldn't find it, after looking for long time finally I've found one, but the manual was so difficult to understand that I thought what's the point making this kind of manual if people can't understand easily.
Then I turned to one of my Arduino expert friend and asked him for help, but he was kind of busy and was not replying my massage for few days. So I thought you know what let me just try myself and experiment with the code, and then let's see what happens. So after working hard I came up with this simple sketch with few useful options.
Let's see some
specification:
What to do?
1. Format your SD card @ Fat16 or Fat32
2. Rename all the sound tracks as
001,
002,
003 and so on. If you want to remember which track is which, then write the name after the numbers, for example
001soundofbird,
002dogbark and so on.
One thing keep in mind that when you write the name, never leave a space between the words, for example
001 sound of bird,
002 dog bark and so on.
3. Copy those sound tracks and paste on the card. Remember not
to make any folder/directory in SD card. Please see my
other post if you want to play songs from other folders.
What does the sketch below can do?
- If you have uploaded the sketch successfully then it will play the first sound track when you first open your serial monitor or press the reset button.
- Play soundtrack on command . That means it will play which ever soundtrack you tell it to play.
- Pause, it can pause the playing soundtrack.
- Play, it will play the soundtrack after pausing.
- Play previous soundtrack.
The sketch
#include <SoftwareSerial.h>
#define ARDUINO_RX 5//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0} ;
#define CMD_SEL_DEV 0X09
#define DEV_TF 0X02
#define CMD_PLAY_W_VOL 0X22
#define CMD_PLAY 0X0D
#define CMD_PAUSE 0X0E
#define CMD_PREVIOUS 0X02
#define CMD_NEXT 0X01
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
delay(200);//wait for 200ms
sendCommand(CMD_PLAY_W_VOL, 0X1E01);//play the first song with volume 30 class
}
String str;
void loop() {
if(Serial.available())
{
str = Serial.readStringUntil('\n');
if(str == "2")
{
sendCommand(CMD_PLAY_W_VOL, 0X1E02);//play the second track with volume 30 class
Serial.println("Second sound track.");
}
if(str == "3")
{
sendCommand(CMD_PLAY_W_VOL, 0X1E03);//play the third track with volume 30 class
Serial.println("Third sound track.");
}
if(str == "4")
{
sendCommand(CMD_PLAY_W_VOL, 0X1E04);//play the forth track with volume 30 class
Serial.println("Forth sound track.");
}
if(str == "ps")
{
sendCommand(CMD_PAUSE, 0X0E);//pause the playing track
Serial.println("Pause");
}
if(str == "pl")
{
sendCommand(CMD_PLAY, 0X0D);//play it again
Serial.println("Play");
}
if(str == "pr")
{
sendCommand(CMD_PREVIOUS, 0X02);//play previous track
Serial.println("Playing previous track.");
}
if(str == "nx")
{
sendCommand(CMD_NEXT, 0X01);//play next track
Serial.println("Playing next track.");
}
}
}
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]) ;
}
} |
What are the commands in this sketch?
- If you send 2, 3 or 4 via the serial monitor then it will play the second sound track, third sound track or forth sound track. What ever number you choose it will play that track and the text will appear on monitor that which track is playing. For example if you send 3 then it will play the 3rd track and you will see "Third sound track." on the serial monitor.
- ps is for pause. If you want to pause any sound track which playing right now, then just send ps and it will pause straight way.
- pl is for play. If you want to play it again after pausing then send pl it will start playing the same track again from where you left from.
- pr is to play the previous track.
- nx is to play next track.
Which Arduino board does it support?
Well, in the manual it says "Compatible with Arduino UNO / Leonardo / Mega2560 / DUE" but I have tried with
Arduino Nano and it's works perfectly, so I hope it will work with other board too.
Places to edit:
- If you don't want to hear the first sound track automatically, when ever you open the serial monitor or press the reset button, then delete this (sendCommand(CMD_PLAY_W_VOL, 0X1E01);//play the first song with volume 30 class) line from the sketch.
- if(str == "2"){sendCommand(CMD_PLAY_W_VOL, 0X1E02);//play the second track with volume 30 classSerial.println("Second sound track.");
}
As you can see number 2 in "
2" which you can change to something else to play second sound track. For example "track_2" or "my_love" in which ever way it will play the same soundtrack and that is soundtrack number two. You can change the serial print "
Second sound track." to what ever you want.
Note: You can do this to other functions too. For example ps, pl, pr, nx and so on.
*
Choosing which sound track to play. For this, simply change the number at the end of this (0X1E
02).
*
Play with volume. Unfortunately I only know two level of volume in this 15 and 30 the code is below.
sendCommand(CMD_PLAY_W_VOL, 0X
0F01);//play the first song with volume 15 class
sendCommand(CMD_PLAY_W_VOL, 0X
1E01);//play the first song with volume 30 class
Can you send commands by using mobile phone?
Of course you can. There is an app called
BlueSerial Beta which is very useful, I use a lot.
That's all for now, if I find out more options I will try to add on and in the meantime you can let me know if you didn't understand anything in this post or if you have found out some new function code. Thanks a lot. :)
You may also like:
catalex mp3 player manual.
serial mp3 player arduino.
catalex serial mp3 player.
arduino serial mp3 player code.
yx5300 arduino.
serial mp3 player v1.0.
serial mp3 player v1.0 arduino.
arduino serial mp3 player.
open smart serial mp3 player.
serial mp3 player.
catalex mp3.
arduino yx5300.
catalex arduino.
yx5300 arduino tutorial.
arduino mp3 player code.
catalex mp3 player.
mp3 player arduino.
arduino mp3 player.
arduino nano mp3 player.
mp3 module arduino code.
mp3 arduino.
serial mp3.
catalex yx5300.
mp3 player arduino nano.
smart mp3.
serial mp3 player catalex.
arduino nano mp3.
catalex.
mp3 serial.
arduino play mp3.
mp3 to arduino code.
yx5300.
arduino songs code.
arduino mp3 code.
mp3 arduino code.
mp3 player code.
arduino uno mp3 player.
mp3 trigger arduino.
arduino mp3 player project.
mp3 player arduino uno.
arduino mp3.
play next track.
serial mp3 download.
smart mp3 player.
arduino play mp3 from sd card.
play mp3 with arduino.
catalex sd card.
mp3 player with arduino.
mp3 player module arduino.
arduino play sound without sd card.
arduino song code.
arduino songs.
arduino play sound file.
mp3 module arduino.
arduino mp3 module.
yx5300 datasheet.
play mp3 on arduino.
serial mp3 song.
my mp3 serial song.
arduino sound player.
yx5300 mp3.
arduino codes for songs.
arduino music player code.
arduino music player without sd card.
play songs on arduino.
dfplayer file names.
yx5300 uart.
mp3 player module for arduino.
catalex sd card module.
arduino nano d1.
amazing mp3 player.
arduino play mp3 file.
arduino play sound on button press.
mp3 player module.
mp3 player for arduino.
arduino play sound from sd card.
mp3 play.
open mp3 player.
arduino usb mp3 player.