2 DFMini mp3 players not working

  pinMode(BusyPin_1, INPUT);  // PIN 12 ON NANO
  pinMode(BusyPin_2, INPUT);  // PIN 13 ON NANO

Try changing these to INPUT_PULLUP

Pin 16 on the mp3 player is either high or low, its output is not floating, but I will give it a try.

I can do that. Is there a forum rule against inserting images?

No. But the forum guide does say

In the same spirit, please don't post an image of the serial monitor instead of the serial monitor output itself, which is text, like code and error messages are :slight_smile: One good reason is that an image of text is probably a thousand times as much data as the text itself.

Posting images of things which are not essentially text is fine.

I added two prints after it reads the busy pin


    Serial.print("Player 1 file number = ");
    Serial.println(player_1_fileNumber);
    Player_1_lastPlayed = player_1_fileNumber;
    Serial.println("attempting to play player 1");
    Mp3Player1.play(player_1_fileNumber);
    int x = digitalRead(BusyPin_1);  // added for testing
    Serial.print("the int x = "); // added for testing
    Serial.println(x);
    while (x == 1) {
      x = digitalRead(BusyPin_1);
    }

Here is the serial monitor's output after adding the prints. Since I don't think you want to see ten seconds of "Player1 loop delay
Player2 loop delay"
I trimmed it

Starting Player 1
Player 1 Online
Starting Player 2
Player 2 Online
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player 1 file number = 11
attempting to play player 1

After that test, I made the Busy Pins INPUT_PULLUP

void setup() {
  Serial.begin(9600);
  pinMode(BusyPin_1, INPUT_PULLUP);  // PIN 12 ON NANO
  pinMode(BusyPin_2, INPUT_PULLUP);  // PIN 13 ON NANO

 startPlayer_1();
 startPlayer_2();
  
}

And again, it stops when trying to play

Starting Player 1
Player 1 Online
Starting Player 2
Player 2 Online
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player 1 file number = 8
attempting to play player 1

Seems pretty certain that the code is getting stuck in the call to .play().

Try this:

    MySerial_1.listen();
    Mp3Player1.play(player_1_fileNumber);

I tried that, it's a no go.

    Serial.print("Player 1 file number = ");
    Serial.println(player_1_fileNumber);
    Player_1_lastPlayed = player_1_fileNumber;
    Serial.println("attempting to play player 1");
    MySerial_1.listen();
    Mp3Player1.play(player_1_fileNumber);
    int x = digitalRead(BusyPin_1);
    Serial.print("the int x = ");
    Serial.println(x);
    while (x == 1) {
      x = digitalRead(BusyPin_1);
    }
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player 1 file number = 12
attempting to play player 1

Thank you. I had not thought about the amount of data used.

I'm fast running out of ideas.

I suppose it could be a bug in the library.

Only the other day, someone was asking for help with their project and that involved 2x BH1750 light sensors. Turned out to be a bug in the library, because when they tried an alternative library, it worked.

There are bugs in the latest version of the DFRobotDFPlayerMini library. I resolved obscure problems a year or so ago by reverting from version 1.0.7 to 1.0.6 which I've used since then. Worth a try.

1.0.6 is the version I'm using.

Thanks for the suggestion.

Long shot. I occasionally encounter problems even with a single player set to 30, due to voltage drop on inherently loud tracks, so with two…

Also try a delay(1000) after setting the volumes.

At a glance that ‘>=‘ looks unusual?


  Mp3Player1.setTimeOut(500);                   // Set Serial communictaion time out 500ms
  Mp3Player1.volume(30);                        // Set volume value (0~30).
  delay(1000);
  Mp3Player1.EQ(DFPLAYER_EQ_BASS);              // Set EQ to BASS (normal/pop/rock/jazz/classic/bass)
  Mp3Player1.outputDevice(DFPLAYER_DEVICE_SD);  // Set device we use SD as default
  Mp3Player1.enableDAC();
  Serial.println("Player 1 Online");
  Mp3Player2.setTimeOut(500);                   // Set Serial communictaion time out 500ms
  Mp3Player2.volume(30);                        // Set volume value (0~30).
  delay(1000);
  Mp3Player2.EQ(DFPLAYER_EQ_BASS);              // Set EQ to BASS (normal/pop/rock/jazz/classic/bass)
  Mp3Player2.outputDevice(DFPLAYER_DEVICE_SD);  // Set device we use SD as default
  Mp3Player2.enableDAC();
  Serial.println("Player 2 Online");

Added the suggested delay

Starting Player 1
Player 1 Online
Starting Player 2
Player 2 Online
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player1 loop delay
Player2 loop delay
Player 1 file number = 4
attempting to play player 1

The sketch did not get past this part of the code " Serial.println("attempting to play player 1")"

   Serial.print("Player 1 file number = ");
    Serial.println(player_1_fileNumber);
    Player_1_lastPlayed = player_1_fileNumber;
    Serial.println("attempting to play player 1");
    Mp3Player1.play(player_1_fileNumber);
    int x = digitalRead(BusyPin_1);
    Serial.print("the int x = ");
    Serial.println(x);

Thanks for the suggestion.

The ">= " means greater than or equal to something
https://docs.arduino.cc/language-reference/en/structure/comparison-operators/greaterThanOrEqualTo/

Yes, I do know that! But is that the test you want to make? I thought the reverse seemed more appropriate?

And my volume point, just in case?

I assume that 0012.mp3 does exist? (And plays OK in other player apps.)

Yes,

 player_1_fileNumber = random(1, 13);
  • The files play just fine in other of the players I have made, as well as the project that has two players if I start just that one player. That was explained in my original post.

Yes, that is the test I want to make. When the difference between the current millis and previous millis is greater or equal to an unsigned long called delayLoop that is set to 10000 (ten seconds) in this test code. In the final project, that delayLoop will be a random value that I have not picked yet.

Declared above, the setup(){}

unsigned long player_1_loopDelay = 0;
unsigned long player_1_PreviousMillis;

within the Player_1_delayLoop() the player_1_PreviousMillis is set to the current millis only if the player_1_loopDelay equals 0 followed by the player_1_loopDelay being set to 10000.

  if (player_1_loopDelay == 0) {
    player_1_PreviousMillis = millis();
    player_1_loopDelay = 10000;
  }
  unsigned long player_1_CurrentMillis = millis();
  if (player_1_CurrentMillis - player_1_PreviousMillis >= player_1_loopDelay) {
    randomSeed(analogRead(0));
    player_1_fileNumber = random(1, 13);

At the end of the file playing, the player_1_loopDelay is set to zero at line 78

if (x == 1) {
      player_1_loopDelay = 0;
    }