Controlling MP3 player with serial commands

Hello!

I an trying to send serial commands to a MP3 player using the Tx and Rx pins.

I have been able to get data from the player and display it in the Serial monitor, if I trigger the player by physical connetions.

But I can't send it commands.
According to the documentation I should send "PF: 10000" to play the file "10000.mp3".
It should then send a resonse back "PLAYING 10000.mp3".

But I think i am getting confusion when trying to read and write serial data at the same time.

So how can i send a command and wait for a resonse, and write it to the serial monitor only?
I think waht happens now is, that when I try to write to the serial monitor, I also write to the MP3 player.

So how can i:

  1. send a serial command to the mp3 player
  2. get a response back and
  3. write that to the serial monitor?

my code so far:

char incomingByte;	// for incoming serial data


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


}

 


void loop() {

聽 // Send play command to MP3 via Tx
 Serial.write("PF:10000");


聽 聽 //READ REPSONSE FROM聽 MP3 player
聽 聽 	// send data only when you receive data:
	while (Serial.available() > 0) {
聽 聽 聽 聽 聽 聽 聽 
		// read the incoming byte:
		incomingByte = Serial.read();
聽 聽 聽 聽 聽 聽 聽 聽 
		// say what you got:
		//Serial.print("I received: ");
		Serial.print(incomingByte);

	}


//WAit 5 sec, and play again

delay(5000);
}

Hm. OK, but if I disconnect the USB, disable code that write to the monitor and use external power; should it then automatically connect to the MP3 player?
Will the onboard Tx and Rx LEDs blink when communicating with the player?

And I just need to find a different way to indicate that I got a response?

I am using the arduino Uno. Smb version. The one with the tiny chip and not the big chip.

Thanks for your help! :slight_smile:

Ok I got the New Software Library working. :slight_smile:

But i often get garbage in the messages, and I think that mess up the reliability.
But generally I can read the incomming messages from the player inbetween the garbage.

It was more stable in the standard Tx an Rx pins.

How can "filter out" the garbage?

My Code

#include <NewSoftSerial.h>

#define rxPin 2
#define txPin 3


char incomingByte;	// for incoming serial data
boolean isPlaying = false;
NewSoftSerial mySerial(rxPin, txPin);


void setup()聽 {
聽 // define pin modes for tx, rx, led pins:
聽 pinMode(rxPin, INPUT);
聽 pinMode(txPin, OUTPUT);

 Serial.begin(9600);
 mySerial.begin(9600);

 pinMode(8, INPUT);

}




void loop() {


聽 聽 if ((digitalRead(8) == HIGH) && (isPlaying==false)) {
聽 聽 聽 聽 playAudio();
聽 聽 }
聽 聽 
聽 聽 if ((digitalRead(8) == HIGH) && (isPlaying==true)) {
聽 聽 聽 fadeOut();
聽 聽 }

聽  //READ RESPONSE FROM聽 MP3 player
聽 聽 // send data only when you receive data:
聽 while (mySerial.available() > 0) {

	// read the incoming byte:
	incomingByte = mySerial.read();
聽 聽 聽 聽 聽 聽 聽 聽 
	// say what you got:
聽 聽 聽  
	Serial.print(incomingByte);

	}


}

void playAudio() {
mySerial.flush();
 mySerial.println("PF 10007");
 
 isPlaying = true;
 delay(500);
}
 
void fadeOut() {
聽 //Fade out
聽  mySerial.flush();
聽  mySerial.println("FO");
 
聽  delay(1000);
聽  // Stop file
聽  mySerial.flush();
聽  mySerial.println("SP");
聽  
聽 isPlaying = false;
}

My Garbage

F`每n每
?II=I茅聛陋r颅鹿陆脻鹿聛
陆碌碌?鹿?5)R镁聽每
Q%=9茅聛?垄陆脕脕??5)
垄?玫脢J*r?聛陆?聛?楼卤?5)R镁@每`每00)每PLAY: 10007.MP3

媒篓H(jU脭脢J?垄陆脕脕??5)
垄?玫脢J*r?聛陆?聛?楼卤?5)R镁聛每`每`每7
PLAY: 10007.MP3

SP

ACTION: Stopped
ACTION: End of file

@每`每007每PLAY: 10007.MP3

SP

ACTION: Stopped
ACTION: End of file

ACTION: End of file

Thanks