Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rev 0 This was developed on 12/19/2022 and is a simple sketch allowing the user to test out the DFPlayer Mini using ESP32 Node MCU - Note ththe DFPlayer Mini is wired to the ESP32 it is to the Arduino
- //#include <SoftwareSerial.h> //Note this is the ESP32 Software Serial
- #include <HardwareSerial.h>
- #include "Arduino.h" //Needed for FullFunction DFRobotDFPlayerMini library sketch
- #include "DFRobotDFPlayerMini.h" //Needed for FullFunction DFRobotDFPlayerMini library sketch
- //Now to Use a Software Serial Port to Control DFPlayer Mini
- //SoftwareSerial portTwo(27, 26); //Here ESP32 GPIO27 is Rx and ESP32 GPIO26 is Tx
- //Connect ESP32 GPIO 27 to DFPlayer Mini Pin Tx through 1 kΩ Resistor
- //Connect ESP32 GPIO 26 to DFPlayer Mini Pin Rx through 1 kΩ Resistor
- HardwareSerial MySerial(1);
- #define DFPlayerTx 27
- #define DFPlayerRx 26
- DFRobotDFPlayerMini myDFPlayer; //Defines an Object to Call the DFPlayer Mini with object name myDFPlayer - Needed for FullFunction DFRobotDFPlayerMini library sketch
- void printDetail(uint8_t type, int value); //Needed for FullFunction DFRobotDFPlayerMini library sketch
- int volC=25; //Volume Level returned from VolumeControl function
- void setup() {
- Serial.begin (9600); //Starts up the serial monitor
- //portTwo.begin(9600); //Start Serial Port to DFPlayer Mini
- MySerial.begin(9600, SERIAL_8N1, DFPlayerTx, DFPlayerRx);
- //Start of DFPlayer Mini setup - comes from FullFunction DFRobotDFPlayerMini library sketch
- Serial.println();
- Serial.println(F("DFRobot DFPlayer Mini Demo"));
- Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
- if (!myDFPlayer.begin(MySerial)) { //Use hardware serial to communicate with DFPlayerMini
- 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(volC); //Set volume value (0~30).
- myDFPlayer.volumeUp(); //Volume Up
- myDFPlayer.volumeDown(); //Volume Down
- //----Set different EQ----
- myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
- //----Set device we use SD as default----
- myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
- //----Read imformation----
- Serial.println(myDFPlayer.readState()); //read mp3 state
- Serial.println(myDFPlayer.readVolume()); //read current volume
- Serial.println(myDFPlayer.readEQ()); //read EQ setting
- Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
- Serial.println(myDFPlayer.readCurrentFileNumber()); //read current play file number
- Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read file counts in folder SD:/03
- //End of DFPlayer Mini setup
- }
- void loop() { //Start of void loop
- //This if statement comes from FullFunction DFRobotDFPlayerMini library sketch
- //if (myDFPlayer.available()) {
- //printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
- // myDFPlayer.enableLoopAll(); //loop all mp3 files.
- // }
- myDFPlayer.enableLoopAll(); //loop all mp3 files.
- } //End of void loop
- //References
- //Reference 1- To use a second serial port in the ESP32 https://quadmeup.com/arduino-esp32-and-3-hardware-serial-ports/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement