Go Down

Topic: dfplayer wiring to arduino nano using rx and tx and code issue (Read 337 times) previous topic - next topic

casualgamer24

yes it uploads but the mp3 player still wont play anything. Nothing happens..

BulldogLowell

yes it uploads but the mp3 player still wont play anything. Nothing happens..
time to post your complete code

casualgamer24

I am not sure what i am doing wrong, ive tested the dfplayer without the arduino and it works.
Code: [Select]
#include <DFPlayer_Mini_Mp3.h>
#include <SoftwareSerial.h>

SoftwareSerial dfPlayer(7, 4); // RX, TX
 
void setup () {
 Serial.begin (9600);
 dfPlayer.begin(9600);
 mp3_set_serial (dfPlayer); //set SoftwareSerial for DFPlayer-mini mp3 module
 mp3_set_volume (80);
}


 
void loop () {       
 
 mp3_play (1); //play 0001.mp3
 delay (10000); //10 sec, time delay to allow 0001.mp3 to finish playing
 
 mp3_play (2);
 delay (5000);
 
}


BulldogLowell

#18
Nov 15, 2017, 03:33 am Last Edit: Nov 15, 2017, 03:34 am by BulldogLowell Reason: added directory question
I am not sure what i am doing wrong, ive tested the dfplayer without the arduino and it works.
how did you test it?  what did you use to test the serial commands?


are you certain that the files are in the right directory:

Code: [Select]
mp3/0001.mp3

casualgamer24

I hooked the dfplayer to the speaker and battery then I jumped the IO_1 to ground and it played through the mp3 in a loop.

BulldogLowell

Are you certain that the files are in the right directory:

Code: [Select]
mp3/0001.mp3
  • you have it connected correctly? TX<->RX and  RX<->TX
  • common ground?


Post a photo...

What is actually happening? does the communication LED lite up when the command is sent from Arduino?


casualgamer24

yea its in the right directory and the tx-rx and rx-tx

casualgamer24

I got it working, looks like it was my soldering job..

casualgamer24

Now Ive run into another problem with the mp3 sounds.. when i press a button i want 0001.mp3 to play only once and 0003.mp3 to play in a loop after and when i press the button again the sounds turn off. Does anyone know how to do this?

J-M-L

Yes many people here would know how to do this :).... but will first wait to see your attempt at solving this;

You can solve this by building a small state machine, using a variable to remember where you are (waiting for button, file 1 playing, waiting for button press whilst playing file2)
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

casualgamer24

Ive been trying to figure out how to count the number of times the mp3 plays. Like mp3player1= 0; if button press mp3player1++; if (mp3player1 == 1){mp3_play(1);} mp3_play(3); if(mp3player1 ==2){mp3player1=0;}. But It just skips 1 and plays 3..

I have also tried bool mp3player1 = false; If button press mp3player1 = true; but the true false statement wont work either. it will skip 0001.mp3 and play the other 0003.mp3 or play both in loop.

J-M-L

Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

BulldogLowell

Now Ive run into another problem with the mp3 sounds.. when i press a button i want 0001.mp3 to play only once and 0003.mp3 to play in a loop after and when i press the button again the sounds turn off. Does anyone know how to do this?
There is a feature call "advertisements" that will pause the playback, play the advertisement, and then continue to play.  the method is called (coincidently) advertise().

There is also a method (coincidently) called loopFolder() where you can place the sounds you want to loop.

so just (semi-pseudo):

Code: [Select]
if(buttonAPressed)
{
  mp3.loopFolder(somefolder); // whatever folder you want to play
  delay(10);
  mp3.advertise(something); // whatever
  uint32_t startMillis = millis();
  while(millis() - startMillis < AD_TIME);  // << semicolon is intentional
  MP3.stopAdvertise();
}
if(buttonBPressed)
{
  mp3.stop();
}

Go Up