mirror of
https://github.com/DFRobot/DFRobotDFPlayerMini.git
synced 2026-03-06 08:44:09 +01:00
compatible with hardware serial port
This commit is contained in:
@@ -20,23 +20,34 @@
|
||||
****************************************************/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SoftwareSerial.h"
|
||||
#include "DFRobotDFPlayerMini.h"
|
||||
|
||||
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
|
||||
#if (defined(ARDUINO_AVR_UNO) || defined(ESP8266)) // Using a soft serial port
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial softSerial(/*rx =*/4, /*tx =*/5);
|
||||
#define FPSerial softSerial
|
||||
#else
|
||||
#define FPSerial Serial1
|
||||
#endif
|
||||
|
||||
DFRobotDFPlayerMini myDFPlayer;
|
||||
void printDetail(uint8_t type, int value);
|
||||
|
||||
void setup()
|
||||
{
|
||||
mySoftwareSerial.begin(9600);
|
||||
#if (defined ESP32)
|
||||
FPSerial.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2);
|
||||
#else
|
||||
FPSerial.begin(9600);
|
||||
#endif
|
||||
|
||||
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.
|
||||
if (!myDFPlayer.begin(FPSerial, /*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!"));
|
||||
|
||||
Reference in New Issue
Block a user