|
| 1 | +## Description |
| 2 | +A micropython library to control the DFPlayer mini mp3 player module. |
| 3 | + |
| 4 | +This library focuses on the most essential functions. Some advanced functions of the dfmini, like the equalizer modes are not implemented yet. |
| 5 | + |
| 6 | +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. |
| 7 | +The files on your micro sd card need to be structured like this: |
| 8 | + |
| 9 | + . |
| 10 | + ├── 01 |
| 11 | + │ ├── 001.mp3 |
| 12 | + │ ├── 002.mp3 |
| 13 | + │ └── ... |
| 14 | + ├── 02 |
| 15 | + │ ├── 001.mp3 |
| 16 | + │ ├── 002.mp3 |
| 17 | + │ └── ... |
| 18 | + ├── 03 |
| 19 | + │ ├── 001.mp3 |
| 20 | + │ ├── 002.mp3 |
| 21 | + │ └── ... |
| 22 | + └── ... |
| 23 | + |
| 24 | +There should be no gaps in the numbering scheme. |
| 25 | +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 dfmini might get confused from artifacts left on the sd cards filesystem. |
| 26 | +You can use the files in /sample_files to test your module. |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | +## Examples |
| 31 | + |
| 32 | +### Play a file from a folder |
| 33 | +```Python |
| 34 | +import time |
| 35 | +from dfplayer import DFPlayer |
| 36 | +df=DFPlayer(uart_id=1,tx_pin_id=4,rx_pin_id=5) |
| 37 | +#wait some time till the DFPlayer is ready |
| 38 | +time.sleep(0.2) |
| 39 | +#change the volume (0-30). The DFPlayer doesn't remember these settings |
| 40 | +df.volume(25) |
| 41 | +time.sleep(0.2) |
| 42 | +#play file ./01/001.mp3 |
| 43 | +df.play(1,1) |
| 44 | +``` |
| 45 | +### Find the number of files in a folder |
| 46 | +If a folder doesn't exist, get_files_in_folder will return -1 |
| 47 | +```Python |
| 48 | +import time |
| 49 | +from dfplayer import DFPlayer |
| 50 | +df=DFPlayer(uart_id=1,tx_pin_id=4,rx_pin_id=5) |
| 51 | +#wait some time till the DFPlayer is ready |
| 52 | +time.sleep(0.2) |
| 53 | +print(df.get_files_in_folder(1)) |
| 54 | +time.sleep(0.2) |
| 55 | +print(df.get_files_in_folder(4)) |
| 56 | +``` |
| 57 | + |
| 58 | +## API |
| 59 | +### class DFPlayer(uart_id,tx_pin_id=None,rx_pin_id=None) |
| 60 | +- uart_id: Uart channel you want to use (0 or 1 for pi pico) |
| 61 | +- tx_pin_id: Pin id for uart tx if your board supports changing the pins of the uart channel. |
| 62 | +- tx_pin_id: Pin id for uart rx if your board supports changing the pins of the uart channel. |
| 63 | + |
| 64 | +```play(folder,file)``` |
| 65 | +Play a file from a folder (stops all previous playback) |
| 66 | +- folder: Folder number of the file you want to play |
| 67 | +- file: File number of the file you want to play |
| 68 | + |
| 69 | +```stop()``` |
| 70 | +Stop all playback |
| 71 | + |
| 72 | +```volume(vol)``` |
| 73 | +Set the volume of the module |
| 74 | +- vol: Volume of the module. The range is 0 to 30. The DFPlayer doesn't remember these settings |
| 75 | + |
| 76 | +```get_volume()``` |
| 77 | +Returns the current volume setting of the module |
| 78 | + |
| 79 | +```ìs_playing()``` |
| 80 | +Returns if currently some playback is running |
| 81 | + |
| 82 | +```get_files_in_folder(folder)``` |
| 83 | +Returns the number of files in a folder or -1 if the folder doesn't exist |
| 84 | +- folder: folder to get the number of files in |
| 85 | + |
| 86 | +```reset()``` |
| 87 | +Reset the module |
| 88 | + |
| 89 | +```send_cmd(cmd,param1=0,param2=0)``` |
| 90 | +Sends a command byte with 2 bytes for parameters to the module. |
| 91 | +This can be used to send commands not yet implemented in this library |
| 92 | +- cmd: cammand byte (0-255) |
| 93 | +- param1: parameter 1 or MSB of a 2 byte parameter |
| 94 | +- param2: parameter 2 or LSB of a 2 byte parameter |
| 95 | + |
| 96 | +```send_query(cmd,param1=0,param2=0)``` |
| 97 | +Like send_cmd, but returns the bytes the module sends as answer to the query |
| 98 | +- cmd: cammand byte (0-255) |
| 99 | +- param1: parameter 1 or MSB of a 2 byte parameter |
| 100 | +- param2: parameter 2 or LSB of a 2 byte parameter |
| 101 | + |
0 commit comments