I'm try communication Communication Wemos D1 wifi to Mp3 Player not working.
can you help me please.
/***************************************************
DFPlayer - A Mini MP3 Player For Arduino
<https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
***************************************************
This example shows the basic function of library for DFPlayer.
Created 2016-12-07
By [Angelo qiao](Angelo.qiao@dfrobot.com)
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
****************************************************/
/***********Notice and Trouble shooting***************
1.Connection and Diagram can be found here
<https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
****************************************************/
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(15, 2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
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.volume(30); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop()
{
static unsigned long timer = millis();
if (millis() - timer > 3000) {
timer = millis();
myDFPlayer.next(); //Play next mp3 every 3 second.
}
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;
}
}
In the ESP8266 core pin D15 isn't equal to 15 and D2 isn't equal to 2. Maybe that's your problem, we cannot tell because you failed to post a wiring diagram.
this picture does not deliver any new information.
Post a datasheet with the pinout of your microcontroller-board.
and a datasheet of the MP3-player-board
this picture still leaves question open.
The io-pin the violet wire is connected to a Pin named D10/SS
well SS seems to be something like "Chipselect" so this might be an IO-pin that has a special purpose or special components connected. I don't know.
You seem to be a lazy guy. In this graphic your wires are inbetween and it is not recognisable to which IO-pin they shall be connected.
To analyse this the real datasheet is required.
If you do a step back and analyse what you have reached so far
you have achieved multiple delays by trying to be quick and ignoring the tips how to improve your posting style
I tried again according to your instructions the mp3 module doesn't work. any suggestions? thanks
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 15; //D10 Connects to module's RX
static const uint8_t PIN_MP3_RX = 13; //D7 Connects to module's TX
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
// Create the Player object
DFRobotDFPlayerMini player;
void setup() {
// Init USB serial port for debugging
Serial.begin(9600);
Serial.swap();
// Init serial port for DFPlayer Mini
softwareSerial.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(softwareSerial)) {
Serial.println("OK");
// Set volume to maximum (0 to 30).
player.volume(30);
// Play the first MP3 file on the SD card
player.play(1);
} else {
Serial.println("Connecting to DFPlayer Mini failed!");
}
}
void loop() {
}
An ESP8266 is a 3.3V device. Not sure if this is true: So it might be that the voltage of 3.3V is not high enough to make the communication work.
best regards Stefan
Be the change you want to see in the world
This notion of be the change you want to see in the world does 3 powerful things when we adopt it:
It stops us from judging others;
It replaces complaining about others with reflection on self;
It stirs us into taking action within the only thing in the world over which we have any control: ourselves.
Serial object works much the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) HardwareSerial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full/empty.
Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.
Though I have a question @PerryBebbington :
if UART0 is mapped to IO-pin 15 to be Tx and IO-pin 13 to be Rx
is this a permanent swap or will a reset or power of/on map it back to
IO-pin 1 to be Tx and IO-pin 3 to be Rx
if the swapping would be permanent this would require pre-cautions in the sketch to make sure back-swapping is always possible.
The standard hardware-serial is IO-pin 1 to be Tx and IO-pin 3 to be Rx
Which is used for uploading the code and for serial.print to the serial monitor.
All lines of code that are needed to use hardware-serial on
IO-pin 15 to be Tx and IO-pin 13 to be Rx is
Serial.begin(baudrate);
Serial.swap();
best regards Stefan
Be the change you want to see in the world
This notion of be the change you want to see in the world does 3 powerful things when we adopt it:
It stops us from judging others;
It replaces complaining about others with reflection on self;
It stirs us into taking action within the only thing in the world over which we have any control: ourselves.
It's not permanent, a reset (power cycle or pressing the reset button) will restore the hardware serial port to the USB, as will using serial.swap() again.
So you can flip between where UART0 is presented as you wish in code, but on restart it is always on the USB.
What don't you understand?
Do you know what hardware serial is?
Do you know what software serial is?
Do you realise that Serial.begin(baudrate) starts the hardware serial port?
Have you connected the Mini to GPIO13 and 15 as I said?
I connected DF player mini to Wemos D1 mini in a project using that same library (as far as I remember). It works well.
If you don't need to read the status or other data back from the player, then you only need to connect a TX pin from the ESP to the player's RX pin.
If that's ok for you (it was for me and my project) then you can use the esp's other hardware serial port. This has its TX pin on D4 (= GPIO2). The RX pin for this serial port is not available to use, but, as I said, you may not need it anyway.
To use it:
Serial1.begin(9600);
// Start communication with DFPlayer Mini
if (player.begin(Serial1)) {
Serial.println("OK");
The advantage of using Serial1 is that you don't need to use Serial.swap() and you can use serial monitor for debugging as normal.
Please stop posting screenshots. Post code or error messages by copying and pasting the text into your post between code tags.
You do not need to declare hardware serial ports, or include any header files, and you do not need to (and cannot) give pin numbers because they exist already and the pin numbers are fixed by the hardware.
there are a few things to learn how to provide the nescessary information
0. never post textual information as a picture
post always your complete sketch as a code-section
if you get an error-message from the compiler
provide the fully detailed compiler-log like described here
best regards Stefan
Be the change you want to see in the world
This notion of be the change you want to see in the world does 3 powerful things when we adopt it:
It stops us from judging others;
It replaces complaining about others with reflection on self;
It stirs us into taking action within the only thing in the world over which we have any control: ourselves.