Go Down

Topic: Created a library for the MDFLY MP3 module (TDB380) (Read 7 times) previous topic - next topic

DavidFMarks

Nearly there ! The main problem appears to be the volume. The data sheet seems to be wrong. The +volume pin is shown as pin 9 when it seem to be grounding pin 10 that increases the volume. I now have to sort out how to get the files in the right order and then how to call them from within my sketch rather than via the serial monitor ! still at least we seem to be winning. Thanks for your patience and help.

Retroplayer

As for the volume, I found that the module does not start up at full volume. That is why I put the volume setting in my .begin method so that you can set it at intialization. If you are looking at the MDFly datasheet, it is missing some of the commands.

You set the volume by writing C8-E7 (200-231). 231 being full volume. So in your setup() put Serial.write(231) to start up with full volume.

EF is not technically a reset. It is STOP. I put that in my code because the module sometimes starts up randomly playing an MP3. Using 0 to play a random file was silly in my opinion.

So, try this:

Code: [Select]


void setup(){
  Serial.begin(9600);
  Serial.write(0xEF); //Stop playing
  Serial.write(0xE0); //Set the volume just below full volume
}


It seems like your module is either just playing a random file at startup and your loop isn't working because the busy signal is active, or it only sees one file on the card for some reason.

I don't see anything wrong with your code (assuming you are changing the number from 0 for the file you want to play). BTW, you could snag the serial parsing part of my example code and just replace the calls with Serial.write commands if you wanted to try out all the features.


Code: [Select]

void loop(){
 byte sc = 0;
 unsigned long number = 0;
 byte n =0;
 
 if(Serial.available()){
   sc = Serial.read();  
 }
 
 if(sc == 'p' || sc == 'P'){ //Play (001-199)
   number=Serial.parseInt();
   n = byte(number);
   if(n > 0 && n < 200){
    MP3.play(n);
   }

   else {
     Serial.println("Error: Use a value 1 - 199);
   }
 }

 if(sc == 's' || sc == 'S'){ //Stop Playing
   Serial.write(0xEF);
 }

 if(sc == '+'){ //Voume Up
   Serial.write(0xE8);
 }

 if(sc == '-'){ //Volume Down
   Serial.write(0xE9);
 }

 if(sc == 'v' || sc == 'V'){ //Set Volume (01-31)
   number=Serial.parseInt();
   n = byte(number);
   n = n + 200;
   if(n >= 0 && n < 32){
   Serial.write(n);
   }
   else {
     Serial.println("Error: Use a value 0 - 31);
   }
 }

 if(sc == 'f' || sc == 'F'){ //Change Directory (01-15) 01 is root
   number=Serial.parseInt();
   n = byte(number);
   n = n + 240;
   if(n > 240 && n < 256){
   Serial.write(n);
   }
   else{
     Serial.println("Error: Use a value 1 - 15);
   }
 }

 if(sc == '*'){ //Play a random file (will switch back to the root folder! Only plays from root folder)
  Serial.write(0x00);
 }

 if(sc == '/'){ //Pause/Resume
  Serial.write(0xEB);
 }
}


No promises that there isn't a typo in there.

Retroplayer

If it is working with the serial port, it should be working with my library. The only thing my library is doing mainly is emulating the Tx portion of a standard serial port at 4800 baud. I used code directly from the SoftwareSerial library to do that part.

Everything else is just formatting numbers to make it easier to understand, and doing some error checking.

Nothing wild going on with it.

DavidFMarks

Everything seems to be working ok now. (My grumpy scarecrow is grumbling away nicely now !) Only two things puzzle me.
Using the code below I am surprised that after the function Playfile is executed that it does not return to the main loop and then repeat.
Also when I upload the program it initially plays the file (n)which was set previously. Only when I run for the second time does it use the new value of (n).
Any comments would be appreciated.

Retroplayer


Go Up