Skip to content
Micropython implementation of DFPlayer control using UART 1 (secondary Serial connection)
Python
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Added pycharm folder suppression Sep 13, 2017
550px-Miniplayer_pin_map.png Image Jul 10, 2017
LICENSE Initial commit Jul 7, 2017
README.md Update README.md Oct 22, 2019
dfplayer.py Config delay lengthened. Added polling finish() method which returns … Sep 13, 2017
scanplayer.py Workaround for volume being set back to 0.5 after test-play Nov 4, 2017

README.md

micropython-dfplayer

Micropython implementation of DFPlayer control using UART 1 (secondary Serial connection) on ESP8266

If you are not limited to ESP8266 (with its TX-only UART) you should consider using https://github.com/jczic/KT403A-MP3/blob/master/kt403A.py instead.

To use, wire up the DFPlayer Mini MP3 breakout module following this loom...

alt text

  • DFPlayer Mini
    • VCC => 5V Vin
    • All GND pins => GND
    • Busy Pin (immediately opposite VCC) => GPIO2 (NodeMCU D3)
    • RX Pin (immediately below VCC) => GPIO0 (NodeMCU D4)
    • SPK1+SPK2 to a 3W speaker (limiting the volume to 0.5 can help prevent brownout for larger wattage speakers)
    • ...or...
    • DAC_R+DAC_L to a 3.5mm Line Out Jack

The following example code uses the ScanPlayer.

It will first scan all available folders for files called 000_XXX.mp3 001_XXX.mp3 and so on.

It considers only folders named 00-09.

It will play a single track from each folder in turn, only repeating a folder when all folders are exhausted, and only repeating a track when all tracks have been exhausted.

from time import sleep
import scanplayer
player = scanplayer.ScanPlayer()
availableFolders = list(player.tracks.keys())
if len(availableFolders) > 0:
    keyPos = 0
    while True:
        folder = availableFolders[keyPos]
        player.playFolder(folder)
        while player.playing():
            sleep(0.1)
        keyPos = (keyPos + 1) %  len(availableFolders)
else:
    print("No available tracks")
You can’t perform that action at this time.