Go Down

Topic: DFPlayer Mini not working with Arduino Nano (Read 4592 times) previous topic - next topic

twanc

Feb 14, 2018, 03:03 pm Last Edit: Feb 16, 2018, 04:55 pm by twanc
Hi there,

I'm new here and I've recently started playing around with Arduino in order to add lights and sound to my model kits.

So far I'm pleasantly surprised how easy it was to setup a working DFPlayer on an Arduino Uno.

But, when I tried the exact same setup linked to an Arduino Nano, I can't get the DFPlayer to play anything.

In both cases I'm using the exact circuit from the DFRobot wiki, where the Arduino is powered by a USB cable:


Here's my code:
Code: [Select]

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

int serial1 = 10;
int serial2 = 11;

SoftwareSerial mySoftwareSerial(serial1, serial2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
  pinMode(serial1, INPUT);
  pinMode(serial2, OUTPUT);

  mySoftwareSerial.begin(9600);
  Serial.begin(115200);

  Serial.println(F("Initializing DFPlayer ..."));

  if (!myDFPlayer.begin(mySoftwareSerial)) {
    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."));
  }

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



The serial monitor outputs the following:
Code: [Select]

Initializing DFPlayer ...
Unable to begin:
1.Please recheck the connection!
2.Please insert the SD card!
Time Out!
DFPlayerError:Card not found
Time Out!


Which is very weird since the SD card is present. When at this point I remove the SD card and insert it again, the serial monitor shows these messages (as expected):
Code: [Select]

Card Removed!
Card Inserted!


So it looks to me like the DFPlayer works at least in some part. Since this exact same setup and code work flawlessly on my Uno, I wonder if anyone can tell me what is wrong here?


beapilot

Make sure it is pressed tightly in. To get it out, press in again and it pops out.

twanc

Make sure it is pressed tightly in. To get it out, press in again and it pops out.
The card is inserted correctly. Without touching the card but switching to the Uno (using the same DFPlayer module) it all works flawlessly.

twanc

OK so I'm embarrassed to report that the issue was related to one of the wires of the resistor not being connected correctly between pin 11 and the Dfplayer ..  :o  All works great now!

xl97

Is the Nano a +5v one?  Or a +3.3v one?

Have you tried powering from the VIN pin instead?  (when powered from a stable 5v source?)

Wonder if its not getting enough current?

toe2thaknee

OMG thank you for posting this.

...
I've been trying to get this to work for 2 days now, and i had the exact same problem, cut resistor too short

nmarkus

#6
Mar 19, 2019, 09:26 am Last Edit: Mar 19, 2019, 09:30 am by nmarkus
I had a similar problem with Arduino nano and DFplayer: Playing mp3s via software worked with Arduino uno, but not with Arduino nano. With the example code (and all other sketches) speaker produced noise and popping noises and software serial reported com problems.

As I stumbled over this thread while searching for an answer, I'll document the result here as well for future reference.


The problem with dfplayer mini and arduino nano in my case was caused by three things:

- wrong wiring of rx / tx ports
Reading the comments in the example sketch of the DFPlayer library, I assumed that the digital RX/TX on the arduino nano goes to the same  corresponding RX/TX on the DFPlayer. This is not so! Valuable lesson about serial connection, digital RX (pin 10 in my sketch on the arduino) should be connected to TX on DFPlayer, and digital TX (pin 11 in my sketch on the arduino) should be connected to RX on the Dfplayer.

- dot files on the sd card, caused by mac os x
Mac computers litter the sd card with lots of unneccessary dot files, that can cause problems with dfplayer (also with catalex mp3 serial player, for the record). What helped was following the tips from https://reprage.com/post/dfplayer-mini-cheat-sheet . If you don't want to remove it via terminal every time, there is also software like "clean my drive" for this mac-software-generated problem.

- odd behavior of my cheap ch340 arduino nanos
A bad karma situation: My cheap asian arduinos caused long debugging pain. I had to power my Cheap Arduino Nano (CAN) and the DFPlayer through an external power supply -for some reason the whole setup would not work when powered through my trash-CAN. Before uploading code, I unplugged the external power supply, after uploading I unplugged usb and plugged in the external power supply. For some reason, serial port communication would be fine when first powering the whole setup through the external power supply, connection the CAN via USB only afterwards.

Final setup:


Fun and games. But now it works.

Go Up