Home

Awesome

pypi version shield pypi downloads per month shield

Description

A micropython library to control the DFPlayer mini mp3 player module.

This library focuses on the most essential functions. Some advanced functions of the DFPlayer, like the equalizer modes are not implemented yet.

Further this library is made to use the folders function of the dfmini. You can use up to 99 folders and 255 files per folder. The files on your micro sd card need to be structured like this:

.
├── 01
│   ├── 001.mp3
│   ├── 002.mp3
│   └── ...
├── 02
│   ├── 001.mp3
│   ├── 002.mp3
│   └── ...
├── 03
│   ├── 001.mp3
│   ├── 002.mp3
│   └── ...
└── ...

There should be no gaps in the numbering scheme. It might be best to prepare the whole file structure on your harddrive first and then copy them in one go on a freshly formated micro sd card, as the DFPlayer might get confused from artifacts left on the sd cards filesystem. You can use the files in /sample_files to test your module.

Sometimes the module isn't able to keep up if you try to send commands to fast, so some delay between the commands is needed.

Connection

DFPlayer mini pinout

Examples

Play a file from a folder

import time
from dfplayer import DFPlayer
df=DFPlayer(uart_id=1,tx_pin_id=4,rx_pin_id=5)
#wait some time till the DFPlayer is ready
time.sleep(0.2)
#change the volume (0-30). The DFPlayer doesn't remember these settings
df.volume(25)
time.sleep(0.2)
#play file ./01/001.mp3
df.play(1,1)

Find the number of files in a folder

If a folder doesn't exist, get_files_in_folder will return 0

import time
from dfplayer import DFPlayer
df=DFPlayer(uart_id=1,tx_pin_id=4,rx_pin_id=5)
#wait some time till the DFPlayer is ready
time.sleep(0.2)
print(df.get_files_in_folder(1))
time.sleep(0.2)
print(df.get_files_in_folder(4))

API

class DFPlayer(uart_id,tx_pin_id=None,rx_pin_id=None)

play(folder,file)

stop()

volume(vol)

volume_up()

volume_down()

get_volume()

ìs_playing()

get_files_in_folder(folder)

reset()

send_cmd(cmd,param1=0,param2=0)

send_query(cmd,param1=0,param2=0)