How to play soundtracks from different folders in catalex mp3 player


I think I probably would not write this post if John Turcott did not ask me, so most of the things in this post will be dedicated to him but other people can get the idea too.
  • As far as I have understood from your (John Turcott) comment that you wanted to know how you can play sound from different folders (directories).
Answer: Well, you can do that by changing the code a bit which I will explain to you down below.
  • You've said something about changing names of the files like 001xxxxblablabla.mp3 which you might have found awkward.
Ans: Yes it is awkward for any human. We don't like numbers to short out files and we easily get mixed up with the files which one is which, but computers work differently than us. It's easier for computers to find/sort out stuffs with  numbers than letters and words so in that case I think we will just have to accept it unless someone comes up with any other way.

Ad

Note:
If you (other people) are new to catalex mp3 player and you looking for basic functions then please see my another post for that because over here I'm thinking not to go over them again.

Ok, now let's begin and start with 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, 0X0F01);//play the first song with volume 15 class
}

String str;
void loop() {
if(Serial.available()){
str = Serial.readStringUntil('\n');

if(str == "2"){
sendCommand(CMD_PLAY_W_VOL, 0X1E07);//play the 7th track with volume 30 class
Serial.println("Second sound track number 7 is playing.");
}

if(str == "3"){
sendCommand(CMD_PLAY_W_VOL, 0X1E99909);//play the third track with volume 30 class
Serial.println("Sound of a whale from folder number 999 file number 09.");
}

if(str == "4"){
sendCommand(CMD_PLAY_W_VOL, 0X1E1102);//play the forth track with volume 30 class
Serial.println("Sound of a bat from folder number 11 and file number 02.");
}

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]) ;
  }
}

As you can see the sketch is almost same as before beside only one thing, and that is you just need to change the folder number. I've tried with few folders 01, 02, 11, 99, and 999 as you can see in the picture at the top just to see how many folder can I add and it's seems like you can at least make 999 folders. And in every folder you can put 10 sound tracks, I've tried to add more than 10 but that didn't work.

Key notes:
  • Only 10 sound tracks in each folder.
  • After volume code *1E* add the folder number and then file number like this (0X1E99909) in this example 999 is a folder number and 09 is that sound track.
  • You might be able to make as many folder you wish but up 999 is for sure.
  • If you make folders and files like the picture at the top and upload this sketch to your Arduino you will be able to hear the sounds from different folders and text will appear on the serial monitor saying which track is playing currently.
  • Which ever song you play and which ever folder it's from all the functions (play, pause, previous, next) all will become automatically for that folder. For example if you play a song from folder 99 then you sent code for next so it will play the next song which you played from the folder number 99 recently.
That's all for this post, I hope it helps you.

Ad



8 comments:

  1. hello, i want to ask you something. i want to make a mp3 player which works with buttons. i used arduino uno, connected 10 buttons to pins 4,5,6.....13. i want it play music named 001.mp3 when i pust 1st button( mean digitalRead(4)==HIGH), 2st button play 002.mp3 etc. i could play just 9 mp3, it doest play more, and every buttons play wrong number mp3. example i push 3rd button, i need it play 003.mp3, but it plays 008.mp3. i created 2 folder named 01 and 02, put first five mp3s in 01, last 5 mp3s in 02 folder, but when i use 0X1E0101(i expect in 01 folder 001.mp3) it plays another musiv and sound is so low. can you help me how can i play 10 or more mp3. sorry for bad english :(

    ReplyDelete
    Replies
    1. I'm having the same exact problem, i followed your instructions but everytime, it simply plays some random sound from another folder with lower volume. it's like it does not even recognize the folder itself

      Delete
  2. I'm having the same exact problem, i followed your instructions but every time, it simply plays some random sound from another folder with lower volume. it's like it does not even recognize the folder itself..... any answer to this issue? I have labeled my folders 01, 02, 03 .... files 001.mp3 002.mp3 etc. but no mater what I select as what I think it should play, it seems to default to 01001... help me Obi Wan

    ReplyDelete
    Replies
    1. Did you try this "After volume code *1E* add the folder number and then file number like this (0X1E99909) in this example 999 is a folder number and 09 is that sound track." it should work.

      Delete
    2. Thanks, I saw that in the article... Here is my layout
      folders
      01
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      02
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      03
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      04
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      05
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      06 within each folder, various number files; example below.
      001.mp3
      002.mp3
      003.mp3
      004.mp3
      005.mp3

      sample folder and file request, but doesn't seem to work


      if(str == "1"){
      Serial.println("In 1");
      sendCommand(CMD_PLAY_W_VOL, 0X1E0101);//folder 1 play the 1st track with volume 30 class

      }

      Help me O B wan can no B


      Delete
    3. I'm sorry I would've helped you but since I don't get any benefit for helping people so I don't think there is any point wasting my time behind it.

      Delete
  3. I don't understand? I'm simply setting up the files as it was stated and asking why it doesn't work as stated in the article? Benefit? why do you answer questions then? Sorry if I have somehow offended you.

    ReplyDelete
    Replies
    1. You must have done something wrong that's why it's not working as it supposed to, I wouldn't write this article if it didn't work. "why do you answer questions then?" To explain why I'm not bothered wasting my time and go over it in detail. Sorry I've wasted a lot of my time and didn't get much from people. People just come get the help and go away, but they don't think if I got something from this person is there any way i can also give back. Simple "Thanks is not everything quite lot of time people need more then that. I hope You understood what I'm trying to say.

      Delete



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