Connect esp32cam with DFplayer mini

Hi, I'm newbie. Can connect esp32cam with df player mini? I have try it with arduino, it's working, but not with esp32cam
Here is my code:

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h" 
SoftwareSerial mySoftwareSerial(16,14); //RX, TX

// Create the Player object
DFRobotDFPlayerMini myDFPlayer;

void setup() { 
  mySoftwareSerial.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(mySoftwareSerial)) {  //Use softwareSerial 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);
  }
  Serial.println(F("DFPlayer Mini online."));
  
  myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms

  //----Set volume----
  myDFPlayer.volume(25);  //Set volume value (0~30). 

  //----Set different EQ----
  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); 

  //----Set device we use SD as default---- 
  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);  
  myDFPlayer.play(2);
  delay(62000);
  //----Read imformation----
  Serial.println("state" + myDFPlayer.readState()); //read mp3 state 
  Serial.println("all file" + myDFPlayer.readFileCounts()); //read all file counts in SD card
  Serial.println("current" + myDFPlayer.readCurrentFileNumber()); //read current play file number
  Serial.println("read fill"+ myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03

}

void loop() { }

The message error is: Unable to begin
Is it have problem with mySoftwareSerial?
Please help me, thanks a lot

The syntax in the first quote looks strange. Likely it's not correct.

Try: if (!myDFPlayer.begin(mySoftwareSerial()))

Note the () accompanying SoftwareSerial.

Thanks for the schematics. Quite good!

According to the example of DFplayer mini, the syntax is correct. I have try with the () accompanying SoftwareSerial but it can't compile. Thanks

That would be incorrect. mySoftwareSerial is an object, not a function.

No schematic had been posted. Only a MS Paint style wiring diagram.

Software Serial should only ever be used when there are no hardware serial (UART) ports available. This is why it is frequently used in code intended to run on Uno. Uno has only one hardware serial port, and that's not available because it's used for uploading code and serial monitor.

But ESP32 have at least 2 available hardware serial ports, and I understand they are configurable to use any available pins. So this is what you should be aiming to achieve with ESP32CAM, as far as I know.

//#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h" 
//SoftwareSerial mySoftwareSerial(16,14); //RX, TX

...


  //mySoftwareSerial.begin(9600);
  Serial2.begin(9600, SERIAL_8N1, 16, 14);

...

  if (!myDFPlayer.begin(Serial2)) {

The ESP32Cam has no free pins available.
At least using PSRAM and the SD-Card.

What you can do is to set the SD-Card to use less pins (slower):

 //Two less PINS when using "true". Allows to use PIR sensor
  //if(!SD_MMC.begin()){
  if (!SD_MMC.begin("/sd", true))

Then PIN12 & PIN13 will be usable.

1 Like

GPIO16 is the PSRAM select for the ESP32CAM.

ESP32-cam have only 1 hardware serial, and it use for ftdi. I have try your code but it still not working. Thanks

It has two hardware serial ports.

Oh really? I just know GPIO1 and GPIO3, could you tell me another hardware serial. Thanks

Did you combine with suggested from @TriB ?

It was a guess, shoting from the hip.

Could you explain more, I'm just newbie :sweat_smile:
I have code like this, is it correct as your idea?

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h" 
#include "SD_MMC.h" 
DFRobotDFPlayerMini myDFPlayer; 
void setup() {  
  Serial.begin(115200); 
  Serial2.begin(9600,SERIAL_8N1,13,12);
  // ---- Set device we use SD as default ----  
  if (!SD_MMC.begin("/sd", true)) {  
    Serial.println(F("Card Mount Failed"));
    // return;
  }  
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  if (!myDFPlayer.begin(Serial2)) {  //Use softwareSerial 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);
  }

Try this

Serial1.begin(9600, SERIAL_8N1, 16, 14);

Do not #include "SoftwareSerial.h"

It's still not working :smiling_face_with_tear:

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