Another DFPlayer Mini issue

Hello!

I have an Arduino Nano ESP32 project, quite simple, involving a DFPlayer Mini.
I struggled many hours before to post here my issue.

The DFPlayer Mini: it is working as a standalone. It is powered by a 4.2V lab powersupply; I inserted a 32Gb SDCard with a single 0001.wav file; it is connected to a 2Ohm speaker. When I set GPIO1 to low with a Dupond cable, I have the music played. It took me ages to realize I could test it as a standalone :smiley:

The Nano32: The board is powered by USB which allows me to read the Serial. It is grounded to the lab powersupply to get it consistent with the DFPlayer. I SoftSerialized A2 and A3 pins, both resistored with 1kOhm:

#define PIN_RX A2
#define PIN_TX A3
SoftwareSerial mySerial(PIN_RX, PIN_TX); // RX, TX

I'm using the DFRobotDFPlayer_Mini library. And I run the first Example provided with it.

On the setup, I try to Begin the player with my softSerial (set to 9600) and debug set to true, as well as reset. But that fails with the classical message "check connection, check card":

if (!myDFPlayer.begin(mySerial, /*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!"));
    }
    else
        Serial.println(F("DFPlayer Mini online."));

I tried several pins, by theie name, GPIO index, Secret Arcanic Names, switched then several time. I tried hardware secondary RX/TX pins and try to swithed them also.

Begin never worked.

Actually, in my Loop(), I request the DFPlayer state as this:

if (myDFPlayer.available())
{
     printDetail(myDFPlayer.readType(), myDFPlayer.read());
}

And in the best configuration, I can read on Serial a lot of DFPlayerError: Get Wrong Stack. That makes me raise an eyebrow: Begin failed, but the player is available?!?
If I add a call to play at this point, after the printDetail... Everything hang. Dead. I've read another thread where someone has an issue with play() doing nothing, but next() doing the job. I tested that: it hangs the same.

The funny part is that when I remove and insert back the SDCard, I have a reading on Serial: "Card Removed!" and "Card online!":

DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
Card Removed!
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack
Card Inserted!
DFPlayerError:Get Wrong Stack
DFPlayerError:Get Wrong Stack

I expect this to prove to me I did not make inconsistent pins connections.

Well. In the end: the player can play when I Low GPOI1 but I always have Wrong Stack error message.

Can someone have an idea to make me go further?
(You noticed I'm bad at making pictures :wink: )

Interesting, using SoftwareSerial with an "Nano ESP32", as SoftSer doesn't work with a 'standard' ESP32.

how ?

if your DF Player is using 4.2V and your ESP 3.3V.. you are at risk of damaging your ESP possibly ? (the Rx pin might not be happy with the 4.2V)

Hello !

The resistor is in "serie". I found here and there notes about RX port supporting 5v.
Actually, I expected the Nano to work at 5v due to USB power, but checking the docs, I realize it is 3.3v. You are right. I might place a resistor to divide the voltage instead of reducing the amps.

I tried downing the DFPlayer to 3.3 but it does not work very fine (sound presents ticks and scratchs.

Note that in the end, that does not change the result: the ESP still complains about getting wrong stack :confused:

can you post the full code and a picture of the drawing (hand drawn is fine) of your circuit?

Hello!
Here is my handdrawn circuitry (coloured thanks to my child). Note that it includes the voltage divider suggested above (with actually no effects on the succesfullness of my DF control).

And then, here is my code.

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
// #include <DFPlayerMini_fast.h>

#define LED LED_BUILTIN
#define PIN_RX A2
#define PIN_TX A3
SoftwareSerial mySerial(PIN_RX, PIN_TX); // RX, TX

// =================================================================
// MP3 Player
// =================================================================

DFRobotDFPlayerMini myDFPlayer;
// DFPlayerMini_Fast myDFPlayer;

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;
    }
}

// =================================================================
// SETUP
// =================================================================

void setup()
{
    // Serial and Pins
    Serial.begin(115200);
    pinMode(LED, OUTPUT);
    delay(500);
    // MP3
    mySerial.begin(9600);
    delay(3000);
    Serial.println(F("DFRobot DFPlayer Mini Demo"));
    Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

    if (!myDFPlayer.begin(mySerial, /*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!"));
    }
    else
        Serial.println(F("DFPlayer Mini online."));

    Serial.println("Timeout:");
    myDFPlayer.setTimeOut(500); // Set serial communictaion time out 500ms
    // Serial.println(myDFPlayer.readFileCounts());          // read all file counts in SD card
    // Serial.println(myDFPlayer.readFileCountsInFolder(1)); // read file counts in folder SD:/01

    Serial.println("Volume:");
    // myDFPlayer.volume(10); // Set volume value. From 0 to 30
    //  Serial.println(myDFPlayer.readVolume()); // read current volume

    Serial.println("EQ:");
    // myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
    //  Serial.println(myDFPlayer.readEQ()); // read EQ setting

    // Serial.println("Play:");
    myDFPlayer.play(1); // Play the first mp3

    Serial.println("Play MP3-4:");
    // myDFPlayer.playMp3Folder(4);
    // myDFPlayer.startRepeatPlay();
    // Serial.println(myDFPlayer.readState());             // read mp3 state
    // Serial.println(myDFPlayer.readCurrentFileNumber()); // read current play file number
}

// =================================================================
// LOOP / MAIN
// =================================================================

void loop()
{
    if (myDFPlayer.available())
    {
        printDetail(myDFPlayer.readType(), myDFPlayer.read()); // Print the detail message from DFPlayer to handle different errors and states.
        // Serial.println("Try to play");
        // myDFPlayer.next();
        // delay(1500);
    }
    // else
    //     Serial.println("DFPlayer: >>> OUT <<<");
}

I found I can define a _DEBUG directive which allows DFPlayer library to output the stack read.

received:7E FF 6 40 0 0 3 FE B8 EF 
DFPlayerError:Get Wrong Stack
received:7E FF 6 40 0 0 3 FE B8 EF 
DFPlayerError:Get Wrong Stack

I think is very stable answer, close to one expected to be sent from DFPlayer.
I have only one DFFPlayer module to check if its serial controller is working fine.
Otherwise, I'm missing a pretty obvious thing regarding RX/TX connection :stuck_out_tongue:

Maybe, as suggested by Runaway_Pancake, the issue comes from the SoftwareSerial not supported by ESP32...

Okay! Thanks for your time and help, Pancake and J-M-L:

I got the solution!
You were both of a big help: using the voltage divider AND using the hardware RX/TX (Serial1 on NanoESP3 : D0/D1) changed the game!
Now, I have consistent communication, DF is setup and respond (correctly) to my commands!

Note to myself: better read the specs for pin voltage AND find a way to know library compatibility with hardware :smiley:

Many thanks!

great news !

have fun

1 Like

I don't know the Nano-ESP32, but here's my example sketch for ESP32 ("non-Nano") using one of its hardware UARTs - which leaves SerialMonitor open --

//
const byte RXD2 = 16; // Connects to module's RX 
const byte TXD2 = 17; // Connects to module's TX 

HardwareSerial dfSD(1); // Use UART channel 1
DFRobotDFPlayerMini player;
   
void setup() 
{
  Serial.begin(19200);
  dfSD.begin(9600, SERIAL_8N1, RXD2, TXD2);  // 16,17
  delay(5000);

  if (player.begin(dfSD)) 
  {
    Serial.println("OK");

    // Set volume to maximum (0 to 30).
    player.volume(17); //30 is very loud
  } 
  else 
  {
    Serial.println("Connecting to DFPlayer Mini failed!");
  }
}

void loop() 
{
  Serial.println("Playing #1");
  player.play(1);
  Serial.println("play start");
  delay(5000);
  Serial.println("played");
  delay(1000);
  //  "as is", it will repeatedly, maddeningly, play 'track No.1' for 5secs.
}
1 Like

I ordered a couple of these (Nano-ESP32).
Having that MP2322 makes it a Big Deal for battery-operated projects.

1 Like

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