PowerBroker2 / DFPlayerMini_Fast

Fast and easy to understand Arduino library to use the DFPlayer Mini MP3 module from DFRobot.com. This is a huge improvement (both in terms of execution speed and simplicity) to the standard library provided by DFRobot.com.
200 stars 31 forks source link

isPlaying() always returns 0 when multiple instances are active #36

Closed kshoichi closed 3 years ago

kshoichi commented 3 years ago

Other functions such as .volume, .play, and .stop all work fine with multiple instances. Tested and confirmed using this code:

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

//audio hardware
SoftwareSerial mySerial1(A0, A1); // RX, TX
SoftwareSerial mySerial2(A2, A3); // RX, TX
SoftwareSerial mySerial3(2, 3); // RX, TX
SoftwareSerial mySerial4(4, 5); // RX, TX
DFPlayerMini_Fast DFP1;
//DFPlayerMini_Fast DFP2;
//DFPlayerMini_Fast DFP3;
//DFPlayerMini_Fast DFP4;

void setup()
{
  Serial.begin(115200); 
  Serial.println(F("Booting Up..."));
  Serial.println(F("Init mySerial 1"));
  mySerial1.begin(9600);
  //mySerial2.begin(9600);
  //mySerial3.begin(9600);
  //mySerial4.begin(9600);

  DFP1.begin(mySerial1);
  //DFP2.begin(mySerial2);
  //DFP3.begin(mySerial3);
  //DFP4.begin(mySerial4);
  DFP1.play(1); 
}

void loop()
{
  Serial.println(DFP1.isPlaying());  
}
kshoichi commented 3 years ago

Looks like .currentVolume() returns -1 instead of the volume when multiple instances are active. So it's probably the same for all the queries. Could be caused by the SoftwareSerial library or this repo's query function?

kshoichi commented 3 years ago

Making SoftwareSerial listen before querying the DFPlayer seems to fix this issue. In this case adding "mySerial1.listen();" prior to the .isPlaying() line makes it work. Not necessary if you are only using one instance of DFPLayerMini_Fast.