Arduino Nano - MajicDesigns Arduino YX5300

Hi there everyone - absolute first time to Arduino so hoping to reach out for help.

My goal - I currently have a YX5300 purchased from jaycar along with a Arduino Nano board. All I want it to do is play a single mp3 on a single cycle as soon as it powers up.

So far I've downloaded the IDE, connected everything up using pins 10/11 as per the jaycar manual.
I have installed Majic Designs library etc.
Im having trouble getting the code to instruct the Arduino to carry out the above function.

mind you this is all so foreign to me so I am trying to learn this all from scratch.

the module I am using can be found in this link: https://www.jaycar.com.au/medias/sys_master/images/images/9505689698334/XC3748-manualMain.pdf

when I input the code into the IDE I get multiple errors such as:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Users\Sa'ad\Documents\Arduino\sketch_apr26b\sketch_apr26b.ino: In function 'void setup()':

sketch_apr26b:10:21: error: no matching function for call to 'MD_YX5300::MD_YX5300(const short int&, const short int&)'

MD_YX5300 mp3(rx, tx);

                 ^

In file included from C:\Users\Sa'ad\Documents\Arduino\sketch_apr26b\sketch_apr26b.ino:1:0:

C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-main\src/MD_YX5300.h:460:3: note: candidate: MD_YX5300::MD_YX5300(Stream&)

MD_YX5300(Stream& S) :

^~~~~~~~~

C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-main\src/MD_YX5300.h:460:3: note: candidate expects 1 argument, 2 provided

In file included from C:\Users\Sa'ad\Documents\Arduino\sketch_apr26b\sketch_apr26b.ino:1:0:

C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-main\src/MD_YX5300.h:383:7: note: candidate: constexpr MD_YX5300::MD_YX5300(const MD_YX5300&)

class MD_YX5300

   ^~~~~~~~~

C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-main\src/MD_YX5300.h:383:7: note: candidate expects 1 argument, 2 provided

sketch_apr26b:12:1: error: a function-definition is not allowed here before '{' token

{

^

sketch_apr26b:24:1: error: a function-definition is not allowed here before '{' token

{

^

Multiple libraries were found for "MD_YX5300.h"

Used: C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-main

Not used: C:\Users\Sa'ad\Documents\Arduino\libraries\MD_YX5300-1.3.1

exit status 1

no matching function for call to 'MD_YX5300::MD_YX5300(const short int&, const short int&)'

Is there anyone out there willing to help with what could be a very simple code?

i believe the instruction is for Set single cycle play
7E FF 06 19 00 00 00 EF Start up single cycle play

alternatively - any recommendations to learn this on my own are also welcomed!

Thankyou!

I strongly suggest that you remove your email address; unless you want to receive spam.

Can you please post your code between code tags. The easiest is probably to use (in the IDE) edit -> copy for forum and next paste it in a new reply here. Also please post a link to the library.

Lastly, Introductory Tutorials is not for questions/issues but for 'articles'; reported for a move.

thanks for the response - so far I've included the basic code from the user manual into IDE as below:

#include <MD_YX5300.h>

void setup() {
  // put your setup code here, to run once:
// Connections for serial interface to the YX5300 module
const short rx = 10; // connect to TX of MP3 Player module
const short tx = 11; // connect to RX of MP3 Player module
MD_YX5300 mp3(rx, tx);
void setup()
{
 Serial.begin(9600);
 Serial.println("XC3748 Serial Command Example");
 // Initialise player
 mp3.begin();
 mp3.setSynchronous(true); // return after sending command.
 mp3.playNext();
 // You can also use the below, if all of your files are in a folder.
 //mp3.playFolderRepeat(1);
 // 1 = "first folder copied onto SD card", 2 = "second folder" etc.
}
void loop()
{
 mp3.check();
 // check the status of mp3; visit the library readme for more.
 // https://majicdesigns.github.io/MD_YX5300/
}
}

void loop() {
  // put your main code here, to run repeatedly:

}

the library I've used can be found here:

Ideally the command I would like to transmit is from the jaycar manual which is a single cycle play:

Set single cycle play
7E FF 06 19 00 00 00 EF Start up single cycle play

Thanks!

The library might have been updated and Jaycar might not have updated their documentation.

The constructor does not take rx and tx as parameters but a stream. So you first need to setup a serial instance (in your case software serial) and use that in the constructor.

#include <SoftwareSerial.h>
#include <MD_YX5300.h>

// Connections for serial interface to the YX5300 module
const short rx = 10; // connect to TX of MP3 Player module
const short tx = 11; // connect to RX of MP3 Player module
SoftwareSerial swSerial(rx,tx);
// setup the MD_YX5300
MD_YX5300 mp3(swSerial);

// put your setup code here, to run once:
void setup()
{
  Serial.begin(9600);
  Serial.println("XC3748 Serial Command Example");
  // Initialise player
  mp3.begin();
  mp3.setSynchronous(true); // return after sending command.
  mp3.playNext();
  // You can also use the below, if all of your files are in a folder.
  //mp3.playFolderRepeat(1);
  // 1 = "first folder copied onto SD card", 2 = "second folder" etc.
}

void loop()
{
  mp3.check();
  // check the status of mp3; visit the library readme for more.
  // https://majicdesigns.github.io/MD_YX5300/
}

This does compile; if it works is another question and I have no option to check.

Good day!,
fantastic news is that I was able to get the player working as intended. I was trying to tweak the CMD PLAY function to play files randomly (4 files in the directory). Serial Monitor is showing the "shuffle" command being sent. However i've noticed that it will always start from track 001. is there any way I can tweak this to start from a different track each time upon powering up?

Main gist is that this MP3 module is designed to play a single start up tone - I would like it to play a different tone at each power up.

Code below for reference.

/***********************************************************/
// Demo for the Serial MP3 Player Catalex (YX5300 chip)
// Hardware: Serial MP3 Player *1
// Board:  Arduino UNO
// http://www.dx.com/p/uart-control-serial-mp3-music-player-module-for-arduino-avr-arm-pic-blue-silver-342439#.VfHyobPh5z0
//
//
//


// Uncomment SoftwareSerial for Arduino Uno or Nano.

#include <SoftwareSerial.h>

#define ARDUINO_RX 5  //should connect toLesson plan  TX of the Serial MP3 Player module
#define ARDUINO_TX 6  //connect to RX of the module

SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX);

// Uncomment next line if you are using an Arduino Mega.


static int8_t Send_buf[8] = {0}; // Buffer for Send commands.  // BETTER LOCALLY
static uint8_t ansbuf[10] = {0}; // Buffer for the answers.    // BETTER LOCALLY

String mp3Answer;           // Answer from the MP3.


String sanswer(void);
String sbyte2hex(uint8_t b);


/************ Command byte **************************/
#define CMD_NEXT_SONG     0X01  // Play next song.
#define CMD_PREV_SONG     0X02  // Play previous song.
#define CMD_PLAY_W_INDEX  0X03
#define CMD_VOLUME_UP     0X04
#define CMD_VOLUME_DOWN   0X05
#define CMD_SET_VOLUME    0X06

#define CMD_SNG_CYCL_PLAY 0X08  // Single Cycle Play.
#define CMD_SEL_DEV       0X09
#define CMD_SLEEP_MODE    0X0A
#define CMD_WAKE_UP       0X0B
#define CMD_RESET         0X0C
#define CMD_PLAY          0X0D
#define CMD_PAUSE         0X0E
#define CMD_PLAY_FOLDER_FILE 0X0F

#define CMD_STOP_PLAY     0X16  // Stop playing continuously. 
#define CMD_FOLDER_CYCLE  0X17
#define CMD_SHUFFLE_PLAY  0x18 //
#define CMD_SET_SNGL_CYCL 0X19 // Set single cycle.

#define CMD_SET_DAC 0X1A
#define DAC_ON  0X00
#define DAC_OFF 0X01

#define CMD_PLAY_W_VOL    0X22
#define CMD_PLAYING_N     0x4C
#define CMD_QUERY_STATUS      0x42
#define CMD_QUERY_VOLUME      0x43
#define CMD_QUERY_FLDR_TRACKS 0x4e
#define CMD_QUERY_TOT_TRACKS  0x48
#define CMD_QUERY_FLDR_COUNT  0x4f

/************ Opitons **************************/
#define DEV_TF            0X02


/*********************************************************************/

void setup()
{
  Serial.begin(9600);
  mp3.begin(9600);

 sendCommand(CMD_SHUFFLE_PLAY);
  delay(5000);
  sendCommand(CMD_STOP_PLAY);

  
}


void loop()
{

  char c = ' ';

  // If there a char on Serial call sendMP3Command to sendCommand
  if ( Serial.available() )
  {
    c = Serial.read();
    sendMP3Command(c);
  }

  // Check for the answer.
  if (mp3.available())
  {
    Serial.println(decodeMP3Answer());
  }
  delay(100);
}


/********************************************************************************/
/*Function sendMP3Command: seek for a 'c' command and send it to MP3  */
/*Parameter: c. Code for the MP3 Command, 'h' for help.                                                                                                         */
/*Return:  void                                                                */

void sendMP3Command(char c) {
  
  switch (c) {
    case '?':
    case 'h':
      Serial.println("HELP  ");
      Serial.println(" p = Play");
      Serial.println(" P = Pause");
      Serial.println(" > = Next");
      Serial.println(" < = Previous");
      Serial.println(" s = Stop Play"); 
      Serial.println(" + = Volume UP");
      Serial.println(" - = Volume DOWN");
      Serial.println(" c = Query current file");
      Serial.println(" q = Query status");
      Serial.println(" v = Query volume");
      Serial.println(" x = Query folder count");
      Serial.println(" t = Query total file count");
      Serial.println(" f = Play folder 1.");
      Serial.println(" S = Sleep");
      Serial.println(" W = Wake up");
      Serial.println(" r = Reset");
      Serial.println(" z = MAXVol");
      Serial.println(" a = Shuffle");
      break;


    case 'p':
      Serial.println("Play ");
      sendCommand(CMD_PLAY);
      break;
      
    case 'a':
      Serial.println("Shuffle");
      sendCommand(CMD_SHUFFLE_PLAY);
      break;
     
    case 'P':
      Serial.println("Pause");
      sendCommand(CMD_PAUSE);
      break;

    case '>':
      Serial.println("Next");
      sendCommand(CMD_NEXT_SONG);
      sendCommand(CMD_PLAYING_N); // ask for the number of file is playing
      break;

    case '<':
      Serial.println("Previous");
      sendCommand(CMD_PREV_SONG);
      sendCommand(CMD_PLAYING_N); // ask for the number of file is playing
      break;

    case 's':
      Serial.println("Stop Play");
      sendCommand(CMD_STOP_PLAY);
      break;


    case '+':
      Serial.println("Volume Up");
      sendCommand(CMD_VOLUME_UP);
      break;

    case '-':
      Serial.println("Volume Down");
      sendCommand(CMD_VOLUME_DOWN);
      break;

    case 'c':
      Serial.println("Query current file");
      sendCommand(CMD_PLAYING_N);
      break;

    case 'q':
      Serial.println("Query status");
      sendCommand(CMD_QUERY_STATUS);
      break;

    case 'v':
      Serial.println("Query volume");
      sendCommand(CMD_QUERY_VOLUME);
      break;

    case 'x':
      Serial.println("Query folder count");
      sendCommand(CMD_QUERY_FLDR_COUNT);
      break;

    case 't':
      Serial.println("Query total file count");
      sendCommand(CMD_QUERY_TOT_TRACKS);
      break;

    case 'f':
      Serial.println("Playing folder 1");
      sendCommand(CMD_FOLDER_CYCLE, 1, 0);
      break;

    case 'S':
      Serial.println("Sleep");
      sendCommand(CMD_SLEEP_MODE);
      break;

    case 'W':
      Serial.println("Wake up");
      sendCommand(CMD_WAKE_UP);
      break;

    case 'r':
      Serial.println("Reset");
      sendCommand(CMD_RESET);
      break;

          case 'z':
      Serial.println("MaxVol");
      sendCommand(CMD_PLAY_W_VOL);
      break;
  }
}



/********************************************************************************/
/*Function decodeMP3Answer: Decode MP3 answer.                                  */
/*Parameter:-void                                                               */
/*Return: The                                                  */

String decodeMP3Answer() {
  String decodedMP3Answer = "";

  decodedMP3Answer += sanswer();

  switch (ansbuf[3]) {
    case 0x3A:
      decodedMP3Answer += " -> Memory card inserted.";
      break;

    case 0x3D:
      decodedMP3Answer += " -> Completed play num " + String(ansbuf[6], DEC);
      break;

    case 0x40:
      decodedMP3Answer += " -> Error";
      break;

    case 0x41:
      decodedMP3Answer += " -> Data recived correctly. ";
      break;

    case 0x42:
      decodedMP3Answer += " -> Status playing: " + String(ansbuf[6], DEC);
      break;

    case 0x48:
      decodedMP3Answer += " -> File count: " + String(ansbuf[6], DEC);
      break;

    case 0x4C:
      decodedMP3Answer += " -> Playing: " + String(ansbuf[6], DEC);
      break;

    case 0x4E:
      decodedMP3Answer += " -> Folder file count: " + String(ansbuf[6], DEC);
      break;

    case 0x4F:
      decodedMP3Answer += " -> Folder count: " + String(ansbuf[6], DEC);
      break;
  }

  return decodedMP3Answer;
}






/********************************************************************************/
/*Function: Send command to the MP3                                             */
/*Parameter: byte command                                                       */
/*Parameter: byte dat1 parameter for the command                                */
/*Parameter: byte dat2 parameter for the command                                */

void sendCommand(byte command){
  sendCommand(command, 0, 0);
}

void sendCommand(byte command, byte dat1, byte dat2){
  delay(20);
  Send_buf[0] = 0x7E;    //
  Send_buf[1] = 0xFF;    //
  Send_buf[2] = 0x06;    // Len
  Send_buf[3] = command; //
  Send_buf[4] = 0x01;    // 0x00 NO, 0x01 feedback
  Send_buf[5] = dat1;    // datah
  Send_buf[6] = dat2;    // datal
  Send_buf[7] = 0xEF;    //
  Serial.print("Sending: ");
  for (uint8_t i = 0; i < 8; i++)
  {
    mp3.write(Send_buf[i]) ;
    Serial.print(sbyte2hex(Send_buf[i]));
  }
  Serial.println();
}



/********************************************************************************/
/*Function: sbyte2hex. Returns a byte data in HEX format.                       */
/*Parameter:- uint8_t b. Byte to convert to HEX.                                */
/*Return: String                                                                */


String sbyte2hex(uint8_t b)
{
  String shex;

  shex = "0X";

  if (b < 16) shex += "0";
  shex += String(b, HEX);
  shex += " ";
  return shex;
}


/********************************************************************************/
/*Function: shex2int. Returns a int from an HEX string.                         */
/*Parameter: s. char *s to convert to HEX.                                      */
/*Parameter: n. char *s' length.                                                */
/*Return: int                                                                   */

int shex2int(char *s, int n){
  int r = 0;
  for (int i=0; i<n; i++){
     if(s[i]>='0' && s[i]<='9'){
      r *= 16; 
      r +=s[i]-'0';
     }else if(s[i]>='A' && s[i]<='F'){
      r *= 16;
      r += (s[i] - 'A') + 10;
     }
  }
  return r;
}


/********************************************************************************/
/*Function: sanswer. Returns a String answer from mp3 UART module.          */
/*Parameter:- uint8_t b. void.                                                  */
/*Return: String. If the answer is well formated answer.                        */

String sanswer(void)
{
  uint8_t i = 0;
  String mp3answer = "";

  // Get only 10 Bytes
  while (mp3.available() && (i < 10))
  {
    uint8_t b = mp3.read();
    ansbuf[i] = b;
    i++;

    mp3answer += sbyte2hex(b);
  }

  // if the answer format is correct.
  if ((ansbuf[0] == 0x7E) && (ansbuf[9] == 0xEF))
  {
    return mp3answer;
  }

  return "???: " + mp3answer;
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.