News:

Let's find out together what makes a PIC Tick!

Main Menu

DFPlayer

Started by shantanu@india, Today at 05:39 AM

Previous topic - Next topic

shantanu@india

Hi,
Has anybody integrated DFPlayer with a microcontroller?
I am facing some issues.
When I issue the play command by sending 0x7E 0xFF 0x06 0x03 0x00 0x00 0x01 0xEF  via the UART port it plays the 11th track instead of the first track.
Regards
Shantanu

JonW

Many moons ago.  I had a similar problem because DFPlayer plays tracks in the order they were written to the FAT filesystem, not by filename. If you copied files to the card in a non-sequential order, or the card was reformatted, and files recopied, the FAT entry order won't match the numeric filenames.

I had to do a fresh low-level format of the SD card, then copy the files across in strict numerical order in a single operation. On Windows, dragging them all at once often still writes them out of sync, so it's better to use a copy in CMD or a dedicated SD card tool that writes sequentially.

Quick verification: If you send 0x7E 0xFF 0x06 0x03 0x00 0x00 0x0B 0xEF (track 11) and it plays what you'd expect to be another track, then it confirms the FAT issue.

shantanu@india

Regards
Shantanu

charliecoutas

#3
Hi Shantanu

I have used DF Player a lot. Below is a command example from one of my progs:

                       Mine:      $7E + $FF + $06 +  $0F  +   $00   +  $00 +  $00  +  $0000 + $EF   
                                  ---   ---   ---    ---   --------   ----  -------   -----   ---
                                     hddr   vsn     Len     cmd   feedback    fldr    track    chksum    End

                       Yours:     0x7E  0xFF   0x06    0x03      0x00      0x00    0x01      ??         0xEF

As far as I an see, you've missed the checksum.

Mine plays the files in the order you command, the actual files logical position on the card makes no difference. I'll go into it a bit deeper later on when I have some time.

Best regards
Charlie

charliecoutas

Not sure if I've got this format right but here's my Play_track procedure:

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                       Mp_data =  $7E + $FF + $06 +  $0F  +   $00   +  $00 +  $00  +  $0000 + $EF   
;                                 ---   ---   ---    ---   --------   ----  -------   -----
;                                 hddr  vsn   len    cmd   feedback   fldr   track   chksum   end
   
Proc Play_track(pFolder As Byte, pTrack As Byte)                        ;this plays a track on the mp3 DF Player - binary byte value is track no 1-255
  Dim mp_check As Word                                                  ;16 bit checksum in +7 +8 posns

   If pTrack = 0 Then                                                   ;requesting track zero stops the curent track playing

           HRSOut1  $7E,  $FF,  $06,  $0E,  $0,   $0,    $0,  $FE, $ED, $EF  ;this stops the player
           DelayMS Busy_time
           
           Else                                                         ;..it's a valid track number

           Mp_data = $7E + $FF + $06 + $0F + $0 +  $0  +  $0  +  $0 + $0 + $EF ;basic "play folder/track" profile, leave checksum blank for now 
;                                                 ===    ===
;                                                 fld    trk
           mp_data#5 = pfolder
           mp_data#6 = pTrack
           mp_check = $FF + $06 + $0F + 0 + pfolder + pTrack            ;form checksum
           mp_check = -mp_check                                         ;negate it
           mp_data#7 = mp_check.Byte1                                   ;plant checksum in string
           mp_data#8 = mp_check.Byte0
 
           For I = 0 To 9                                               ;can't use HRSOUT string because string contains zeros!
               HRSOut1 Mp_data[I]                                       ;send next char of 10 to mp3 player                                           
           Next
           
           DelayMS Busy_time                                            ;just in case we examine BUSY too early before the player has set it??
                                                                        ;..BUSY seems to be high for 50mS so this should be OK
   EndIf
EndProc

shantanu@india

Thank you very much Charlie.
Yes I've omitted the checksum bytes purposefully which maybe I shouldn't have done. The datasheet says that the checksum is optional but its better to provide it for packet integrity .
0x7E 0xFF 0x06 0x03 0x00 0x00 0x01 0xEF  should play track number 001.mp3 directly from the SD card(without any folder structure). My problem is that sometimes instead of playing track number 001.mp3 it plays 011.mp3  due to no reason at all !
Inserting all the tracks in a single folder "01" & playing track number 001.mp3 by sending 0x7E 0xFF 0x06 0x0F 0x00 0x01 0x01 0xEF seems to be a more robust approach.
Regards
Shantanu

charliecoutas

You are very welcome. I settled on several folders to make life easier. At the museum we run an Escape Room where part of the solution involves telephones (some very old bakelite ones too!) I needed several messages which grouped well into folders and it works just fine. The phones have been modified to include a DF-Player, an audio amp and, of course, an 18F26K22.

I also use a lot of HC-12 modules (433MHZ two way RS232 radio modules). Another project has a number of "Spies" dotted around the museum. They are polled from a Spy Finder and the user has to wander round and discover them all and learn some codes (Bletchley Park of course). The finder therefore gets bombarded with responses from all the Spies in range. This sometimes results in the HC12 stopping it RX side. The only way I could get round this was to add power-cycling. I did try polling each Spy in turn but it took far too long. I mention this in case other forum users experience odd behaviour with HC12's. There are several rip-off vsns on the market which is another headache.

If you've had trouble with HC12, see if I can help. A true RESET pin would be nice but it just ain't so.

Charlie

xvovanx

In my projects, these audio modules work perfectly, and the command is used without a checksum. I can also write files to the SD card in any order, and everything works without any problems. You need to use older SD cards up to 2 GB, formatted as FAT, and create a folder named "mp3" on the card. Then copy the files into that folder with names 0001.mp3, 0002.mp3...

VOICE_SEND:
RsOut $7E,$FF,$06,$12,$00,VOICE_NR.HighByte,VOICE_NR.LowByte,$EF 
DelayMS 1000
If VOICE_BUSY=1 Then             
    Repeat                                                                                                                   
        DelayMS 100                                                       
    Until PLAYER_BUSY=1         
EndIf
Return