Simple test

Ensure your device works with this simple test. When working, will play the first sound stored on the DFPlayer Pro.

examples/df1201s_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2022 Aaron Silinskas for Mindwidgets
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import board
 6import busio
 7from mindwidgets_df1201s import DF1201S
 8
 9uart = busio.UART(tx=board.GP16, rx=board.GP17, baudrate=115200)
10
11df_player = DF1201S(uart)
12df_player.volume = 0.2
13df_player.play_mode = DF1201S.PLAYMODE_PLAY_ONCE
14
15if not df_player.play_next():
16    print("No sound files to play!")
17
18while True:
19    pass

More Features

Explore more features of the DFPlayer Pro, including volume adjustment, play modes, and play status.

examples/df1201s_morefeatures.py
 1# SPDX-FileCopyrightText: Copyright (c) 2022 Aaron Silinskas for Mindwidgets
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import board
 7import busio
 8from mindwidgets_df1201s import DF1201S
 9
10uart = busio.UART(tx=board.GP16, rx=board.GP17, baudrate=115200)
11
12df_player = DF1201S(uart)
13
14print("Disabling start-up prompt (persists after power off)")
15df_player.disable_prompt()
16
17print("Volume:", df_player.volume)
18df_player.volume = 0.2
19print("New Volume:", df_player.volume)
20df_player.increase_volume(0.05)
21print("Increased Volume:", df_player.volume)
22df_player.decrease_volume(0.1)
23print("Decreased Volume:", df_player.volume)
24df_player.play_mode = DF1201S.PLAYMODE_REPEAT_ONE_SONG
25print("Mode:", df_player.play_mode)
26
27print("File Count:", df_player.total_files)
28
29df_player.enable_led()
30print("Play song")
31
32if not df_player.play_next():
33    print("No sound files to play!")
34
35print("Current file number:", df_player.file_number)
36print("Current file name: ", df_player.file_name)
37print("Length of the current file in seconds:", df_player.total_time)
38
39while df_player.playing:
40    time.sleep(0.5)
41
42print("Done playing")
43
44df_player.disable_led()
45
46while True:
47    pass