Notifications
Clear all

Can an Arduino control 2 DfMini mp2 players

5 Posts
3 Users
1 Likes
361 Views
(@maxairedale)
Member
Joined: 12 months ago
Posts: 5
Topic starter  

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.


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7005
 

Posted by: @maxairedale

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.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@maxairedale

For caveats, see https://docs.arduino.cc/learn/built-in-libraries/software-serial

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@maxairedale)
Member
Joined: 12 months ago
Posts: 5
Topic starter  

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");
}
}
 
 
Thanks for viewing

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@maxairedale 

Good, I'm glad you found the "secret sauce" and got it working.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote