Friday, July 17, 2026

DFRobot mini with pause for podcasts

For an index to all my stories click this text.

In a previous story I wrote how to use a DFRobot Mini MP3 player. The player is attached to a Raspberry Pi Pico with 5 keys. The key's functions are next song, previous song, volume up, volume down and reset. You can read that story here: 
https://lucstechblog.blogspot.com/2026/07/dfrobot-mini-mp3-with-micropython.html

There are however some more commands you can issue to the MP3 player. And while using it in real life I realized I do miss these commands. So I made some adjustments to the previous design.

Pause and Resume.

The previous design had a reset button. That reset the Pico and the program started fresh making the MP3 player start playing from the first song again.

I am however a frequent podcast listener.
And when listening something urgent happens: the phone rings, the doorbell rings etc.
Stop playing the podcast is annoying as you then have to start all over again. Not a problem for a song of a few minutes but annoying when listening to a podcast of an hour or so.

Luckily the DFRobot MP3 player has a pause function (music.pause()) and a resume function (music.resume()). Pause indeed pauses the player and resume neatly starts where the player was set at pause.
So I adapted the design an added a Pause and resume button.

I also rewired the reset button to another pin and altered the software so that it makes the player sop playing. Pressing any button (except the volume buttons) then restarts the player at the next song in line.

Breadboard.


You can find the description in the previous story. I just mention the 3 new buttons here.
The pause and resume button are wired to GPI14 and GPIO15.
The stop button is wired to GPIO11.

As mentioned in the previous story: watch out which pins you use. Pins GPIO12 and GPIO13 are wired to UART0. And UART0 communicates with the DFRobot Mini MP3 player. So pressing a button attached to one of these pins interferes with the Uart communication and makes the player behave strangely.

Please note that the USB power line is only connected to the DFRobot Mini player. It is not connected to the Pico. The GND lines are connected to the Pico and to the player.

The MicroPython program.

Because 1 button is rewired and 2 new buttons are added as wel extra functionality being added the software needs to be adapted. Here is the new program in full.

from dfplayermini import Player
from time import sleep
import machine

vol = 20

butstop   = machine.Pin(11, machine.Pin.IN)

butpause  = machine.Pin(15, machine.Pin.IN)
butresume = machine.Pin(14, machine.Pin.IN)

butnext   = machine.Pin(18, machine.Pin.IN)
butprev   = machine.Pin(19, machine.Pin.IN)
butvolup  = machine.Pin(20, machine.Pin.IN)
butvoldwn = machine.Pin(21, machine.Pin.IN)

busypin = machine.Pin(22, machine.Pin.IN)

txpin = machine.Pin(0)
rxpin = machine.Pin(1, machine.Pin.IN)
music = Player(pin_TX=txpin, pin_RX=rxpin)

stop = False
pause = False

sleep(.2)

music.stop()
sleep(.2)

music.volume(vol)
sleep(.2)
music.play(1)
sleep(2)

while True:
    if butpause.value() == 0:
        print("pause")
        pause = True
        music.pause()
        sleep(.5)
    if butresume.value() == 0:
        print("resume")
        pause = False
        music.resume()
        sleep(.5)
    if butstop.value() == 0:
        print("stop")
        music.stop()
        stop = not stop
        sleep(.5)
    if busypin.value() == 1 and stop == False and pause == False:
        music.play('next')
        sleep(.4)
    if (butnext.value()==0):
        music.stop()
        sleep(.5)
        print ("next number")
        music.play('next')
        sleep(.5)
    if (butprev.value()==0):
        music.stop()
        sleep(.5)
        print ("previous number")
        music.play('prev')
        sleep(.5)
    if (butvolup.value()==0):
        vol = vol + 1
        print ("Volume : ",vol)
        music.volume(vol)
        sleep(.2)
    if (butvoldwn.value()==0):
        vol = vol - 1
        print ("Volume : ",vol)
        music.volume(vol)
        sleep(.2)

Nothing special in this program except this part in the while loop:

    if busypin.value() == 1 and stop == False and pause == False:
        music.play('next')
        sleep(.4)

When the player has played one song it normally stops. The busy pin is LOW when the player plays and gets HIGH when the player stops. This is handled in a different part of the program and already discussed in the previous story.

But we do not want the player to automatically play the next song if the stop and pause buttons have been pressed. And that is handled here.

Copy the program into Thonny's editor and save it in your Pico's memory. If you did not follow the previous story then do so now because it showed where to get the required library.

If you do not have a clue about what Thonny is, how to install MicroPython or how to install libraries please consider buying one of my books, about the Raspberry Pi Pico, listed below.

That's all for now.

Till next time
have fun

Luc Volders