Go Down

Topic: YX5300, YX5200 weird action, goes to sleep/suspended? (Read 1 time) previous topic - next topic

FrankStark

Jun 14, 2019, 10:02 am Last Edit: Jun 14, 2019, 11:33 am by FrankStark
Hi there!

The case: Uno, with 2 different serial mp3 players hooked up, a YX5300, and a YX5200 based. I'm playing back short drum samples ( 1-2 seconds at max ).

Both player has a behaviour. If I play a sample the first is low volume, like much lower volume but audible, but it's there and if I hit the "play button" again within 1-2 seconds the 2nd sample play is at normal volume. If I wait like more than 2 seconds the first sample is quieter again.

It's a musical application so timing is important. I can't have silence at the beginning of the track.

I don't know is it going to sleep or suspended? If hit the samples back to back they sound ok, but if I leave more than a few seconds gap, the first is always much lower in volume. I use asincronous communication by that I mean I don't monitor the signals coming back from the players. I tried it with "next song", "play xy song" commands, and a direct IO2 control on the DF Player. ( which is a simple phisical switch ) the case is always the same. I tried to make a 3 minute long sample, which has like silence all the way to the end to not allow suspension if that's the case, but it's the same, if I wait 2 seconds the first sample is lower in volume. the led is lighting up so I see that the player is playing the silence after the sample. The code is in the next post.

EDIT: I tried to add a silent track to play inbeetween the samples, but it doesn't change to fade in of the actual samples.

IDEA1: I only need mono files so I could play a sample regularly in the Left side only and play my sample in the right.

IDEA2: use the DAC output of the DF player. I have to test these out. Meanwhile help if you can pls :D

IDEA3: get an other type of "wave shield" but I don't know which... simple cheap is all I need

FrankStark

Code: [Select]
#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
#define ARDUINO2_RX 8
#define ARDUINO2_TX 9

SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
SoftwareSerial mySerial2(ARDUINO2_RX, ARDUINO2_TX);
//all the commands needed in the datasheet(http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf)
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
                                //0X7E FF 06 command 00 00 00 EF;(if command =01 next song order) 
#define NEXT_SONG 0X01 
#define PREV_SONG 0X02 
#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)
#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X1E //DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
#define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B
#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED
#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3
#define STOP_PLAY 0X16
#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)
#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close
#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output

const int buttonPin = 2;
const int buttonPin2 = 3;
int buttonState;
int buttonState2;
//int lastButtonState = LOW;
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
unsigned long startMillis2;  //some global variables available anywhere in the program
unsigned long currentMillis2;
const unsigned long period = 25;  //the value is a number of milliseconds


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

void sendCommand2(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++)//
{
  mySerial2.write(Send_buf[i]) ;
}
}


void setup() {

mySerial.begin(9600);//Start our Serial coms for our serial monitor!
delay(500);//Wait chip initialization is complete
sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card   
delay(200);//wait for 200ms  // put your setup code here, to run once:
mySerial2.begin(9600);
delay(500);
sendCommand2(CMD_SEL_DEV, DEV_TF);
delay(200);
 pinMode(buttonPin, INPUT_PULLUP);
 pinMode(buttonPin2, INPUT_PULLUP);
   startMillis = millis();  //initial start time
   startMillis2 = millis();
}

void loop() {

int reading = digitalRead(buttonPin);
int reading2 = digitalRead(buttonPin2);


if ( reading == LOW ) {
  startMillis = millis();

  if (buttonState == 0) {
    mySerial.write(0x7E);
    mySerial.write(0xFF);
    mySerial.write(0x06);
    mySerial.write(0x01);
    mySerial.write((byte)0x00);
    mySerial.write((byte)0x00);
    mySerial.write((byte)0x00);
    mySerial.write(0xEF);
    //sendCommand(CMD_PLAY_W_INDEX, 002);
    //0X7E FF 06 command 00 00 00 EF
    buttonState = 1;
  }
}

else {
  currentMillis = millis();
  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    buttonState = 0;
  }
}

if ( reading2 == LOW ) {
  startMillis2 = millis();

  if (buttonState2 == 0) {
    //mySerial2.write(0x7E);
    //mySerial2.write(0xFF);
    //mySerial2.write(0x06);
    //mySerial2.write((byte)0x01);
    //mySerial2.write((byte)0x00);
    //mySerial2.write((byte)0x00);
    //mySerial2.write((byte)0x00);
    //mySerial2.write(0xEF);
    sendCommand2(NEXT_SONG, 0x0000);
    //CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
    buttonState2 = 1;
  }
}

else {
  currentMillis2 = millis();
  if (currentMillis2 - startMillis2 >= period)  //test whether the period has elapsed
  {
    buttonState2 = 0;
  }
}


}

xl97

Perhaps try one of the current available libraries out there.. and see if they same things happen

Could be a hex value (command) setting or something?

but it should rule out the software/code question

Go Up