mindwidgets_df1201s

CircuitPython driver for DFRobot DFPlayer Pro (DF1201S) MP3 player with onboard storage

  • Author(s): Aaron Silinskas

Implementation Notes

Hardware:

Software and Dependencies:

class mindwidgets_df1201s.DF1201S(uart: busio.UART)

Driver for DFRobot DFPlayer Pro (DF1201S) MP3 player with onboard storage.

Initialize the DFPlayer connection.

Parameters

uart (busio.UART) – the serial connection to the DFPlayer

PLAYMODE_PLAY_ONCE = 3

Play one sound and pause.

Type

play_mode

PLAYMODE_RANDOM = 4

Play a random sound.

Type

play_mode

PLAYMODE_REPEAT_ALL = 2

Repeat all sounds.

Type

play_mode

PLAYMODE_REPEAT_FOLDER = 5

Play all sounds in a folder.

Type

play_mode

PLAYMODE_REPEAT_ONE_SONG = 1

Repeat one sound.

Type

play_mode

property connected: bool

True if the DFPlayer is connected.

decrease_volume(decrement: float) bool

Decrease the volume level.

Note

Persists after power off.

Parameters

decrement (float) – the amount to decrement the volume, as a float between 0 and 1.

Returns

True if the volume was decreased.

disable_amp() bool

Disable the builtin amplifier.

Returns

True if the amp is disabled.

disable_led() bool

Turn the builtin LED off.

Note

Persists after power off.

Returns

True if the LED is off.

disable_prompt() bool

Disable the sound that is played after power on.

Note

Persists after power off.

Returns

True if the prompt is disabled.

enable_amp() bool

Enable the builtin amplifier.

Returns

True if the amp is enabled.

enable_led() bool

Turn the builtin LED on.

Note

Persists after power off.

Returns

True if the LED is on.

enable_prompt() bool

Enable the sound that is played after power on.

Note

Persists after power off.

Returns

True if the prompt is enabled.

fast_forward(seconds: int) bool

Fast forward the currently playing sound.

Parameters

seconds (int) – the number of seconds to fast forward.

Returns

True if fast forward was successful.

fast_rewind(seconds: int) bool

Rewind the currently playing sound.

Parameters

seconds (int) – the number of seconds to rewind.

Returns

True if rewind was successful.

fast_seek(seconds: int) bool

Start playing the current sound at a specific time offset.

Note

If the offset exceeds the sound length, this function still returns True and the sound stops.

Parameters

seconds (int) – the time offset, in seconds.

Returns

True if the current offset was set.

property file_name: str

The file name of the currently playing file.

property file_number: int

The file number of the currently playing file.

increase_volume(increment: float) bool

Increase the volume level.

Note

Persists after power off.

Parameters

increment (float) – the amount to increase the volume, as a float between 0 and 1.

Returns

True if the volume was increased.

play_file_name(file_name: str) bool

Play the sound with the given file name.

Note

Plays the first sound if the file name is invalid. I don’t see a way to turn off this behavior.

Parameters

file_name (str) – the file name to play.

Returns

True if the given file is playing, False if the first file if playing.

play_file_number(file_number: int) bool

Play the sound at the given file number.

Note

Plays the first sound if the file number is invalid. I don’t see a way to turn off this behavior.

Parameters

file_number (int) – the file number to play.

Returns

True if the given file number is playing, False if the first file is playing.

play_last() bool

Play the last sound.

Returns

True if the last sound is playing.

property play_mode: int

Returns the current play mode.

Returns

One of the play mode constants, PLAYMODE_REPEAT_ONE_SONG, PLAYMODE_REPEAT_ALL, or PLAYMODE_PLAY_ONCE. PLAYMODE_RANDOM can be set, but this function will return -1. Bug in the device? PLAYMODE_REPEAT_FOLDER can be set, but this function will return 3. Bug in the device?

play_next() bool

Play the next sound.

Returns

True if the next sound is playing.

property played_time: int

The number of seconds the current sound has played.

property playing: bool

True if a sound is currently playing.

set_baud_rate(rate: int) bool

Set baud rate for the serial DFPlayer connection.

Note

Persists after power off.

Parameters

rate (int) – the baud rate to use. Valid values are 9600、19200、38400、57600、or 115200.

Returns

True if the baud rate was set.

property total_files: int

The total count of sound files available.

property total_time: int

The length of the current sound in seconds.

property volume: float

Volume level, as a float between 0 and 1.