Go Down

Topic: New and Improved DFPlayer Mini Library!! (Read 11408 times) previous topic - next topic

Power_Broker

Yes, but with one small edit: in order to use multiple software serial ports, you must call SWSerialPort.listen() (SWSerialPort being either Serial1 or Serial2 in your case) before each call from the class DFPlayerMini_Fast.

Here's an example:

Code: [Select]


#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>

SoftwareSerial Serial1(2, 3); // RX, TX
SoftwareSerial Serial2(4, 5); // RX, TX

DFPlayerMini_Fast myMP3One;
DFPlayerMini_Fast myMP3Two;
// Or DFPlayerMini_Fast myMP3One, myMP3Two;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(9600);
  Serial2.begin(9600);

  myMP3One.begin(Serial1);
  myMP3Two.begin(Serial2);
 
  Serial.println("Setting volume to max");
  Serial1.listen();    //<---------------------------------- #
  myMP3One.volume(30);
  Serial2.listen();    //<---------------------------------- #
  myMP3Two.volume(30);
  delay(20);
 
  Serial.println("Playing track 1 player 1 for 5 sec");
  Serial1.listen();    //<---------------------------------- #
  myMP3One.play(1);
  Serial.println("Playing track 2 player 2 for 5 sec");
  Serial2.listen();    //<---------------------------------- #
  myMP3Two.play(2);
  delay(5000);

  Serial.println("Looping track 1");
  Serial1.listen();    //<---------------------------------- #
  myMP3One.loop(1);
}

void loop()
{
  //do nothing
}
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up