Hi there guys I hope you will be able to help me !
I am making a drink dispenser project with arduino mega and I would like to include a DFmini mp3 player. I can't figure out how to get the code to work with the arduino mega. On an arduino uno i use softwareserial library but with the arduino mega I don't won't to use it but instead use RX1 and TX1. I've been trying for hours but can't figure out the right code and nothing on the web which can help me.
Hope you guys could give me a hand !
Have a nice day.
So post your best attempt at getting it included and explain the problems you're having. Then we'll have something to help with.
Steve
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
static unsigned long timer;
void setup() {
Serial.begin(9600);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini"));
Serial.println(F("Initializing DFPlayer..."));
myDFPlayer.volume(30);
myDFPlayer.play(2);
timer = millis();
}
void loop() {}
This is basically all I have. I can get it to work using SoftwareSerial.h on pin 10 & 11 but i can't get it working without softwareserial.h and i know an arduino mega can operate and dfmini mp3 player throught RX1 and TX1 without software serial. I'm very new with arduinos !
Thanks.
Benjamin
You can use the library DFPlayerMini_Fast.h library (better in quality than DFRobotDFPlayerMini.h and installable via the Arduino IDE's Libraries Manager) with this example code:
#include <DFPlayerMini_Fast.h>
DFPlayerMini_Fast myMP3;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
myMP3.begin(Serial1);
Serial.println("Setting volume to max");
myMP3.volume(30);
delay(20);
Serial.println("Playing track 1 for 5 sec");
myMP3.play(1);
delay(5000);
Serial.println("Sleeping for 5 sec");
myMP3.sleep();
delay(5000);
Serial.println("Waking up");
myMP3.wakeUp();
Serial.println("Looping track 1");
myMP3.loop(1);
}
void loop()
{
//do nothing
}
Also make sure the grounds are connected and TX --> RX and RX --> TX.
thank you very much !!!! It works. Thank you again for your help.
Benjamin.
ben-archard:
Hi there guys I hope you will be able to help me !
I am making a drink dispenser project with arduino mega and I would like to include a DFmini mp3 player. I can't figure out how to get the code to work with the arduino mega. On an arduino uno i use softwareserial library but with the arduino mega I don't won't to use it but instead use RX1 and TX1. I've been trying for hours but can't figure out the right code and nothing on the web which can help me.
Hope you guys could give me a hand !
Have a nice day.
Mega2560 has possible Serial, Serial1, Serial2, Serial3.
The serial.begin() for any of those sets up the matching hardware port to use as serial RX/TX on the proper pins.
Serial1.begin( 115200 ); // we don't need no steenkin SoftwareSerial!
ben-archard:
'
void setup() {
Serial.begin(9600);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini"));
Serial.println(F("Initializing DFPlayer..."));
myDFPlayer.volume(30);
myDFPlayer.play(2);
timer = millis();
}
You removed the whole initialisation code for the MP3 player, including the myDFPlayer.begin() call where you tell it which serial interface to use.