DFPlayer mp3 - can't stop it auto-playing on power up

Can't think what I'm missing here - this DFPlayer (attached to an Arduino) won't stop playing mp3s on first power-up. It functions normally after that.

Anyone else found this "feature"?

Post your code.... we'll take a look.

I have been playing with these modules a lot over the last 2-3 weeks..

And while I have found some oddities... none of them were playing a file upon start up. (without being told to do so!)

Thanks, xl97! Here we go:

///              MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////

#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

# define ACTIVATED LOW

int buttonOne = 2;
int buttonTwo = 3;
int buttonThree = 4;
int buttonLidOpen = 5;
boolean isPlaying = false;

void setup () {
  pinMode(buttonOne, INPUT);
  digitalWrite(buttonOne, HIGH);
  pinMode(buttonTwo, INPUT);
  digitalWrite(buttonTwo, HIGH);
  pinMode(buttonThree, INPUT);
  digitalWrite(buttonThree, HIGH);
  pinMode(buttonLidOpen, INPUT);
  digitalWrite(buttonLidOpen, HIGH);
  mySerial.begin (9600);
  delay(1000);
  doInit();
}

void setVolume(int volume) {
  execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
  delay(2000);
}

void doInit() {
  execute_CMD(0x3F, 0, 0);
  delay(500);
  setVolume(30);
  delay(500);
}


void loop () {
  if (digitalRead(buttonThree) == ACTIVATED) {
    if (isPlaying == false) {
      playThird();
      isPlaying = true;
    }
  }
  if (digitalRead(buttonTwo) == ACTIVATED) {
    if (isPlaying == false) {
      playSecond();
      isPlaying = true;
    }
  }
  if (digitalRead(buttonOne) == ACTIVATED) {
    if (isPlaying == false) {
      playFirst();
      isPlaying = true;
    }
  }
  if (digitalRead(buttonOne) != ACTIVATED && digitalRead(buttonTwo) != ACTIVATED && digitalRead(buttonThree) != ACTIVATED)
  {
    stop();
    isPlaying = false;
  }
}


void playFirst()
{
  execute_CMD(0x03, 0, 1);
  delay(500);
}

void playSecond()
{
  execute_CMD(0x03, 0, 2);
  delay(500);
}

void playThird()
{
  execute_CMD(0x03, 0, 3);
  delay(500);
}



void stop()
{
  execute_CMD(0x16, 0, 0);
  delay(500);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
  // Calculate the checksum (2 bytes)
  word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
  // Build the command line
  byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
                            Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte
                          };
  //Send the command line to the module
  for (byte k = 0; k < 10; k++)
  {
    mySerial.write( Command_line[k]);
  }
}

Thanks...

oh.. your directly sending hex values for the commands? (and manually doing the checksum?)

Is there a reason why? Or a specific reason why you are not using the DFRobot library?

(with pre-defined functions like play() and loop() or next() and previous()?)...etc

You can.. just curious.

https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

p.s it seems to function correctly otherwise, it's just that it insists on playing through all three of the very short (2 seconds long) mp3s I have on the card. Then it stops and behaves as I'd expect it to.

Ah, um, that'd be because I found the source code online and modified it but I really don't know what i'm doing! I will certainly have a look at the DFRobot library.

I would.

I think it'll make your life WAY easier!

doing something like myDFPlayer.play(#) is much easier... :slight_smile:

Only I can see is perhaps the doInit() command?

maybe something like this (once you have the library included)

** not tested.. (I'm at work)

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

int buttonOne = 2;
int buttonTwo = 3;
int buttonThree = 4;
int buttonLidOpen = 5;
boolean isPlaying = false;

DFRobotDFPlayerMini myDFPlayer;
SoftwareSerial myDFPlayerSerialConn(7, 8);



void setup () {
	//debug (monitor)
	Serial.begin(115200);
	//talk to DFPlayer
	myDFPlayerSerialConn.begin(9600);
	
	Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
	if (!myDFPlayer.begin(myDFPlayerSerialConn)) {
		Serial.println(F("Unable to begin:"));
		Serial.println(F(" - Please recheck the connection!"));
		Serial.println(F(" - Please insert the SD card!"));
		while (true);
	}

	//DFPlayer properties
	Serial.println(F("DFPlayer Mini online."));
	myDFPlayer.setTimeOut(500);
	myDFPlayer.volume(7);
	myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
	myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);

	//button 1
	pinMode(buttonOne, INPUT);
	digitalWrite(buttonOne, HIGH);
	//button 2
	pinMode(buttonTwo, INPUT);
	digitalWrite(buttonTwo, HIGH);
	//button 3
	pinMode(buttonThree, INPUT);
	digitalWrite(buttonThree, HIGH);
	//lid switch
	pinMode(buttonLidOpen, INPUT);
	digitalWrite(buttonLidOpen, HIGH);
	
	delay(1000);

}


void loop () {
	if (digitalRead(buttonThree) == ACTIVATED) {
		if (isPlaying == false) {
			isPlaying = true;
			myDFPlayer.play(3);
		}
	}
  
	if (digitalRead(buttonTwo) == ACTIVATED) {
		if (isPlaying == false) {
			isPlaying = true;
			myDFPlayer.play(2);
		}
	}
  
	if (digitalRead(buttonOne) == ACTIVATED) {
		if (isPlaying == false) {
			isPlaying = true;
			myDFPlayer.play(1);
		}
	}
  
	if (digitalRead(buttonOne) != ACTIVATED && digitalRead(buttonTwo) != ACTIVATED && digitalRead(buttonThree) != ACTIVATED){
		myDFPlayer.stop();
		isPlaying = false;
	}
}

Thank you!

Your code works fine but doesn't stop the problem, unfortunately. This DFPlayer just starts playing the moment it receives power and won't stop until the Arduino has booted up and told it to. It appears to agree with the comment on the line:

Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

Does that seem right to you?

Also, have you found that you need to disconnect the RX and TX pins when uploading to the Arduino for it to work?

*hmm…

I dont believe I disconnect my RX/TX lines when updating (loading a new sketch) to my Arduino.

How are you ‘powering it’?

I think I have been either using a fixed +5v regulator… or in some cases/test… the VIN/VCC pin of the Arduino (sometimes UNO, sometimes Pro-Mini)

You should only have:
RX (through 1K resistor)
TX (through 1K resistor)
POWER
GROUND
SPEAKER 1
SPEAKER 2
(off the top of my head)
connected to anything.

Wondering if you have a pin grounded or something? triggering the button only mode type of playback?

If the playback is triggered by this:
Serial.println(F(“Initializing DFPlayer … (May take 3~5 seconds)”));

Then… no that does NOT seem correct to me.

(thats a serial print line for the serial monitor… not even directed at the DFPlayer)

Both boards should be powered at the same time…and the Arduino should set up all default params for it.

Can you post a pick of your set-up and wiring?

I just quoted that line because it mentions “May take 3~5 seconds” which seems to be the time it takes before the Arduino tells the DFPlayer to shut up.

It’s all badly wired together at the moment so these pictures may not help very much but attached anyway.

I’ve also ordered another DFPlayer this morning in case this one is just plain faulty.

No pics attached. :slight_smile:

ALso.. what color led does yrou player have? (just curious)..

I have some with red and some with blue... the blue ones (I feel) are more current, work better, and seem to be able to use the most recent DFRobot library... while the red led variants, do NOT work with all commands in the new DFRobot library.

Currently.. my best guess is that one of the I/O pins of being triggered

They should be attached now - the forum first refused the pics because they were too big so I resized them by which time the forum had decided I'd posted too many times in the past five minutes.

It's a blue LED.

Wow. So your last comment - “that one of the I/O pins of being triggered” - just made me take a much closer look at the board where I saw that a there was a trace of stray solder shorting the bottom-right two pins - GND and IO_1. A manufacturing defect I think, since I’ve not been anywhere near this board with a soldering iron yet. You might just be able to make it out in the attached.

I scraped it away with a scalpel and now it’s functioning correctly.

Some sort of lesson learned! Thank you for your patience and your code and sorry for wasting your time.

Solder.jpg

Glad it all worked out.