DFPlayer wont start playing on startup

The player only starts working when I press the 'Next' button. I want it to start playing straight after I turn it on. I included player.play(1); in the setup, but it won't work. Also I wanted to set the initial volume, but that doesn't work either. (player.volume(10);)

I have a folder called '01' and two files: 001.mp3 and 002.mp3 in that folder.

Here's the full code:

//-----------------------------------------------------------------------
//DFPlayer: Mini mp3 Player
//Library by: Angelo qiao: https://github.com/DFRobot/DFRobotDFPlayerMini
//-----------------------------------------------------------------------
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
//---------------------------------------------------
SoftwareSerial softwareSerial(10, 11);
DFRobotDFPlayerMini player;
//===========================================================

void setup()
{
  pinMode(2,INPUT); pinMode(3,INPUT); pinMode(4,INPUT);
  pinMode(5,INPUT); pinMode(6,INPUT); pinMode(7,INPUT);
  pinMode(9,OUTPUT);
  //---------------------------------------------------
  softwareSerial.begin(9600);
  player.begin(softwareSerial);
  player.volume(10);
  player.play(1); 
}
//===========================================================
void loop()
{
  if(digitalRead(5) == HIGH) player.volumeUp();
  if(digitalRead(6) == HIGH) player.volumeDown();
  //---------------------------------------------------
  if(digitalRead(2) == HIGH)
  {
    delay(200); player.next();
  }
  //---------------------------------------------------
  if(digitalRead(3) == HIGH)
  {
    delay(200); player.previous();
  }
  //---------------------------------------------------
  if(digitalRead(4) == HIGH)
  {
    delay(200);
    digitalWrite(9, HIGH);
     player.pause();
    while(1)
    {
     
      if(digitalRead(4) == HIGH) {player.start(); break;}
    }
    digitalWrite(9, LOW);
  }
}


Since the Next button works, the DFplayer is up and running. The Arduino just can't communicate with it. The problem is likely in your wiring. Please show us a schematic. A clearly drawn pen and paper one is perfectly acceptable.

I'm using the arrangement below, but I swapped the 10k resistor in the RX line with a 1k one as the specs shows for the DFplayer. It didn't work with the 10k one. Also I didn't connect anything to the pin where a 'pause' LED supposed to be.

Oh, you're not using the Next button on the DFplayer? So the Arduino can communicate with the DFplayer, just not at startup. Try adding a delay(2000); between player.begin(...) and player.volume(...). It may be that the DFplayer simply takes a bit longer to start up than the Arduino.

Then you have to specify the folder.
Your sketch as posted is structured for having everything in the root directory (no folder).

It looks like my file structure was the issue. I placed those files in the root folder, and it started working. Adding delay was a good idea too, but luckily it's not necessary.

Now the only issue is the pause button, as it's very fiddly and hard to operate, but I guess it's something to do with the timings.

Thanks both of you for the help.

the pause button is the easiest part:
define this in the beginning:
bool Pause = false;
and use that in the loop:

// pause/play Button
  if (button_b.released()) {
    if (busyState == LOW) {
      Pause = true;
      myDFPlayer.pause(); // pause if playing
      digitalWrite(LEDb, HIGH);
    }
    else {
      Pause = false;
      myDFPlayer.start(); // start if not playing
      digitalWrite(LEDb, LOW);
    }
  }

Attention: I use the busy pin of the player to check if playing or not. You can do that with a variable as well. Just reading the status of the player is not very reliable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.