DFPlayer does not play from folder

Hey all, I have some problem with playing mp3 files from DFPlayer from a folder. When I press on the start button it doesn't play at all, though it does make a green light and the red led on the DFPlayer blinks. The busy output shows 0 for a second (which means playing) and then come back straight to 1. Long press let it stay at 0, yet the file is not playing (as it is beginning every time anew). When I put a delay it plays only for the time of the delay and then stops. I used the command playFolder and saved the files as they specified (SD:/XX/XXX.mp3) in the commands list (and the DFPlayer recognizes them all indeed, he just stops to play them immediately after the start). The code worked well before I used the folders and I really have no idea where's the problem here. I would be happy if you guys can help me. Here is the code. I removed all the light methods because they are working well and I wanted to save space. Thank you all :slight_smile: :slight_smile: :slight_smile:

Edit :
Ok, I managed to solve that, the problem was with those lines :
int numberFilesLongFolder = myDFPlayer.readFileCountsInFolder(1) ;
int numberFilesShortFolder = myDFPlayer.readFileCountsInFolder(2) ;

They prevented (apparently) the DFPlayer from accessing the folders or something similar. I moved it to the setup and it works now.

    #include "Arduino.h"
    #include "SoftwareSerial.h"
    #include "DFRobotDFPlayerMini.h"
    
    SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
    DFRobotDFPlayerMini myDFPlayer;
    void printDetail(uint8_t type, int value);
    
    int buttonStart = 5 ;
    int buttonStop = 4 ;
    
    int switchFolderButton = 2 ;
    
      int redLightPin = 6;
    int greenLightPin = 3;
    int blueLightPin = 9 ;
    
    boolean isPlaying = false ;
    
    int randomNumber ;
    
    int busy = 13 ;
    
    boolean playShort = true ;
    boolean playLong = false ;
    
    int numberFilesLongFolder  ;
    int numberFilesShortFolder  ;
    
    //Methods
    
    //start
    void playRandom (int folder, int randomNumber) {
      myDFPlayer.playFolder(folder, randomNumber);  
      if (digitalRead (busy)) {
        green() ;
        isPlaying = true;
      }
    }
   
    //switch short -> long or long -> short
    void switchDirectory () {
      if (playShort) {
        playShort = !playShort ;
        playLong = !playLong ;
        blue () ;
      }
      else if (playLong) {
        playShort = !playShort ;
        playLong = !playLong ;
        blue () ;
      }
    }   
    
    void setup() {
      mySoftwareSerial.begin(9600);
      Serial.begin(115200);
      myDFPlayer.begin (mySoftwareSerial) ;
    
     myDFPlayer.volume(22);
    

      pinMode (buttonStart, INPUT) ;
      digitalWrite (buttonStart, HIGH);
    
      pinMode (buttonStop, INPUT) ;
      digitalWrite (buttonStop, HIGH);
    
      pinMode (volumeUp, INPUT) ;
      digitalWrite (volumeUp, HIGH);
    
      pinMode (volumeDown, INPUT) ;
      digitalWrite (volumeDown, HIGH);
    
      pinMode (switchFolderButton, INPUT) ;
      digitalWrite (switchFolderButton, HIGH);
  
      pinMode (busy, INPUT) ;
    }
    
    
    
    
    void loop() {
    
      int numberFilesLongFolder = myDFPlayer.readFileCountsInFolder(1) ;
      int numberFilesShortFolder = myDFPlayer.readFileCountsInFolder(2) ;
    
      if (myDFPlayer.available()) {
        isPlaying = false;
      }
    
      if (!digitalRead(buttonStart)) {
        delay(100);
        if (!digitalRead(buttonStart)) {
    if (playShort) {
            randomNumber = random (1, numberFilesShortFolder) ;
 playRandom(2, numberFilesShortFolder) ;
        }   
    
          else if (playLong) {
            randomNumber = random (1, numberFilesLongFolder) ;
            playRandom(1, randomNumber);  //Play file
    
          }
        }
      }

      //switch folder
      if (!digitalRead(switchFolderButton) ) {
        delay (100) ;
        if (!digitalRead(switchFolderButton) ) {
          switchDirectory () ;
        }
      }
    }

Hi arad2456,

If you use DFPlayerMini_Fast.h, you can poll the MP3 module with <DFPlayerMini_Fast>.isPlaying(). The function call will return true as long as the module is playing the file. As soon as it returns false, you know the current file is done and can start the next file.

Hope this helps you solve your issue,

Regards,
Mika Hawkins