Catalex serial mp3 control

hi I need some help with a catalex mp3 controlled by arduino mega I would like to be able to input 2 digit numbers and play the corresponding song number and a potentiometer for volume control would help
thank you in advance
here is my code:

#include <SoftwareSerial.h>
#include <Keypad.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);
 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

 const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','4','7','*'},
  {'2','5','8','0'},
  {'3','6','9','#'},
  {'A','B','C','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11, 10}; //connect to the column pinouts of the keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

 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

 }
 String str;
 void loop() {
char key = kpd.getKey();
 if(key=='1')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E01);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='2')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E02);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='3')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E03);//play the third track with volume 30 class
 Serial.println("Third sound track.");
 }
 if(key=='4')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E04);//play the forth track with volume 30 class
 Serial.println("Forth sound track.");
 }
 if(key=='5')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E05);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='6')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E06);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='7')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E07);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='8')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E08);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 if(key=='9')
 {
 sendCommand(CMD_PLAY_W_VOL, 0X1E09);//play the second track with volume 30 class
 Serial.println("Second sound track.");
 }
 
 if(key=='B')
 {
 sendCommand(CMD_PAUSE, 0X0E);//pause the playing track
 Serial.println("Pause");
 }
 if(key=='A')
 {
 sendCommand(CMD_PLAY, 0X0D);//play it again 
 Serial.println("Play");
 }
 if(key=='D')
 {
 sendCommand(CMD_PREVIOUS, 0X02);//play previous track
 Serial.println("Playing previous track.");
 }
 if(key=='C')
 {
 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]) ;
   }
 }

Duplicate of http://forum.arduino.cc/index.php?topic=465060.0
DON'T DO THAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reported

Several questions. Since you are using a Mega, with 4 hardware serial ports, why are you using SoftwareSerial?

If you are going to leave all 4 hardware serial ports doing nothing, why did you not bother to RTFM? SoftwareSerial works on pins that support pin change interrupts. Unlike on the Uno, not all pins on the Mega support pin change interrupts.

I'd like to find out if the player ever responds or how to read the drive for so much as file names. Will it at least transmit an error code if unable to carry out or interpret a command?

I have DAOKI modules on order, maybe see them when customs is done in a week or two, it's coming on 2 already... but 5 for $15 and change?

nattylol48:
hi I need some help with a catalex mp3 controlled by arduino mega I would like to be able to input 2 digit numbers and play the corresponding song number and a potentiometer for volume control would help
thank you in advance
here is my code:

---- snipped by GFS, this I want to refer to below

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

This is the play indexed song command string: 7E FF 06 03 00 00 01 EF

The folder number (folder file names start with 2 digits is encoded in this byte: 7E FF 06 03 00 @@ 01 EF
The song number (song file names start with 3 digits is encoded in this byte: 7E FF 06 03 00 00 ## EF

EDIT: this part is wrong, have to send byte values not text hex of byte values, SEE BELOW.
If you use Arduino bytes (unsigned 8 bit integers) and print them out as HEX with code to print a leading 0 if val < 0x10 first you get the chars to send 2 hex digit text values for folder and song. The pattern is: 7E FF 06 03 00 @@ ## EF, the first 5 bytes and the last byte are constant bytes you print as hex. Hex is just decimal with 6 extra fingers.

That delay(20) wastes 320000 cpu cycles. There’s ways around it, search on arduino non-blocking code

If you want indexed access to folders and/or songs then the folders need to be named “01”, “02”, etc, and song files “001xxx.mp3”, etc.

Attached is the sketch I’m using to run the player and see feedback. I’d put the source in code tags but my system is a pain, I get to the net through a boot-drive and I can’t get the ide running to copy it from.

Get serial monitor up and hit reset if needed to see the startup message. Enter anything in the monitor to start it playing “the next song”. You will see the data bytes sent to the player separated by commas. Next line is the player feedback bytes separated by spaces only. When the song ends see the feedback from that, the code right now looks for the 4th byte of all player feedback and flags the code to play the next song when it detects 0x3D there twice, the player kicks that out twice after “play next” song is finished.

The code runs but it’s only a start for anything finished.

I don’t like these players. They don’t let me read the SD card at all. If I want to keep information to show the user I need to use another SD card or try to fit it all in PROGMEM. They work but at the least level. They’re cheap, and worth the price.

catalex_test.ino (2.12 KB)

I got DFPlayer Mini in and when I found doc I found it to be very similar to the Catalex player. Almost if not identical except that the DFPlayer pdf English-language datasheet is complete including responses. The Catalex may or may not be the same in all respects, the vs1053 in one may not have all the program features of the other... the DFPlayer Mini has equalizer choices for example.

Songs should start with 4 digits but can have regular file names after (rename to add 4 digits up front, got it) and folder names should be all number.. it says, if you want to play songs by number.