Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Types | Public Member Functions | Static Public Attributes | List of all members
DFPlayerMini Class Reference

#include <DFPlayerMini.h>

Inheritance diagram for DFPlayerMini:
Inheritance graph

Public Types

enum  Cmd {
  Undefined = 0x00, Next = 0x01, Prev = 0x02, PlayPhysical = 0x03,
  SetVolume = 0x06, SetEqalizer = 0x07, SetDevice = 0x09, Sleep = 0x0A,
  Reset = 0x0C, Play = 0x0D, Pause = 0x0E, PlayTf = 0x12,
  Stop = 0x16, SingleLoop = 0x19, GetStatus = 0x42, GetVolume = 0x43,
  GetUSum = 0x47, GetTfSum = 0x48, GetFlashSum = 0x49, GetUCurrent = 0x4B,
  GetTfCurrent = 0x4C, GetFlashCurrent = 0x4D
}
 

Public Member Functions

 DFPlayerMini (Stream &serial, const uint8_t busyPin=0)
 
void begin (bool bootWait=true)
 
void sendCmd (Cmd cmd, uint16_t arg=0)
 
DFPResponse query (Cmd cmd, uint8_t tries=3)
 
bool busy ()
 
bool check ()
 

Static Public Attributes

static const uint8_t BufferLength = 10
 
static const uint8_t MinimumTimeMs = 20
 
static const uint8_t ResponseTimeoutMs = 20
 
static const uint8_t PacketOffsetCmd = 3
 
static const uint8_t PacketOffsetArg = 5
 
static const uint8_t PacketOffsetCkSum = 7
 

Detailed Description

Easy-to-use controller class for DFPlayer Mini devices.

This class implements some of the functionality of the DFPlayer_Mini_MP3 library, to control a DFPlayer Mini device. It includes features which were not yet implemented in the DFPlayer_Mini_MP3 at time of writing, namely a mechanism to receive results of query calls to the device.

The device is expected to be connected using serial and optionally the BUSY line. Serial comms are at 9600 baud. The BUSY line is pulled to ground when the DFPlayerMini device is playing an mp3 file.

See also:

Definition at line 25 of file DFPlayerMini.h.

Member Enumeration Documentation

◆ Cmd

Command codes.

The DFPlayerMini's serial interface uses this set of command codes to instruct the device to perform some action or reply with some information.

Enumerator
Next 

Play next track.

Prev 

Play previous track.

PlayPhysical 

Play track arg.

SetVolume 

Set volume to arg (0-30)

SetEqalizer 

Set EQ, arg 0-5 (normal=0, pop, rock, jazz, classical, bass)

SetDevice 

Set device, arg 1-5 (U, SD, AUX, SLEEP, FLASH)

Sleep 

Enter low power sleep mode.

Reset 

Exit sleep mode.

Play 

Play track arg.

Pause 

Pause playback.

PlayTf 

Play track arg from (SD card)

Stop 

Stop playback.

SingleLoop 

Loop track arg = boolean !state.

GetStatus 

Get some meaningless status code.

GetVolume 

Get volume setting.

GetUSum 

Get file count U.

GetTfSum 

Get file count Tf.

GetFlashSum 

Get file count Flash.

GetUCurrent 

Get file current U.

GetTfCurrent 

Get file current Tf.

GetFlashCurrent 

Get file current Flash [No response].

Definition at line 44 of file DFPlayerMini.h.

Constructor & Destructor Documentation

◆ DFPlayerMini()

DFPlayerMini::DFPlayerMini ( Stream &  serial,
const uint8_t  busyPin = 0 
)

Constructor.

Parameters
seriala software serial object set at 9600 baud connected to the DFPlayerMini device
busyPinthe pin on the arduino connected to the BUSY pin of the DFPlayerMini. See the busy() documentation for more details.

Definition at line 6 of file DFPlayerMini.cpp.

Member Function Documentation

◆ begin()

void DFPlayerMini::begin ( bool  bootWait = true)

Initialization.

Sets up pin modes and resets state - typically called from begin().

Parameters
bootWaitif true, delay for about 600ms to allow the DFPlayer to boot. Failure to wait can cause the DFPlayer to miss initial commands like volume setting.

Definition at line 13 of file DFPlayerMini.cpp.

Here is the caller graph for this function:

◆ busy()

bool DFPlayerMini::busy ( )

Find out if a sound is playing.

If the BUSY pin has been connected to the arduino and properly set with the busyPin parameter to the DFPlayerMini constructor, the value will be determined by analysing this pin state.

If the busy pin was not passed when the DFPlayerMini was constructed, a GetStatus query will be sent to the player and the result analysed to determine the result. Note that the query method will cause jitter in the audio playback, and takes longer to execute, so the BUSY pin method is recommended if there is a digital input available.

Returns
true if audio is currently playing, else false.

Definition at line 164 of file DFPlayerMini.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check()

bool DFPlayerMini::check ( )

Find out if we can communicate with the device.

Returns
true if comms works, else false

Definition at line 215 of file DFPlayerMini.cpp.

Here is the call graph for this function:

◆ query()

DFPResponse DFPlayerMini::query ( DFPlayerMini::Cmd  cmd,
uint8_t  tries = 3 
)

Send a command and wait for a response.

Parameters
cmdThe command to send.
trieshow many attempts will be made to get a valid result.
Returns
a DFPResponse object with the results of the query. The .ok member will be false if the query failed to get a valid result (possible resons: timeout, bad serial comms etc.)

Definition at line 56 of file DFPlayerMini.cpp.

Here is the caller graph for this function:

◆ sendCmd()

void DFPlayerMini::sendCmd ( DFPlayerMini::Cmd  cmd,
uint16_t  arg = 0 
)

Send a command no response is expected.

Parameters
cmdThe command to send
argThe argument to the command, if one is expected

Definition at line 32 of file DFPlayerMini.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: