Hi, I am using
- Arduino Mega
- OPEN-SMART Serial MP3 Player
I want the Arduino to do something "as long as" a song is playing (for instance light a led), and stop it once the song finished.
I wrote the following code and it seems to successfully play audio:
// Include required libraries:
#include <SoftwareSerial.h>
// Define the RX and TX pins to establish UART communication with the MP3 Player Module.
#define MP3_RX 15 // to TX
#define MP3_TX 14 // to RX
// Define the Serial MP3 Player Module.
SoftwareSerial MP3(MP3_RX, MP3_TX);
///////////////////////////////////////////////////////////////////////////////////////////////////
static int8_t play_song[] = {0x7e, 0x04, 0x42, 0x01, 0x05, 0xef}; // 7E 04 41 00 01 EF, 5th Song
static int8_t player_status[] = {0x7e, 0x02, 0x10, 0xef};
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef};
//// Play the song.
//static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
//static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF
void send_command_to_MP3_player(int8_t command[],int8_t len){
Serial.print("\nMP3 Command => ");
for(int i=0;i<len;i++){
MP3.write(command[i]);
Serial.print(command[i], HEX);
}
Serial.println();
}
void get_status() {
if (MP3.available())
{
char player_status;
Serial.println("MP3.available is True");
send_command_to_MP3_player(player_status, 4);
for (int i = 0; i < 8; i++) {
while (!MP3.available()); // wait for a character
player_status = MP3.read();
Serial.print(player_status, HEX);
}
Serial.println();
} else {
Serial.println("MP3.available is False");
}
}
void setup() {
Serial.begin(9600);
// Initiate the Serial MP3 Player Module.
MP3.begin(9600);
send_command_to_MP3_player(select_SD_card, 5);
}
void loop() {
///////////////////////////////////////////////////
get_status();
delay(500);
send_command_to_MP3_player(play_song, 6);
delay(500);
get_status();
delay(5000);
}
However, I'm not quite sure how to check the status of the MP3 player.
According to the manual I need to write "7E 02 10 EF". I tried to as suggested here - this is the get_status()
function.
However, MP3 is always not available even if a song is playing.
What am i missing? Is there an easier way to achieve what i need?
Thanks in advance
EDIT -
Adding the part in the manual referring to checking the status.