Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading Command: How to receive returning data from the shield #2

Open
sonhan opened this issue Feb 26, 2014 · 4 comments
Open

Reading Command: How to receive returning data from the shield #2

sonhan opened this issue Feb 26, 2014 · 4 comments

Comments

@sonhan
Copy link

sonhan commented Feb 26, 2014

The library is lacking the functions with returning values such as check status, check volume, check number of files. One possible is to enable Arduino RX interrupt, isn't it?

@JiapengLi
Copy link

Hardware Serial:
Use Serial.available(); to check if there is data in RX buffer, use Serial.read() to read serial data.
Check the user manual to see the format of the return value.

Software Serial:
Add extern SoftwareSerial COM_SOFT; to Arduino example.
Use COM_SOFT.available(); to check if there is data in RX buffer, use COM_SOFT.read() to read serial data.

@sonhan
Copy link
Author

sonhan commented Feb 28, 2014

I tried with following code to check the playing status (Check Work State) but the output always is ~�Ã~status test


unsigned char cmd_buf[10];
unsigned char i;

void ArduinoMP3Shield_SendCMD(unsigned char *cmd_buf, unsigned len)
{
    unsigned i;
    for(i=0; i<len; i++){
        Serial.write(cmd_buf[i]);
    }
}

void setup(void)
{
    /** wait until arduino mp3 shield get ready */
    delay(1000);

    Serial.begin(9600);

    /** set volume */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x03;          // Length
    cmd_buf[2] = 0xA7;          // Command
    cmd_buf[3] = 0x0F;          // new volume
    cmd_buf[4] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 5);

    /** set play mode repeat all */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x03;          // Length
    cmd_buf[2] = 0xA9;          // Command SET MODE
    cmd_buf[3] = 0x00;          // set mode
    cmd_buf[4] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 5);

    /** select SD card first music and play */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x04;          // Length
    cmd_buf[2] = 0xA0;          // Command
    cmd_buf[3] = 0x00;          // file number high byte
    cmd_buf[4] = 0x03;          // file number low byte
    cmd_buf[5] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 6);
}

void loop(void)
{
  delay(2000);
  Serial.println("status test");  
  cmd_buf[0] = 0x7E;
  cmd_buf[1] = 0x02;
  cmd_buf[2] = 0xC3;
  cmd_buf[3] = 0x7E;
  ArduinoMP3Shield_SendCMD(cmd_buf, 4);
  if(Serial.available()) {
      byte c = Serial.read();
      if (c == 0x01) Serial.println("playing");
      else if (c == 0x02) Serial.println("stop");
      else if (c == 0x02) Serial.println("pause");
      else Serial.println("nothing");
  }
}

@sonhan
Copy link
Author

sonhan commented Feb 28, 2014

Sorry here is the code and output is always (no matter it is playing or not or pause)

status test
�Ânothing
status test
�Âstop
status test
�Ânothing
status test
�Âstop
status test
�Ânothing
status test
�Âstop


unsigned char cmd_buf[10];
unsigned char i;

void ArduinoMP3Shield_SendCMD(unsigned char *cmd_buf, unsigned len)
{
    unsigned i;
    for(i=0; i<len; i++){
        Serial.write(cmd_buf[i]);
    }
}

void setup(void)
{
    /** wait until arduino mp3 shield get ready */
    delay(1000);

    Serial.begin(9600);

    /** set volume */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x03;          // Length
    cmd_buf[2] = 0xA7;          // Command
    cmd_buf[3] = 0x0F;          // new volume
    cmd_buf[4] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 5);

    /** set play mode repeat all */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x03;          // Length
    cmd_buf[2] = 0xA9;          // Command SET MODE
    cmd_buf[3] = 0x00;          // set mode
    cmd_buf[4] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 5);

    /** select SD card first music and play */
    cmd_buf[0] = 0x7E;          // START
    cmd_buf[1] = 0x04;          // Length
    cmd_buf[2] = 0xA0;          // Command
    cmd_buf[3] = 0x00;          // file number high byte
    cmd_buf[4] = 0x03;          // file number low byte
    cmd_buf[5] = 0x7E;          // END
    ArduinoMP3Shield_SendCMD(cmd_buf, 6);
}

void loop(void)
{
  delay(1000);
  Serial.println("status test");  
  cmd_buf[0] = 0x7E;
  cmd_buf[1] = 0x02;
  cmd_buf[2] = 0xC2;
  cmd_buf[3] = 0x7E;
  ArduinoMP3Shield_SendCMD(cmd_buf, 4);
  if(Serial.available()) {
      byte c = Serial.read();
      if (c == 0x01) Serial.println("playing");
      else if (c == 0x02) Serial.println("stop");
      else if (c == 0x03) Serial.println("pause");
      else Serial.println("nothing");
  }
}

@sonhan
Copy link
Author

sonhan commented Feb 28, 2014

And if I read 02 bytes (command, value) the output is always nothing

void loop(void)
{
  delay(1000);
  Serial.println("status test");  
  cmd_buf[0] = 0x7E;
  cmd_buf[1] = 0x02;
  cmd_buf[2] = 0xC2;
  cmd_buf[3] = 0x7E;
  ArduinoMP3Shield_SendCMD(cmd_buf, 4);
  if(Serial.available()) {
      byte command = Serial.read();  
      byte value = Serial.read();
      if (value == 0x01) Serial.println("playing");
      else if (value == 0x02) Serial.println("stop");
      else if (value == 0x03) Serial.println("pause");
      else Serial.println("nothing");
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants