Main Page | Projects Index Gallery IndexSite log

 

DFPlayer Interface Board.

Overview

Giving feedback to the user in order to indicate the operation of a given device can can be enhanced if a simple sounder is used in addition to an LCD display. In the past I have found, in most cases, that a Piezo will do the trick quite satisfactorily.

However today it is possible, through the development of cheap mp3 modules to add music or speech to a project with very little effort.

What follows is a description of how to interface one of these devices (the DFPlayer) with a micro-controller (MicoMite28) and an example program is given and briefly discussed (Written in MicroMite Basic)

The DFPlayer Module

 The module itself is very small (20 mm by 20 mm), however the primary reason it was chosen was its exceptionally low cost. This module was £1.88 on Ebay and as a result of this I purchased several in one go for experimentation.

Physically the device appears as below and this is a screen grab from the manual that outlines its operation. This manual can be found at the bottom of this page.

The device can be supplied from either 5 or 3.3 volts with the reservation that if the micro-controller is running from 3.3V and the module is powered from 5V some suitable interface must be included to prevent over driving the inputs to the micro-controller. Even though this dose create an inconvenience, in the circuit discussed later a 5V supply is used for the module. My reason for this was during testing when the module was powered from 3.3V I was plagued by intermittent oscillation of the amplifier on the module that resulted in a continuous howl coming from the speaker. As soon as the supply was moved to 5V this ceased to be a problem.

 

SD File Format

 The module can read a wide range of mp3 file formats as outlined in the manual, however there are very strict naming conventions for files and directories. These are namely that file names can range from 001.mp3 to 255.mp3 in any given numbered directory from '00' to '99'. An example directory is provided at the bottom of this page and if should wish to use it this should be copied onto a freshly formatted SD card.

The example file contains speech, the speech was produced using the https://ttsmp3.com/ Website.

Communicating with the module

 

Initially for testing I connected the module directly to my PC via a USB to RS232 converter, then by using a suitable terminal program fired HEX packets at the module in order to observe the results. I used the some terminal software called HTerm that I found very good for this purpose, but many others are available. HTerm Link: http://www.der-hammer.info/terminal/

To control the player correctly formatted command packets must be sent to the module. These packets are made up of 9 elements as shown below:

To play track 1 in folder 1 we would send:

     7E FF 06 0F 00 01 01 FE EA EF

This breaks down as:

7E = Start of Packet
FF = Always set to FF
06 = Number of Words in the command words
0F = Command for "Specify file and folder to play"
00 = State if serial feedback is needed
01 = Directory Number (0 - 63)Hex, (0 - 99)Dec
01 = File number (00-FF)Hex, (0 - 255)Dec
EF = Checksum Hi
EA = Checksum Lo
EF = End of Packet

A description that explained the creation of the checksum was very hard to find but eventually by looking around online the following method was located.

The start and stop are not included in the checksum, but if the other elements are added together as below:

     FF + 06 + 0F + 00 + 01 + 01 = 116

Then by subtracting this result from zero the Hi and Lo checksums can be calculated.

     0 - 116 = FEEA   (Hi = FE) / (Lo = EA)

When the packet is sent, if you are monitoring the reply from the module then you see the following: 

     7F FF 06 3D 00 00 10 FE AE EF

Which according to the manual a CMD value of 3D is described as "Stay", something may have been lost in translation here. This packet arrives when the module completes the playback of the selected mp3 so could be used in order to indicate when playback has ended.

If however we structured the message as below, substituting the 5th word with a 01 instead of 00 in order to request feedback: 

     7E FF 06 0F 01 01 01 FE E9 EF (note that the checksum has also changed)

Then when the packet is sent, the module would reply:

     7E FF 06 41 00 00 00 FE BA EF

     7E FF 06 3D 00 00 10 FE AE EF

According to the manual the 41 in the first packet is the described as "Reply" the first packet arrives the moment the command is sent to the module and the second packet is much as above arriving when the mp3 playback ends.  

Other command examples are:

play track 2 in folder 1
     7E FF 06 0F 00 01 02 FE E9 EF
play track 3 in folder 1
     7E FF 06 0F 00 01 03 FE E8 EF
play track 1 in folder 2
     7E FF 06 0F 00 02 01 FE E9 EF

volume to 15 out of 30
     7E FF 06 06 00 00 0F FE Ed EF

A BUSY flag is also supplied on the module that indicates when the mp3 player is active, this can also be used in order to identify if a control command can be sent, this line is used on the example program suppled as it provides an easier way in order to monitor the mp3 modules operation.

The DFPlayer Interface Circuit

 

Connecting to the circuit is quite striate forward, as described above R1 and R2 provide protection for the microcontroller running at 3.3V. The 5V supply powers the module and for this suitable de-coupling is included.

 
 

 

Construction

 

The strip board layout shown below is fairly compact with only a small number of track cuts. 

The module is inserted into two 0.1" edge connectors that have been cut to size.

(The images below show revision 1 that used resistors and diodes for the protection circuit however this design had to be revised due to the way in which the busy pin operated)

 

MicroMite Test and Library Program

 

If a formatted MicroSD card is pre loaded with the "01" numbers folder supplied at the bottom of this page and the module is connected to COM1s transmit (pin 21) and a digital IO line (pin 15) of a 28pin MicroMite, then the example program also listed at the bottom of this page can be used to drive the mp3 module.

The program calls upon four subroutines as described below:

Name                         Operation
prep_mp3_module This is called in order to set up an array that is used to hold the command packet.
mp3_volume(n)         This subroutine can be used to set the volume between 0 and 30.
play_mp3(folder,track) This is called in order to play the selected track.
 
run_mp3_packet()  The two previous subrvolumees call upon this program in order to create and send the control packets.

 

Links:

Click here to download the associated project files:

DFPlayer Data Sheet

- Circuit Diagram

- Strpboard Layout

SD Files (Unzip and copy onto a blank microSD card)

MMCODE