Catalex mp3 player code (Arduino)


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 bird002 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 next soundtrack.
  • 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 (0X1E02).

* 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, 0X0F01);//play the first song with volume 15 class
sendCommand(CMD_PLAY_W_VOL, 0X1E01);//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.

27 comments:

  1. Thank you for the sketch. The sketch works well on both the Arduino UNO and the WeMos D1 R2 as long as you change the RX=5 to RX=D5 and TX=6 to TX=D6, but how can you list file names from the Catalex SD MP3 serial card?

    ReplyDelete
  2. A SD fileInfo/file dump/directory of mp3 files listed on the SD card embedded in the Catalex Serial MP3 Player. Just like to do a folder directory or even a root directory. Example dir c:\*.mp3.
    I've looked everywhere for this information and either I'm overlooking something or there doesn't seem to be any information as to how to list the files(e.g. song.mp3) on the SD card.

    ReplyDelete
  3. Been there, did that, but thank you again, especially for responding so quickly! If I locate a solution, I'll post it since there doesn't seem to be an answer even when using google's search.

    ReplyDelete
  4. Thank you very much. I am sure this has saved me many hours of head banging.
    Everything worked exactly as described.

    ReplyDelete
  5. I'm still interested and would love to see what you come up with. As far as playing complete songs(*.mp3 files), I've had no issues, however, back to the original question; it amazes me that every programmer using either the Catalex or a variation like the DFPlayer serial audio players hasn't asked about listing wav and/or mp3 files in each directory. Renaming file names to 001xxxxSoundofSilence.mp3 002xxxxblablabla.mp3 from their original names, seems like a poor method. Also reorganizing the files or file table of contents also seems primitive at best. There just doesn't seem to be a command like dir or list for these. Odd.

    ReplyDelete
  6. Abul, sorry but my question wasn't how to play mp3 files because, as mentioned above, I've done all that. It was how to list the files that are located on the Catalex or DFPlayer SD serial mp3 player?

    ReplyDelete
  7. Abul, your sketches works great and both are very clear in what they do. I'll try my question one more time, then not bother you with this again. Let's say I have qty 2 mp3 files on the Catalex or DFPlay SD card, one is named 001.mp3 and the other is 002.mp3. All I want is when I start either the ESP8266 or Arduino, that is attached to either mp3 play, is list the files that are on the SD memory card. A simple directory listing of each file name (001.mp3, 002.mp3).

    ReplyDelete
    Replies
    1. A sketch or command that list the files on the serial MP3 player.

      Delete
  8. Abul, no problem, I haven't found the solution anywhere, including Youtube Google etc.

    All I really wanted a sketch to do is list the MP3 files that are on the serial MP3 player, like Serial.println(MP3[1]); etc., and there doesn't seem to be a command/method/function to do this anywhere.

    I still like and will visit your site again. Thank you for trying to resolve this issue.

    ReplyDelete
  9. Hi ,
    Fantastic work with the Catalex sketch code and commands . Works perfectly on the Uno clone .

    Is it possible to use a PIR to trigger the "play soundtrack on command" ?

    Thanks ,
    Tom

    ReplyDelete
    Replies
    1. Hello again ,

      Thank you for taking the time to answer my question .I looked at your plant watering thread and it has code that works for my project . Now I have another question ,if its not too much trouble ? I am using the PIR (motion sensor)to trigger the mp3 track and H Bridge to DC motor ( left to right turns with delay ) . The problem is the H Bridge delays override the MP3 time so I only get a piece of the mp3 playing until PIR senses no motion , then I get the full mp3 track . Is there a way to keep the delay times independent of each other ?

      Tom

      Delete
  10. For different volume, in command , replace 0x1E(which is hexadecimal and it is equal to 30 in decimal) with
    0X00 for volume=0
    0x01 for volume=1
    .
    .
    .
    0X09 for volume =9
    0X0A for volume =10
    0X0B for volume =11
    .
    .
    0X0f for volume = 15
    0X10 for volume = 16
    .
    .
    0X1E for volume =30

    ReplyDelete
  11. I would like to give you a tip.
    I followed Abul's very useful tips and instructions in the pdf manual ... but when I wanted to play 002.mp3, for example, I played 004: it did not match the file list number! After a day of testing I discovered that the files hidden by the operating system (WIN or MAC OS) are seen from the catalex and they break everything! When you made your list of files displayed in windows HID FILES and DELETE ALL !!! I hope my advice serves someone. Good luck

    ReplyDelete
    Replies
    1. This happened to me too. On Mac show hidden files on the card works, but even though I delete the files, there is still an offset between the file number I want to play and what actually plays.

      Delete
  12. Hi! Thanks for the sketch, It works great. Do you know how can I play files in shuffle?

    ReplyDelete
  13. To control volume, add these to the defines section:
    #define CMD_VOLUP 0X04
    #define CMD_VOLDOWN 0X05

    And then I stuck this code block between the tests for strings "4" and "ps":

    if(str == "d")
    {
    sendCommand(CMD_VOLDOWN, 0X05);//play the forth track with volume 30 class
    Serial.println("Volume Down.");
    }
    if(str == "u")
    {
    sendCommand(CMD_VOLUP, 0X04);//play the forth track with volume 30 class
    Serial.println("Volume Up.");
    }

    Incremental volume control. Up is "u", down is "d".

    ReplyDelete
  14. I've connected mine exactly as per the instructions and it doesn't work. I've tried two different catalex mp3 players, an arduino mega, an arduino nano and a USB to serial converter FTDI232, all without success. Nothing happens when I send the code to the catalex mp3 player. Any idea how I could debug this?

    ReplyDelete
  15. Yes I'm using pins 5 and 6. I'm starting to think that maybe the mp3 player that I bought is not the same as the Catalax one. It doesn't actually say Catalex anywhere, it just says "Open smart mp3 player". It's this one here:

    https://www.ebay.com.au/itm/PCB-Alloy-Plastic-UART-Serial-MP3-Music-Player-Module-w-1W-Speaker-for-Arduino/132387835323?_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20160908105057%26meid%3Db56f8e45dad24cddaede4e390ce8bf20%26pid%3D100675%26rk%3D7%26rkt%3D15%26sd%3D182783476201&_trksid=p2481888.c100675.m4236&_trkparms=pageci%253A3874b8eb-c936-11e7-812a-74dbd18051fd%257Cparentrq%253Aba795ddf15f0aadc3598cb60fffe0561%257Ciid%253A1

    ReplyDelete
  16. Whoops, my fault for assuming it was a Catalex. Thanks, I've purchased some of the Catalex ones now!

    ReplyDelete
    Replies
    1. For those people who also purchase the Open-Smart one like me, I've worked out how to use it. It's actually very similar to the Catalex one except the programming commands are a bit different. You can find the instructions here: www.baaqii.com/promanage/manual/AA2822.rar

      Delete
  17. I would like to solder this board to a breadboard. How are people doing this? Are you using the 4 holes on the edges to screw the mp3 player into place?

    ReplyDelete
  18. I have a problem with loud audible clicks and buzzing, which I assume is processing noise, when I connect an external amplifier to the Cantalex board and power it from the same battery the Arduino is powered by. If I power them independently, there is no extraneous noise. Do you have any suggestions to help resolve this problem, please?

    ReplyDelete
  19. Is there a way (with arduino) to understand when catalex is in the play state? Once given the command arduino does not know when the mp3 song is finished .... tanks

    ReplyDelete
    Replies
    1. Thank you for your quick reply. I figured that catalex did not have a way to tell if it was playing or not. I will use its led (D1, C1 and R6) connecting it to an input of arduino and reading if it flashes it stays on fixed ... This frees me from writing the duration time of each mp3.

      Delete
  20. Hi!
    we followed every step but the songs dont play. The sd indicator stays green. It never blinks. All we get is a short static noise when we first send the code to the arduino and then, even though the commands work on serial monitor nothing happens, but a single short "tic" sound after every command.
    Any ideas?
    thanks

    ReplyDelete
  21. Hello, I use ils senso magnet for starting play music by Seeed mp3 player but it's a probleme when the Ils sensor is staying the music is always biginning, repeat. Perhaps, i have to define the status of ils. It's my firs code and i need help !!!
      if (digitalRead(ilssensor) == ACTIVATED)
      {
        Serial.println("Ils is pressed");
        if (isPlaying)
        {
          pause();
          isPlaying = false;
        }
        else
        {
          isPlaying = true;
          play();
        }

    ReplyDelete



Newly posted:
Reason why rich getting richer and poor getting poorer