DFPlayer Mini with Adafruit Feather 32u4

I am having an issue trying to get the Feather to connect with a DFPlayer Mini. Using any of the supplied example code from the Libraries does not work.

I receive back the message:
"Not initialized:

  1. Check the DFPlayer Mini connections
  2. Insert an SD card"

Here is a picture of the circuit:

This is the example code I'm referencing. It's a modified version of the Library example. I'm using pins 10 and 11 for RX and TX, but not sure if that's possible or right? I also added a ground from the "Busy" pin on the DF Player to GND, as one video I saw said that it turned on the LED (just so I could see if the board was even working)?

//Very much inspired by https://www.dfrobot.com/blog-1462.html by DFRobot Feb 26 2020
//Additions made by Just Baselmans https://www.youtube.com/justbaselmansYT Jan 23 2023

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

// Initialize software serial on pins 10 and 11
SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;
String line;
char command;
int pause = 0;
int repeat = 0;

void setup() {
  // Serial communication with the module
  mySoftwareSerial.begin(9600);
  // Initialize Arduino serial
  Serial.begin(115200);
  // Check if the module is responding and if the SD card is found
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini"));
  Serial.println(F("Initializing DFPlayer module ... Wait!"));

  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println(F("Not initialized:"));
    Serial.println(F("1. Check the DFPlayer Mini connections"));
    Serial.println(F("2. Insert an SD card"));
    while (true)
      ;
  }
  Serial.println();
  Serial.println(F("DFPlayer Mini module initialized!"));
  // Initial settings
  myDFPlayer.setTimeOut(500);  // Serial timeout 500ms
  myDFPlayer.volume(5);        // Volume 5
  myDFPlayer.EQ(0);            // Normal equalization
  //  myDFPlayer.EQ(DFPLAYER_EQ_POP);
  //  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
  //  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
  //  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
  //  myDFPlayer.EQ(DFPLAYER_EQ_BASS);
  menu_options();
}

void loop() {
  // Waits for data entry via serial
  while (Serial.available() > 0) {
    command = Serial.peek();
    line = Serial.readStringUntil('\n');

    // Play from first 9 files
    if ((command >= '1') && (command <= '9')) {
      Serial.print("Music reproduction");
      Serial.println(command);
      command = command - 48;
      myDFPlayer.play(command);
      menu_options();
    }

    //Play from specific folder
    if (command == 'f') {
      int indexF = line.indexOf('f');
      int indexS = line.indexOf('s');
      if (indexF != -1 && indexS != -1 && indexF < indexS) {
        int folder = line.substring(indexF + 1, indexS).toInt();
        int song = line.substring(indexS + 1).toInt();
        Serial.print("From folder: ");
        Serial.print(folder);
        Serial.print(", playing song: ");
        Serial.println(song);
        myDFPlayer.playFolder(folder, song);  //play specific mp3 in SD:/folder/song.mp3; Folder Name(1~99); File Name(1~255)
      } else {
        Serial.println("Incomplete 'f' command. Specify both folder and song numbers.");
      }
      menu_options();
    }

    // Reproduction
    // Stop
    if (command == 's') {
      myDFPlayer.stop();
      Serial.println("Music Stopped!");
      menu_options();
    }

    // Pause/Continue the music
    if (command == 'p') {
      pause = !pause;
      if (pause == 0) {
        Serial.println("Continue...");
        myDFPlayer.start();
      }
      if (pause == 1) {
        Serial.println("Music Paused!");
        myDFPlayer.pause();
      }
      menu_options();
    }

    // Toggle repeat mode
    if (command == 'r') {
      repeat = !repeat;
      if (repeat == 1) {
        myDFPlayer.enableLoop();
        Serial.println("Repeat mode enabled.");
      } else {
        myDFPlayer.disableLoop();
        Serial.println("Repeat mode disabled.");
      }
      menu_options();
    }

    // Set volume
    if (command == 'v') {
      int myVolume = line.substring(1).toInt();
      if (myVolume >= 0 && myVolume <= 30) {
        myDFPlayer.volume(myVolume);
        Serial.print("Current Volume:");
        Serial.println(myDFPlayer.readVolume());
      } else {
        Serial.println("Invalid volume level, choose a number between 0-30.");
      }
      menu_options();
    }

    // Increases volume
    if (command == '+') {
      myDFPlayer.volumeUp();
      Serial.print("Current Volume:");
      Serial.println(myDFPlayer.readVolume());
      menu_options();
    }
    // Decreases volume
    if (command == '-') {
      myDFPlayer.volumeDown();
      Serial.print("Current Volume:");
      Serial.println(myDFPlayer.readVolume());
      menu_options();
    }

    // Play previouse
    if (command == '<') {
      myDFPlayer.previous();
      Serial.println("Previous:");
      Serial.print("Current track:");
      Serial.println(myDFPlayer.readCurrentFileNumber() - 1);
      menu_options();
    }

    // Play next
    if (command == '>') {
      myDFPlayer.next();
      Serial.println("Next:");
      Serial.print("Current track:");
      Serial.println(myDFPlayer.readCurrentFileNumber() + 1);
      menu_options();
    }
  }
}

void menu_options() {
  Serial.println();
  Serial.println(F("=================================================================================================================================="));
  Serial.println(F("Commands:"));
  Serial.println(F(" [1-9] To select the MP3 file"));
  Serial.println(F(" [fXsY] Play song from folder X, song Y"));
  Serial.println(F(" [s] stopping reproduction"));
  Serial.println(F(" [p] pause/continue music"));
  Serial.println(F(" [r] toggle repeat mode"));
  Serial.println(F(" [vX] set volume to X"));
  Serial.println(F(" [+ or -] increases or decreases the volume"));
  Serial.println(F(" [< or >] forwards or backwards the track"));
  Serial.println();
  Serial.println(F("================================================================================================================================="));
}

Thank you so much for any support!

Nothing is going to work until you solder those pins.

Thank you :). Yes, sorry, this was just the mockup of how they are connected. The board and the DF Player are getting power. Checked with a Multi-meter and the LED on the BUSY line lights up when connected to ground.

I am narrowing down the issue to either the RX TX communication or the SD Card. The SD Card is formatted on a Mac.

Unlike the Atmega 328 boards, a 32U4 board hast a hardware serial port addressed as Serial1 available on pins 0 and 1. There is no need to use software serial. Hardware serial is more reliable.

Did you use "SDcard.org" card formatter?

Did you try the DF Player Mini in I/O mode? (power+/-, speaker +/-, shorting wire)

Thank you for this! Is it possible to see a code example for this? When I've tried to use the Hardware serial in other examples, I get an error.

I referenced a similar post using something like below and changed the serial pins to 0 and 1 that the Feather board uses.

#include "HardwareSerial.h"
#include "DFRobotDFPlayerMini.h"

//
const byte RXD2 = 0;
const byte TXD2 = 1; 

HardwareSerial dfSD(1); // Use UART channel 1
DFRobotDFPlayerMini player;

I did, it was recommended in a video. I've reset the card 2-3 times just to be sure.

I have not tried it in I/O mode. I don't have a different power supply other than USB through the controller board. If I can track something down, I'll give it a go.

Use the 5V and GND from the Arduino (which is plugged into the USB port).

I think this is your code converted from software serial to Serial1.

//Very much inspired by https://www.dfrobot.com/blog-1462.html by DFRobot Feb 26 2020
//Additions made by Just Baselmans https://www.youtube.com/justbaselmansYT Jan 23 2023

//#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// Initialize software serial on pins 10 and 11
//SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;
String line;
char command;
int pause = 0;
int repeat = 0;

void setup() {
  // Serial communication with the module
  //mySoftwareSerial.begin(9600);
  Serial1.begin(9600);
  // Initialize Arduino serial
  Serial.begin(115200);
  // Check if the module is responding and if the SD card is found
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini"));
  Serial.println(F("Initializing DFPlayer module ... Wait!"));

  //if (!myDFPlayer.begin(mySoftwareSerial)) {
  if (!myDFPlayer.begin(Serial1)) { 
    Serial.println(F("Not initialized:"));
    Serial.println(F("1. Check the DFPlayer Mini connections"));
    Serial.println(F("2. Insert an SD card"));
    while (true)
      ;
  }
  Serial.println();
  Serial.println(F("DFPlayer Mini module initialized!"));
  // Initial settings
  myDFPlayer.setTimeOut(500);  // Serial timeout 500ms
  myDFPlayer.volume(5);        // Volume 5
  myDFPlayer.EQ(0);            // Normal equalization
  //  myDFPlayer.EQ(DFPLAYER_EQ_POP);
  //  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
  //  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
  //  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
  //  myDFPlayer.EQ(DFPLAYER_EQ_BASS);
  menu_options();
}

void loop() {
  // Waits for data entry via serial
  while (Serial.available() > 0) {
    command = Serial.peek();
    line = Serial.readStringUntil('\n');

    // Play from first 9 files
    if ((command >= '1') && (command <= '9')) {
      Serial.print("Music reproduction");
      Serial.println(command);
      command = command - 48;
      myDFPlayer.play(command);
      menu_options();
    }

    //Play from specific folder
    if (command == 'f') {
      int indexF = line.indexOf('f');
      int indexS = line.indexOf('s');
      if (indexF != -1 && indexS != -1 && indexF < indexS) {
        int folder = line.substring(indexF + 1, indexS).toInt();
        int song = line.substring(indexS + 1).toInt();
        Serial.print("From folder: ");
        Serial.print(folder);
        Serial.print(", playing song: ");
        Serial.println(song);
        myDFPlayer.playFolder(folder, song);  //play specific mp3 in SD:/folder/song.mp3; Folder Name(1~99); File Name(1~255)
      } else {
        Serial.println("Incomplete 'f' command. Specify both folder and song numbers.");
      }
      menu_options();
    }

    // Reproduction
    // Stop
    if (command == 's') {
      myDFPlayer.stop();
      Serial.println("Music Stopped!");
      menu_options();
    }

    // Pause/Continue the music
    if (command == 'p') {
      pause = !pause;
      if (pause == 0) {
        Serial.println("Continue...");
        myDFPlayer.start();
      }
      if (pause == 1) {
        Serial.println("Music Paused!");
        myDFPlayer.pause();
      }
      menu_options();
    }

    // Toggle repeat mode
    if (command == 'r') {
      repeat = !repeat;
      if (repeat == 1) {
        myDFPlayer.enableLoop();
        Serial.println("Repeat mode enabled.");
      } else {
        myDFPlayer.disableLoop();
        Serial.println("Repeat mode disabled.");
      }
      menu_options();
    }

    // Set volume
    if (command == 'v') {
      int myVolume = line.substring(1).toInt();
      if (myVolume >= 0 && myVolume <= 30) {
        myDFPlayer.volume(myVolume);
        Serial.print("Current Volume:");
        Serial.println(myDFPlayer.readVolume());
      } else {
        Serial.println("Invalid volume level, choose a number between 0-30.");
      }
      menu_options();
    }

    // Increases volume
    if (command == '+') {
      myDFPlayer.volumeUp();
      Serial.print("Current Volume:");
      Serial.println(myDFPlayer.readVolume());
      menu_options();
    }
    // Decreases volume
    if (command == '-') {
      myDFPlayer.volumeDown();
      Serial.print("Current Volume:");
      Serial.println(myDFPlayer.readVolume());
      menu_options();
    }

    // Play previouse
    if (command == '<') {
      myDFPlayer.previous();
      Serial.println("Previous:");
      Serial.print("Current track:");
      Serial.println(myDFPlayer.readCurrentFileNumber() - 1);
      menu_options();
    }

    // Play next
    if (command == '>') {
      myDFPlayer.next();
      Serial.println("Next:");
      Serial.print("Current track:");
      Serial.println(myDFPlayer.readCurrentFileNumber() + 1);
      menu_options();
    }
  }
}

void menu_options() {
  Serial.println();
  Serial.println(F("=================================================================================================================================="));
  Serial.println(F("Commands:"));
  Serial.println(F(" [1-9] To select the MP3 file"));
  Serial.println(F(" [fXsY] Play song from folder X, song Y"));
  Serial.println(F(" [s] stopping reproduction"));
  Serial.println(F(" [p] pause/continue music"));
  Serial.println(F(" [r] toggle repeat mode"));
  Serial.println(F(" [vX] set volume to X"));
  Serial.println(F(" [+ or -] increases or decreases the volume"));
  Serial.println(F(" [< or >] forwards or backwards the track"));
  Serial.println();
  Serial.println(F("================================================================================================================================="));
}

I don't have your DF min iplayer library, and its possible that this initialization might need modification like this

 //if (!myDFPlayer.begin(Serial1)) { 
 if (!myDFPlayer.begin(&Serial1)) {

Thank you so much for the support! I was able to get this code working for anyone else who is looking for a solution working with the Feather 32u.

You have to connect the RX (DFMini) to TX (Feather) and TX (DFMini) to RX (Feather).

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

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  Serial1.begin(9600);

  Serial.begin(115200);

  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(Serial1, /*isACK = */true, /*doReset = */true)) {  //Use serial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.volume(10);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop()
{
  if (myDFPlayer.available()) {
    printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }
}

void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerUSBInserted:
      Serial.println("USB Inserted!");
      break;
    case DFPlayerUSBRemoved:
      Serial.println("USB Removed!");
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
  
}
1 Like

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