Hi. Has anybody used this library using the built-in serial port? (hardware serial). I am trying to use hardware serial because I am using timers and interrupts to my 7-segments and the DFRobot library have conflicts when I use Software Serial (I actually not tested DFPlayerMini_Fast library with software serial.
What Arduino board?
Is there a problem?
Please read the how to get the best from the forum guidelines to see how to ask a question.
Ok, thks!!
Arduino Nano.
Yes, I have troubles using Software Serial because I think there are conflicts with timers, that's the reason I want to use Hardware Serial. Have you used it?
I happen to have a DF player mini module handy so gave connecting the DF player to my Uno with hardware serial (pins 0 and 1) a try. I modified the DFRobotDFPlayerMini library GetStarted example to work with hardware serial (shown below). It works fine. It is necessary to disconnect the Uno from the DF player to upload code. The down side is that you loose the ability for using the serial port to monitor the program functioning since you cannot talk to the player and serial monitor at the same time.
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
Serial.begin(9600);
myDFPlayer.begin(Serial);
myDFPlayer.volume(25); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
void loop()
{
static unsigned long timer = millis();
if (millis() - timer > 5000)
{
timer = millis();
myDFPlayer.next(); //Play next mp3 every 5 second.
}
}
How it is connected:
Thank you very much groundFungus!!!! I appreciate it!!! I will try today. I know I have to disconnect the DF when I am uploading and I lose the ability to use the serial for monitoring.
I had some progress yesterday (with my serial soft library DFPlayer_Mini_Fast), but I have a lattency or delay between triggering and the sound (1 to 2 seconds). I am suspicious is because my files are mp3. I will try wav files.
I experience no latency with the setup that I have.
All of the sound files on my SD card are MP3 files.
Great! I will try it!! Do you have folders in the SD or just files in the root?
The DF Player mini library wants the MP3 files to be in a folder named MP3. The files are named 0001, 0002, 0003, ...
ROOT
......MP3
.............0001.mp3
.............0002.mp3
.............0003.mp3
But that is how the library that I am using works. Yours may be different.
I have the same folder too. I was thinking about the Latency. If your previous answer about latency is from your sketch (playing a song every 5 seconds) is not possible to determine if latency is present or not. The correct method would be by pressing a button and expecting the sound. That's I have, and time lapse is 2 seconds more or less. Have you try it?
Yes, i have. I have a program where I press a button and the player plays a random sound file. The is no noticeable pause between pressing the button and the sound playing.
If you would like for me to try your code, post your code and a schematic.
Great!! I will send you my sketch and the schematic so you can try it. For now, my version with delay is using software serial, I couldn't make work my hardware serial version. I will try yours. I will try to make some time to send it when I get home.
It may make a difference whether it's a genuine DFRobot device.
Maybe, we'll see when groundFungus try my sketch, we'll see if he have delay.
I was remembering one thing: I tried play the sound by their own input pins of DFPlayer, using ADKEY1 (first song), and the delay was present too...that's why I'am suspicious from mp3 files. I tried 2 memories and the delay was there too.
This is my code where I get delay
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A5, A6); // RX, TX
DFPlayerMini_Fast myMP3;
void setup()
{
mySerial.begin(9600);
myMP3.begin(mySerial, false);
pinMode(2, INPUT_PULLUP);
delay(1000);
myMP3.volume(30);
delay(500);
myMP3.playFromMP3Folder(1);
}
void loop()
{
if (digitalRead(2) == LOW)
{
myMP3.playFromMP3Folder(1);
delay(500);
}
}
What Arduino board are you using? On a Nano, the A6 pin does not have any of the digital functions. A6 and A7 are analog inputs, only.
Yes, nano, I agree with you if you read theory or website of arduino. (nano doesn't have digital functions on Ax) but actually it works fine like DI's or DO's. Anyway, I tried my sketch with digital ports as RX and TX and work the same way
What type of SD do you have? Speed?
Have you tried my sketch? Any delay?