Forum >Replies by whispers007
userhead whispers007
Replies (12)
  • You Reply: ^bump (again)

    Still on the look out for a TRIED -n- TRUE solution for reliably detecting when an audio clip is finished playing.

    Especially with the example sketch above.

    * press button -
    * playing a clip using the .play(#) command... (clip #1)
    * keep holding button down -
    * sitting in a loop, constantly checking for this (clip #1) to be finished..
    * Once playback complete is detected, start a .loop(#) command (clip #2)... that will loop until the button is released
    * button release happens
    * stops .loop(#) for clip #2
    * automatically trigger .play(#) (clip #3)

    ...wait for button press/hold again..

    Anyone show me proof where clip #1 doesnt randomly get stick in a LOOP! (that is only intended for clip #2 after clip #1 playback complete is detected)
  • You Reply: For anyone else searching for a solution the speaker 'pop' when using the DFRobot library...

    https://github.com/DFRobot/DFRobotDFPlayerMini

    There is a reset() call made in the begin() method.

    file:
    DFRobotDFPlayerMini.cpp


    part of this method/function:
    bool DFRobotDFPlayerMini::begin(Stream &stream, bool isACK, bool doReset){

    line#:
    103 (I believe)

    this line: (comment it out)
    //reset();


    If anyone else reads about the resistor hack/mod for eliminating the speaker 'pop' by moving the 0R resistor on the bottom of the board, to the other side of the amp, where there are two open pads.

    DO NOT TRY IT... it doesnt work...

    The above works.
  • You Reply: ^bump
  • You Reply: ^bump
  • You Reply: ^bump
  • You Reply: I had the same issue until I used the 1K resistor on the RX & TX lines... then it cleared up during playback.

    Since you are using a speaker..... why are you not using the speaker pins? (but instead the DAC pins?)

    Trying using SPKR1 & SPKR 2


    Not quite the same.. but my lingering problem is a huge POP from the speaker when it gets powered on/off.. playback is fine..

    This article has a theory.. (although I havent tested it)

    http://work-now-dammit.blogspot.dfrobot.at/2 ... scent.html
  • You Reply: Have you tried to keep a counter of the current track being played? ANd then just trying to play that song again from the beginning?

    And then perhaps trying this command after it (to continue the folder looping?)

    myDFPlayer.enableLoopAll()
  • You Reply:
    eleqsis wrote:
    Tue Feb 27, 2018 10:07 am
    The library already provides a function (printDetail > case DFPlayerPlayFinished) that fires if a track has ended. It's within the FullFunction.ino example.
    I cant seem to get the built in function to work/detect when a song finishes accurately when its JUST a .play(#) command..

    If its a loop() or I use dsiableLoop()/enableLoop() around a.play() command.. I get an accurate read every time..

    however.. that seems to mess up the looping behavior of the DFPlayer.. (ie: track 002.wav gets stuck in a loop when it NEVER should... this happens randomly maybe 30% of the time.. other %70 it works as intended)

    I posted some threads here asking about DFPLayer stuff.. in one them is an example sketch I invite anyone to try and see if they also get the erroneous looping issues!!

    I also asked about checking and updating the DFPlayer firmware?? (Looks like I got an old batch from somewhere?)
  • You Reply: Good luck with getting any sort of help here! (The forum, especially when it deals with DFPlayers seems 'dead'.. I have several DFPlayer questions posted.. all 0 replies!)

    Anyways..

    Your servo needs interrupts to work...(Timer).. and the DFPlayer takes serial commands.. (also using interrupts I believe)..

    In order for you to get your sketch to work the way you want it to... you will need to update things to be non-blocking..

    (ie: no delays() are used ANYWHERE in your code).. and instead you use millis() to detect when something should happen. (Check out the blink without delay example sketch in the IDE)

    You might try calling the DFplayer .play() command first.. since it shouldnt need to do anything after the serial command has been sent..
    Even if that does happen to work.. it is still recommended to never (ever) use delays().. when a delay is happening.. nothing else in the code is working.. (you are checking sensors, you arent checking button presses...etc..etc) you dont want to eliminate that stuff.. so its better to never use delays()..

    Or you can use a dedicated servo driver board... but you should not -have- to..

    Good luck!
  • You Reply: WOW!...

    Thats an INSANE customs fee for a product that costs $1.75 USD on ebay!!!

    They have not been too good with answering questions/posts on the forum (I have at least three posts without any responses).. you may want to try and use an alternate method to contact them.


    Good luck!
  • You Reply: Perhaps its my code that is the problem then? The way I am trying to use that then? Because I can NOT seem to get consistent results.. most of the time it doesnt fire at all..

    Basically I'm trying to:

    Upon power on..
    play a boot up sound (001.wav)
    waits/listens for button press/state
    when the button is pressed down, it plays 002.wav file..
    *** if by the time 002.wav file is done playing.. and the button is STILL pressed, .. automatically start to loop 003.wav file.***
    when the button is released play 004.wav file.

    Maybe you have an example of how it should be done?

    heres a quick example where its not working for me:

    Code: Select all
    //import needed libraries
    #include "Arduino.h"
    #include "SoftwareSerial.h"
    #include "DFRobotDFPlayerMini.h"
    
    
    //project vars
    const int buttonPin = 19; //Pin (A5) the pin that the pushbutton is attached to
    int buttonState = 0; // current state of the button
    int lastButtonState = 1; // previous state of the button
    boolean doCompletionCheck = false;
    
    //FSM state control/vars
    #define S_IDLE 1
    #define S_POWERON 2
    #define S_POWERDOWN 3
    
    //FSM init vars
    static int state = S_IDLE; // initial state is 1, the "idle" state.
    
    //instantiate class instances
    SoftwareSerial mySoftwareSerial(10, 11); // RX, TX (DFPlayer connections)
    DFRobotDFPlayerMini myDFPlayer;
    
    void setup() {
    
      //debug (monitor)
      Serial.begin(115200);
    
      //talk to DFPlayer
      mySoftwareSerial.begin(9600);
    
      //declare pin & state
      pinMode(buttonPin, INPUT); // initialize the button pin as a input
      digitalWrite(buttonPin, HIGH); //use interal pull up resistors
    
      //check on DFPlayer state (ready for use?)
      Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
      if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
        Serial.println(F("Unable to begin:"));
        Serial.println(F("1.Please recheck the connection!"));
        Serial.println(F("2.Please insert the SD card!"));
        while (true); //keep checking,...repeat
      }
      Serial.println(F("DFPlayer Mini online."));
    
      //why?
      myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
    
      //----Set volume----
      myDFPlayer.volume(9);  //Set volume value (0~30).
      Serial.print(F("CURRENT VOLUME: ")); //read current volume
      Serial.println(myDFPlayer.readVolume()); //read current volume
    
      //----Set different EQ----//
      myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
    
      //----Set source device, we use SD as default----//
      myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
    
      //play boot sound on power-up
      myDFPlayer.play(1);
    
      Serial.print(F("INTIT STATE: "));
      Serial.println(state);
    
      //delay to let boot sound play and start 'listening' for interaction
      delay(3000);
    }
    
    void loop() {
    
      //FSM state listener
      switch (state) {
        case S_IDLE:
    
          //check main button state
          buttonState = digitalRead(buttonPin);
    
          //** button state HAS changed (compare) **//
          if (buttonState != lastButtonState) {
           
            //-- button state changed and is: pressed (ie: down) --//
            if (buttonState == LOW) {
             
             //any time button is pressed down, trigger power on sound
              state = S_POWERON;
    
             
            //-- button state changed and is: not pressed (ie: up) --//
            }else {       
                 
              //any time button is released, trigger power down sound     
              state = S_POWERDOWN;
                             
            }
           
    
          //** button state has NOT changed  **//     
          }else{
                   
            //check if -still- pressed
            if(buttonState == LOW) {
              //Serial.println(F("READ STATE: "));
              //Serial.println(myDFPlayer.readState());
                       
             if(doCompletionCheck == true){     
                Serial.println(F("watching audio file for completion"));     
               
                //dedicated function attempt for checking track completion
                trackComplete(2, 3, 'l');             
               
                /*
                if(myDFPlayer.readType()==DFPlayerPlayFinished && myDFPlayer.readCurrentFileNumber()==2) { 
                  Serial.println(F("audio finished..."));
                 
                  myDFPlayer.loop(3);
                  doCompletionCheck = false;
                }
                */
              }
    
                                       
            }else{
              //Serial.println(F("BUTTON STILL -NOT- PRESSED........ "));   
            }
          }
    
          //update/save the current button state for next loop/cycle
          lastButtonState = buttonState;
        break;
    
        case S_POWERON:
          //play power up     
          myDFPlayer.play(2);     
          doCompletionCheck = true;     
         
          //return to button checking
          state = S_IDLE;
        break;
    
        case S_POWERDOWN:     
          myDFPlayer.play(4);
         
          //return to button checking
          state = S_IDLE;   
        break;
      }
    
    }
    
    //playMode options: p = play or l = loop
    void trackComplete(int currTrack, int newTrack, uint8_t playMode) { 
      Serial.print(F("Current Track that is playing: "));
      Serial.print(myDFPlayer.read());
      Serial.print(F(" / "));
      Serial.println(myDFPlayer.readCurrentFileNumber());
     
      Serial.print(F("Checking for completetion of track: "));
      Serial.println(currTrack);
      Serial.println(F(""));
      Serial.println(F(""));
     
      //if(myDFPlayer.readType() == DFPlayerPlayFinished && myDFPlayer.read() == currTrack) {
      if(myDFPlayer.readType() == DFPlayerPlayFinished && myDFPlayer.readCurrentFileNumber() == currTrack) {
      //if(myDFPlayer.readType() == DFPlayerPlayFinished) {
       
        doCompletionCheck = false;
       
        Serial.print(F("TRACK MATCH: "));
        Serial.print(myDFPlayer.readCurrentFileNumber());
        //vs.
        Serial.print(F(" / "));
        Serial.println(myDFPlayer.read());       
       
        Serial.println(F("Setting completion listener off---->"));
        switch (playMode) {
          case 'p':
            myDFPlayer.play(newTrack);
          break;
    
          case 'l':
            delay(800);
            myDFPlayer.loop(newTrack);
          break;     
        } 
         
      }
      //back to button checking
      state = S_IDLE;
    }
    
    
  • You Reply: *Looks like the forum doesnt get much traffic any more? (shame)..

    I tried to look in the .h files.. (but really only saw the raw HEX value/command being sent)..

    If there are built in loop functions.... such as loop folder/directory..

    There has to be a pretty efficient way to tell (callback? non blocking looping/function?) that the current files has ended, and do 'whatever' next........no?

    How are others out there detecting how a file has completed playing?

    Thanks.