1
1
/*
2
2
NodeMCU ESP12E + DFPlayer Mini MP3
3
- Author : ChungYi Fu (Kaohsiung, Taiwan) 2020-2-17 00 :00
3
+ Author : ChungYi Fu (Kaohsiung, Taiwan) 2022-6-7 20 :00
4
4
https://www.facebook.com/francefu
5
5
6
- DFPlayer RX -> ESP12E gpio16
7
- DFPlayer TX -> ESP12E gpio17
6
+ DFPlayer RX -> ESP12E TX
7
+ DFPlayer TX -> ESP12E RX
8
8
9
9
Sample Code
10
10
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
@@ -18,9 +18,9 @@ Default APIP: 192.168.4.1
18
18
STAIP:
19
19
Query: http://192.168.4.1/?ip
20
20
Link:http://192.168.4.1/?resetwifi=ssid;password
21
-
22
21
If you don't need to get response from ESP8266 and want to execute commands quickly,
23
22
you can append a parameter value "stop" at the end of command.
23
+
24
24
For example:
25
25
http://192.168.4.1/?digitalwrite=gpio;value;stop
26
26
http://192.168.4.1/?restart=stop
@@ -29,8 +29,8 @@ http://192.168.4.1/?restart=stop
29
29
#include < ESP8266WiFi.h>
30
30
31
31
// Enter your WiFi ssid and password
32
- const char * ssid = " " ; // your network SSID
33
- const char * password = " " ; // your network password
32
+ const char * ssid = " teacher " ; // your network SSID
33
+ const char * password = " 87654321 " ; // your network password
34
34
35
35
const char * apssid = " ESP12E_DFPlayer" ;
36
36
const char * appassword = " 12345678" ; // AP password require at least 8 characters.
@@ -39,8 +39,6 @@ WiFiServer server(80);
39
39
40
40
#include " Arduino.h"
41
41
#include " DFRobotDFPlayerMini.h"
42
- #include < HardwareSerial.h>
43
- HardwareSerial mySerial (1 ); // RX:gpio16 TX:gpio17
44
42
45
43
DFRobotDFPlayerMini myDFPlayer;
46
44
void printDetail (uint8_t type, int value);
@@ -50,11 +48,6 @@ byte ReceiveState=0,cmdState=1,strState=1,questionstate=0,equalstate=0,semicolon
50
48
51
49
void ExecuteCommand ()
52
50
{
53
- Serial.println (" " );
54
- // Serial.println("Command: "+Command);
55
- Serial.println (" cmd= " +cmd+" ,P1= " +P1+" ,P2= " +P2+" ,P3= " +P3+" ,P4= " +P4+" ,P5= " +P5+" ,P6= " +P6+" ,P7= " +P7+" ,P8= " +P8+" ,P9= " +P9);
56
- Serial.println (" " );
57
-
58
51
if (cmd==" your cmd" ) {
59
52
// You can do anything
60
53
// Feedback="<font color=\"red\">Hello World</font>";
@@ -72,16 +65,12 @@ void ExecuteCommand()
72
65
}
73
66
else if (cmd==" resetwifi" ) {
74
67
WiFi.begin (P1.c_str (), P2.c_str ());
75
- Serial.print (" Connecting to " );
76
- Serial.println (P1);
77
68
long int StartTime=millis ();
78
69
while (WiFi.status () != WL_CONNECTED)
79
70
{
80
71
delay (500 );
81
72
if ((StartTime+5000 ) < millis ()) break ;
82
73
}
83
- Serial.println (" " );
84
- Serial.println (" STAIP: " +WiFi.localIP ().toString ());
85
74
Feedback=" STAIP: " +WiFi.localIP ().toString ();
86
75
}
87
76
else if (cmd==" volume" ) { // value = 0 to 30
@@ -210,9 +199,7 @@ void ExecuteCommand()
210
199
211
200
void setup ()
212
201
{
213
- mySerial.begin (9600 , SERIAL_8N1, 16 , 17 );
214
-
215
- Serial.begin (115200 );
202
+ Serial.begin (9600 );
216
203
delay (10 );
217
204
218
205
WiFi.mode (WIFI_AP_STA);
@@ -260,7 +247,7 @@ void setup()
260
247
Serial.println (F (" DFRobotDemo" ));
261
248
Serial.println (F (" Initializing DFPlayer ... (May take 3~5 seconds)" ));
262
249
263
- if (!myDFPlayer.begin (mySerial )) { // Use softwareSerial to communicate with mp3.
250
+ if (!myDFPlayer.begin (Serial )) { // Use softwareSerial to communicate with mp3.
264
251
Serial.println (F (" Unable to begin:" ));
265
252
Serial.println (F (" 1.Please recheck the connection!" ));
266
253
Serial.println (F (" 2.Please insert the SD card!" ));
0 commit comments