Catalex YX5300 mp3 player STS_FILE_END

Hi,

I'm using the Catalex YX5300 MP3 player to play a few audio files in sequence and control lights and servos between and during songs. Is there anyway of me using the STS_FILE_END message to set variables in code.

Thanks

The file end notification is sent as an unsolicited message, so you need to initially be ready to receive the message. Once the message is received, you can do whatever you want triggered by the 'act of receiving'. I wrote some blog posts a while ago:

If you can be more specific about why you think this is a problem then I can be more specific.

Thanks a lot for the documentation. I have written code for a simple player that plays a specific song for a specific button pressed. The player works fine I push button 1 and song 1 plays etc. The trouble I’m having is every time I push a button I receive the timeout error “STS_TIMEOUT, 0x0”. I also receive no other messages eg: “STS_FILE_END” when I song finishes. What could be wrong? My code is below

/*
Test for Mp3 MDS_YX5300 player
*/

#include <MD_YX5300.h>

// Connections for serial interface to the YX5300 module
const uint8_t ARDUINO_RX = 4; // connect to TX of MP3 Player module
const uint8_t ARDUINO_TX = 5; // connect to RX of MP3 Player module

const int playButton1 = 2; // button on pin 2
const int playButton2 = 8;
const int playButton3 = 9;
const uint8_t PLAY_FOLDER = 1;
int playButtonState1 = 0; // variable for reading the pushbutton status
int playButtonState2 = 0;
int playButtonState3 = 0;

// Define global variables
MD_YX5300 mp3(ARDUINO_RX, ARDUINO_TX);

void cbResponse(const MD_YX5300::cbData *status)
// Used to process device responses either as a library callback function
// or called locally when not in callback mode.
{

switch (status->code)
{
case MD_YX5300::STS_OK: Serial.print(F(“STS_OK”)); break;
case MD_YX5300::STS_TIMEOUT: Serial.print(F(“STS_TIMEOUT”)); break;
case MD_YX5300::STS_VERSION: Serial.print(F(“STS_VERSION”)); break;
case MD_YX5300::STS_CHECKSUM: Serial.print(F(“STS_CHECKSUM”)); break;
case MD_YX5300::STS_TF_INSERT: Serial.print(F(“STS_TF_INSERT”)); break;
case MD_YX5300::STS_TF_REMOVE: Serial.print(F(“STS_TF_REMOVE”)); break;
case MD_YX5300::STS_ERR_FILE: Serial.print(F(“STS_ERR_FILE”)); break;
case MD_YX5300::STS_ACK_OK: Serial.print(F(“STS_ACK_OK”)); break;
case MD_YX5300::STS_FILE_END: Serial.print(F(“STS_FILE_END”)); break;
case MD_YX5300::STS_INIT: Serial.print(F(“STS_INIT”)); break;
case MD_YX5300::STS_STATUS: Serial.print(F(“STS_STATUS”)); break;
case MD_YX5300::STS_EQUALIZER: Serial.print(F(“STS_EQUALIZER”)); break;
case MD_YX5300::STS_VOLUME: Serial.print(F(“STS_VOLUME”)); break;
case MD_YX5300::STS_TOT_FILES: Serial.print(F(“STS_TOT_FILES”)); break;
case MD_YX5300::STS_PLAYING: Serial.print(F(“STS_PLAYING”)); break;
case MD_YX5300::STS_FLDR_FILES: Serial.print(F(“STS_FLDR_FILES”)); break;
case MD_YX5300::STS_TOT_FLDR: Serial.print(F(“STS_TOT_FLDR”)); break;
default: Serial.println(F(“STS_??? 0x”)); Serial.println(status->code, HEX); break;
}

Serial.print(F(", 0x"));
Serial.println(status->data, HEX);
}

void setup() {
// initialize global libraries

Serial.begin(57600);
mp3.begin();
mp3.setSynchronous(true);
mp3.setCallback(cbResponse);
mp3.volumeMax();

pinMode(playButton1, INPUT_PULLUP);
pinMode(playButton2, INPUT_PULLUP);
pinMode(playButton3, INPUT_PULLUP);

}

void loop() {
playButtonState1 = digitalRead(playButton1);
playButtonState2 = digitalRead(playButton2);
playButtonState3 = digitalRead(playButton3);

if (playButtonState1 == LOW){
mp3.playTrack(001);
}

if (playButtonState2 == LOW){
mp3.playTrack(002);
}

if (playButtonState3 == LOW){
mp3.playTrack(003);
}

mp3.check();

}

Hi again

marco_c I also tried your example MD_YX5300_Test.ino. I can use all functions (play specific songs, pause set volume etc), but every time I receive "Cback status: STS_TIMEOUT, 0x0" on serial monitor. Example me setting volume to 30 and playing track 1 the serial monitor prints.

Cback status: STS_TIMEOUT, 0x0

Volume 30
Command ?

Cback status: STS_TIMEOUT, 0x0

Play Track 1
Command ?

Cback status: STS_TIMEOUT, 0x0

A few things to consider:

  1. Detecting a switch has been pressed is not just detecting it is low, but it is detecting that is has TRANSITIONED from an ‘off’ to an ‘on’ state (in your case a transition from HIGH to LOW). And you also need to take into account mechanical switch bounce that will give you a few HIGH/LOW transitions for each press. The problem with your loop() function is that every time it sees LOW (and this will be several times for each press) it will send a message to play. You can do research to work out what to do or just use the MD_UISwitch library that will take care of switches the right way.

  2. “Command ?” is printed when the command character is not correct.

default: Serial.print(F("\n>Command ?")); Serial.print(c); break;

It also prints the character that cannot be processed. The fact we cannot see a character probably means that your setup line endings for Serial Monitor are not correct. From memory there should be NO line endings for the test software, but you can try the different options until you no longer get the message.

  1. You should probably turn on the debugging in the library to get output of what messages are being sent back and forth to see why you are getting the timeout. Edit MD_YX5300.cpp and change
#define LIBDEBUG  0   ///< Set to 1 to enable Debug statement in the library

to 1.

Hi. I have noticed the problem is with the boards. I have been using an Arduino Mega. Every time with the mega I get the timeout message (STS_Timeout). I switched to an Uno and it works fine. I receive all messages. Any reason why its not working with the mega. The debug statement with the mega is below for running MD_YX5300_TEST.ino

Callback ON
Synchronous OFF
Synchronous ON
Command ?

Volume 30
0014408 S: 7E FF 06 06 01 00 1E FE D6 EF
0015429 R: -> 1 : Timeout
Sync Status: STS_TIMEOUT, 0x0
Synch wait over
Command ?

Play Track 1
0019814 S: 7E FF 06 03 01 00 01 FE F6 EF
0020835 R: -> 1 : Timeout
Sync Status: STS_TIMEOUT, 0x0
Synch wait over
Command ?

Have you connected the right pins on the Mega? Particularly serial receive from the Yx.

Yes

I have TX of the MP3 connected to pin 4
and RX of the MP3 connected to pin 5.

I have also tried connecting to other PWM pins on the mega and changing the pins number in the code below to the suitable pins.

const uint8_t ARDUINO_RX = 4; // connect to TX of MP3 Player module
const uint8_t ARDUINO_TX = 5; // connect to RX of MP3 Player module

I still get the timeout message. Could it have something to do with the mega running at a different clock speed compared to the uno.

The timeout is generated by the library if it does not get a response in within the timeout time. Change the timeout to be really long, say 5 seconds, to see if this allows a message in.

As your device is doing what you ask then it is getting the message one way. As we cannot see a receive message then it is either in the wrong pin or a cable problem. No other option.

Hi, I will give setting timeout to 5 seconds a try. I would also like to use the mp3 on native serial. That's the reason why I chose the mega. Apart from setting the line of code in the header file found below what changes would I require in main code.

#define USE_SOFTWARESERIAL 1

Would it be something like where variables a defined

Mp3 Serial2

and in setup

Mp3.begin(9600)

Or can I just use Serial2.begin(9600) in setup

Thanks

#if USE_SOFTWARESERIAL
#include <SoftwareSerial.h>
#else
#define _Serial Serial2      ///< Native serial port - can be changed to suit
#endif

If SOFTWARESERIAL is not defined then it will default to Serial2. _Serial is initialized in the begin() method so you don’t need to do anything in the application. If you want to use a different Serial change the Serial2 to your choice in the library.