Pages: [1]   Go Down
Author Topic: How to send command to MP3 Shield?  (Read 588 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am a total newb and need a simple answer since I can't seem to figure this out our unfortunately get any support from the vendor (probably since I am asking such a ridiculous question).  Could someone please stop laughing long enough to point me in the right direction and let me know how I send commands to the mp3 shield from my computer?  Do I open up the serial monitor within the Arduino software and type the commands in the top line then press send?  Could someone take a peek at this guide toward bottom of page 8?  http://www.elechouse.com/elechouse/images/product/Arduino%20MP3%20Shield/Arduino%20MP3%20Shield%20User%20Guide.pdf

For example this is what is in the guide to play a file from the sd card (toward bottom of page eight).  Do I type what's below in the top line of the serial monitor and then press send (it doesn't seem to work)?

0x7E 0x04 0xA0 00 02 0x7E

Thanks for your help.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27113
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So you have some version of their example file running?
Code:
#include <SoftwareSerial.h>
#include <MP3.h>

/** define mp3 class */
MP3 mp3;

void setup()
{
  /** begin function */
  mp3.begin(MP3_SOFTWARE_SERIAL);    // select software serial
//  mp3.begin();                       // select hardware serial(or mp3.begin(MP3_HARDWARE_SERIAL);)
 
  /** set volum to the MAX */
  mp3.volume(0x1F);
 
  /** set MP3 Shield CYCLE mode */
  mp3.set_mode(MP3::CYCLE);
 
  /** play music in sd, '0001' for first music */
  mp3.play_sd(0x0001);
 
  /** play music in USB-disk */
  //mp3.play_usb_disk(0x0001);
 
  /** play music in SPI FLASH */
  //mp3.play_spi_flash(0x0001);
}

void loop()
{
/** function code here */
}
and you've written some code to send the commands you referenced to the board?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick reply.  Now that you mention it I was using the example code but it does not look like there's any commands in the example sketch (told you I was a newb!).  I was also trying this other example code below which plays the songs automatically but I was unable to send any "play, pause, next" commands.  Would you know how I could control the mp3 shield from my computer?  

Code:
//..............................................................................
// Mohannad Rawashdeh
// MP3 1.2V Shield test .
#include <SoftwareSerial.h>
SoftwareSerial Geno(7,8); // Rx , Tx
unsigned char Data[10];
unsigned char i;

void setup() {
  // put your setup code here, to run once:
  Geno.begin(9600);
  SetVolume(20); // set volume from 0-31
  delay(1000);
  FileSource('SD_card',0x05);
  SetPlayMode('Single_play');
  delay(5000);
  play_pause();// Pause
  delay(3000);
  FileSource('SD_card',0x01);
  play_pause(); // play
  delay(5000);
  Next();
  delay(5000);
  Next();
  for(int v=15;v>0;v--){
  SetVolume(v); // set volume from 0-31
  delay(1000);
  }
  for(int j=0;j<15;j++){
  SetVolume(j); // set volume from 0-31
  delay(500);
  }
  delay(1000);
  FileSource('SD_card',0x04);
  delay(5000);
  FileSource('SD_card',0x05);
// FileSource('SD_card',0x03);
 
  //Stop();
}

void loop() {
  // put your main code here, to run repeatedly:
 
}
// Select File sorce "SD Card, SPI Flash , U Disk "
void FileSource( char type, byte track ){
  play_pause();// Pause
   Data[0] = 0x7E;
   Data[5] = 0x7E;   
  switch (type){
   case 'SD_card':
          // START
    Data[1] = 0x04;          // Length
    Data[2] = 0xA0;          // Command
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;          // file number low byte
    break;
    case 'SPI_Flash':
    Data[1] = 0x04;          // Length
    Data[2] = 0xA1;          // Command spi flash 0XA1
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;
   break;
    case 'U_Disk':
    Data[1] = 0x04;          // Length
    Data[2] = 0xA2;          // Command
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;          // file number low byte
    break;
 
  }
  Command(Data,5);
  play_pause();// Pause
}

void SetVolume( int vol){
   Data[0] = 0x7E;          // START
   Data[1] = 0x03;          // Length Not 0x02
   Data[2] = 0xA7;          // Command
   Data[3] = vol;          // new volume
   Data[4] = 0x7E;          // END
   Command(Data,5);
}

void SetPlayMode(char type){
   Data[0] = 0x7E;          // START
   Data[4] = 0x7E;          // START
   switch (type){
   case 'Single_play':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x00;          //Mode parameter
   break;
   case 'Repeat_single':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x01;          //Mode parameter
   break;
   case 'Repeat_all':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x02;          //Mode parameter
   break;
   case 'Play_Random':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x03;          //Mode parameter
   break;
}
Command(Data,5);
}
//...............................

void play_pause(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA3;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

  void Stop(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA4;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

  void Next(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA5;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}
  void Previous(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA6;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

void Command(unsigned char *Data, int length){
    for(int i=0; i<length; i++){
    Geno.write(Data[i]);
    }
 
}
« Last Edit: November 10, 2013, 01:40:41 pm by FSUDAL » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27113
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

From your computer, you would send the bytes to the arduino.
The arduino would receive them and send them to the shield.

So for this 6 byte command

0x7E 0x04 0xA0 0x00 0x02 0x7E

you might have
Code:
void loop(){
if (Serial.available()>5){ // 6 or more bytes received?
byte0 = Serial.read(); // read 1st byte
if (byte0 == 0x7E){   // and then the rest if a valid start byte came in
commandArray[0] = byte0
commandArray[1] = Serial.read();
commandArray[2] = Serial.read();
commandArray[3] = Serial.read();
commandArray[4] = Serial.read();
commandArray[5] = Serial.read();

// now send the bytes to the shield using its library commands
...
// all done, go back to looking for PC commands
}
} // end loop
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again for your help!  I am getting the following errors;

     sketch_nov10a.cpp: In function 'void loop()':
     sketch_nov10a:46: error: 'byte0' was not declared in this scope
     sketch_nov10a:48: error: 'commandArray' was not declared in this scope
     sketch_nov10a:56: error: expected primary-expression before '...' token
     sketch_nov10a:56: error: expected `;' before '...' token

Would you know the proper format for declaring the above?

Here's what my code looks like after entering in your suggestion;

Code:
//..............................................................................
// Mohannad Rawashdeh
// MP3 1.2V Shield test .
#include <SoftwareSerial.h>
SoftwareSerial Geno(7,8); // Rx , Tx
unsigned char Data[10];
unsigned char i;

void setup() {
  // put your setup code here, to run once:
  Geno.begin(9600);
  SetVolume(20); // set volume from 0-31
  delay(1000);
  FileSource('SD_card',0x05);
  SetPlayMode('Single_play');
  delay(5000);
  play_pause();// Pause
  delay(3000);
  FileSource('SD_card',0x01);
  play_pause(); // play
  delay(5000);
  Next();
  delay(5000);
  Next();
  for(int v=15;v>0;v--){
  SetVolume(v); // set volume from 0-31
  delay(1000);
  }
  for(int j=0;j<15;j++){
  SetVolume(j); // set volume from 0-31
  delay(500);
  }
  delay(1000);
  FileSource('SD_card',0x04);
  delay(5000);
  FileSource('SD_card',0x05);
// FileSource('SD_card',0x03);
 
  //Stop();
}

void loop() {

  // put your main code here, to run repeatedly:

if (Serial.available()>5){ // 6 or more bytes received?
byte0 = Serial.read(); // read 1st byte
if (byte0 == 0x7E){   // and then the rest if a valid start byte came in
commandArray[0] = byte0;
commandArray[1] = Serial.read();
commandArray[2] = Serial.read();
commandArray[3] = Serial.read();
commandArray[4] = Serial.read();
commandArray[5] = Serial.read();

// now send the bytes to the shield using its library commands
...
// all done, go back to looking for PC commands
}
} // end loop
 
}
// Select File sorce "SD Card, SPI Flash , U Disk "
void FileSource( char type, byte track ){
  play_pause();// Pause
   Data[0] = 0x7E;
   Data[5] = 0x7E;   
  switch (type){
   case 'SD_card':
          // START
    Data[1] = 0x04;          // Length
    Data[2] = 0xA0;          // Command
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;          // file number low byte
    break;
    case 'SPI_Flash':
    Data[1] = 0x04;          // Length
    Data[2] = 0xA1;          // Command spi flash 0XA1
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;
   break;
    case 'U_Disk':
    Data[1] = 0x04;          // Length
    Data[2] = 0xA2;          // Command
    Data[3] = 0x00;          // file number high byte
    Data[4] = track;          // file number low byte
    break;
 
  }
  Command(Data,5);
  play_pause();// Pause
}

void SetVolume( int vol){
   Data[0] = 0x7E;          // START
   Data[1] = 0x03;          // Length Not 0x02
   Data[2] = 0xA7;          // Command
   Data[3] = vol;          // new volume
   Data[4] = 0x7E;          // END
   Command(Data,5);
}

void SetPlayMode(char type){
   Data[0] = 0x7E;          // START
   Data[4] = 0x7E;          // START
   switch (type){
   case 'Single_play':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x00;          //Mode parameter
   break;
   case 'Repeat_single':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x01;          //Mode parameter
   break;
   case 'Repeat_all':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x02;          //Mode parameter
   break;
   case 'Play_Random':
   Data[1] = 0x02;          // Length
   Data[2] = 0xA9;          // Command
   Data[3] = 0x03;          //Mode parameter
   break;
}
Command(Data,5);
}
//...............................

void play_pause(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA3;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

  void Stop(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA4;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

  void Next(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA5;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}
  void Previous(){
  Data[0] = 0x7E;          // START
  Data[1] = 0x02;          // Length
  Data[2] = 0xA6;          // Command
  Data[3] = 0x7E;          //Mode parameter
  Command(Data,4);
}

void Command(unsigned char *Data, int length){
    for(int i=0; i<length; i++){
    Geno.write(Data[i]);
    }
 
}
Logged

Pages: [1]   Go Up
Jump to: