I'm sorry if this topic has been posted somewhere within the forums but if it has I can't find it. If it has please point me towards it.
I know how to set up an Arduino with a DfMini mp3 player and the needed code to make it work.
My question is can I control 2 different DfMini mp3 players with one Arduino?
I currently have these lines of code as well as the code configuring the player.
int rxPin = 10;
int txPin = 11;
SoftwareSerial mySoftwareSerial(rxPin, txPin);
DFRobotDFPlayerMini myDFPlayer;
Can I add some code like this?
int rxPin2 = 9;
int txPin2 = 8;
SoftwareSerial mySoftwareSerial2(rxPin2, txPin2);
DFRobotDFPlayerMini myDFPlayer2;
Thank you for your time.
I'm sorry if this topic has been posted somewhere within the forums but if it has I can't find it. If it has please point me towards it.
I know how to set up an Arduino with a DfMini mp3 player and the needed code to make it work.
My question is can I control 2 different DfMini mp3 players with one Arduino?
I currently have these lines of code as well as the code configuring the player.
int rxPin = 10;
int txPin = 11;
SoftwareSerial mySoftwareSerial(rxPin, txPin);
DFRobotDFPlayerMini myDFPlayer;
Can I add some code like this?
int rxPin2 = 9;
int txPin2 = 8;
SoftwareSerial mySoftwareSerial2(rxPin2, txPin2);
DFRobotDFPlayerMini myDFPlayer2;
Thank you for your time.
Just try it. As long as those pins are 'valid' I see no reason it will not work.
Arduino says and I agree, in general, the const keyword is preferred for defining constants and should be used instead of #define
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon
My experience hours are >75,000 and I stopped counting in 2004.
Major Languages - 360 Macro Assembler, Intel Assembler, PLI/1, Pascal, C plus numerous job control and scripting
@maxairedale
For caveats, see https://docs.arduino.cc/learn/built-in-libraries/software-serial
I had a psychic girlfriend but she left me before we met.
I tried it and in a word it was frustrating.
It appears that the library DFRobotDFPlayerMini cannot handle two players. If it can I could not make it work. After many hours of trying and researching, I found the library DFPlayerMini_Fast ( https://github.com/PowerBroker2/DFPlayerMini_Fast/releases ) along with some coding suggestions also on the web I was able to get 2 DFPlayers to work with one Arduino Nano.
I put a 1K ohm resistor on each of the RX TX pins of the DFPlayers to the respective pins on the Nano.
The attached sketch is what I used for test purposes only. In my final project, if I go this way, the sketch will be slightly different.
#include"Arduino.h"
#include"SoftwareSerial.h"
#include"DFPlayerMini_Fast.h"
DFPlayerMini_Fast player1;
DFPlayerMini_Fast player2;
SoftwareSerial player1_RxTx(10, 11); // RX, TX Arduino pin 10 is attached to DfPalyer1 pin 3 Arduino pin 11 is attached to DfPlayer1 pin 2
SoftwareSerial player2_RxTx(7, 8); // RX, TX Arduino pin 7 is attached to DfPalyer2 pin 3 Arduino pin 8 is attached to DfPlayer2 pin 2
int button = 2;
voidsetup(){
player1_RxTx.begin(9600); // hardware uart
player2_RxTx.begin(9600); // hardware uart
Serial.begin(115200);
player1.begin(player1_RxTx); // player1_RxTx uart assoc'd with player1
player2.begin(player2_RxTx); // player2_RxTx uart assoc'd with player2
pinMode(button, INPUT_PULLUP);
player1.volume(30);
player2.volume(30);
delay(500);
/******************************************
** Player 1 is started in the setup() **
** Player 1 is playing the second track **
***************************************/
player1.play(2);
delay(500);
Serial.println("Looping player1 Track 2");
}
voidloop(){
/***************************************
** the sketch is waiting for digital pin **
** 2 to go low. If pin 2 is low player2 **
** starts to play **
******************************************/
Serial.println("Checking button press");
if(!digitalRead(button)){
player2.play(1); // Play audio track 0001
delay(1000);
Serial.println("Playing player1 track 1");
}
}
Good, I'm glad you found the "secret sauce" and got it working.
I had a psychic girlfriend but she left me before we met.