Advertisement
Guest User

Yerke Post about DF Player mini commands

a guest
Sep 8th, 2018
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.68 KB | None | 0 0
  1. Post on April 04,2015 17:49
  2. The most simple way to get sound out of your board, I found in the Arduino forum about this subject. Simply put a MP3 sound file with the name 0001.mp3 in the root of your SD card and execute the next program. It will play the song one time.
  3. A datasheet and an Arduino library can be found at: http://www.dfrobot.com/index.php?route=product/product&product;_id=1121http://www.dfrobot.com/index.php?route=product/product&product;_id=1121
  4. I used USB 3.0 (although 2.0 will do the job as well when volume is turned down) of my PC to power the Arduino and the module. Don't connect the power of the DFPlayer to the +5V pin but use the Vin pin instead (only when USB powered !!!!) to prevent overloading the Arduino regulator. When using an external power source, be sure to power the module seperately with 5V (In theory power consumption of the module might exceed 3 Watts):
  5.  
  6. // **************************************************
  7. // Very important: Use serial 1K resistors on RX and TX
  8. // to suppress noise
  9. // Connect Sound module board RX to Arduino pin 11
  10. // Connect Sound module board TX to Arduino pin 10
  11. // **************************************************
  12.  
  13. #include "SoftwareSerial.h"
  14. SoftwareSerial mySerial(10, 11);
  15. char play[10] = { 0X7E, 0xFF, 0x06, 0X03, 00, 00, 0x01, 0xFE, 0xF7, 0XEF};
  16.  
  17. void setup () {
  18. mySerial.begin (9600);
  19. delay(1000);
  20. for (int count=0; count<10; count++) { mySerial.write( play[count]); }
  21. }
  22.  
  23. void loop () {
  24. }
  25.  
  26.  
  27. Post on April 05,2015 01:33
  28. After some time of experimenting, I found the datasheet on the DF Robot website very incomplete and even wrong for many commands.
  29. Although the Arduino library that is offerd by DF Robot fullfils a need, it is pretty easy to write a sketch without the library. The program listed below (Arduino Uno) is made to reveal all the available commands in the module. In the leading comment of the sketch, all commands I found available in the module are documented. In your Serial Monitor type in a DFPlayer mini command with its parameters and see and hear what is happening. It is very easy to make your own sketch based on all available (and undocumented) commands. I hope it will help.
  30. Because of the poor formatting of the forum editor, you can download a copy here.
  31.  
  32. /*
  33. DF Player mini command discovery
  34. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. Program is mend to discover all the possibilities of the command
  36. structure of the DFPlayer mini. No special libraries are needed.
  37. Program is very easy to understand and can be the basis for your own mp3 player sketch.
  38. Note: Commands are not always correct described in the manual. I tried to fix it, but
  39. there is still a something to do. The commands recoverd so far are listed below.
  40.  
  41. Use of sketch: Enter three (separated) decimal numbers in the Serial Monitor with no end of line character.
  42. First number : Command
  43. Second number: First (High Byte) parameter
  44. Third number : Second (Low Byte) parameter
  45. E.g.: 3,0,1 will play the first track on the TF card
  46.  
  47. Very important: Use serial 1K resistors or a level shifter between module RX and TX
  48. and Arduino to suppress noise
  49. Connect Sound module board RX to Arduino pin 11 (via 1K resistor)
  50. Connect Sound module board TX to Arduino pin 10 (via 1K resistor)
  51. Connect Sound module board Vcc to Arduino Vin when powered via USB (preferably 3.0)
  52. else use seperate 5V power supply
  53. Connect Sound module board GND to Arduino GND
  54.  
  55. General DF Player mini command structure (only byte 3, 5 and 6 to be entered in the serial monitor):
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. Byte Function Value
  58. ==== ================ ====
  59. (0) Start Byte 0x7E
  60. (1) Version Info 0xFF (don't know why it's called Version Info)
  61. (2) Number of bytes 0x06 (Always 6 bytes)
  62. (3) Command 0x__
  63. (4) Command feedback 0x__ If enabled returns info with command 0x41 [0x01: info, 0x00: no info]
  64. (5) Parameter 1 [DH] 0x__
  65. (6) Parameter 2 [DL] 0x__
  66. (7) Checksum high 0x__ See explanation below. Is calculated in function: execute_CMD
  67. (8) Checksum low 0x__ See explanation below. Is calculated in function: execute_CMD
  68. (9) End command 0xEF
  69.  
  70. Checksum calculation.
  71. ~~~~~~~~~~~~~~~~~~~~
  72. Checksum = -Sum(byte(1..6)) (2 bytes, notice minus sign!)
  73.  
  74. Commands without returned parameters (*=Confirmed command ?=Unknown, not clear or not validated)
  75. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. CMD CMD
  77. HEX Dec Function Description Parameters(2 x 8 bit)
  78. ==== === =================================== ========================================================================
  79. 0x01 1 Next * [DH]=X, [DL]=X Next file in current folder.Loops when last file played
  80. 0x02 2 Previous * [DH]=X, [DL]=X Previous file in current folder.Loops when last file played
  81. 0x03 3 Specify track(NUM) * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  82. 1~2999 Playing order is order in which the numbers are stored.
  83. Filename and foldername are arbitrary, but when named starting with
  84. an increasing number and in one folder, files are played in
  85. that order and with correct track number.
  86. e.g. 0001-Joe Jackson.mp3...0348-Lets dance.mp3)
  87. 0x04 4 Increase volume * [DH]=X, [DL]=X Increase volume by 1
  88. 0x05 5 Decrease volume * [DH]=X, [DL]=X Decrease volume by 1
  89. 0x06 6 Specify volume * [DH]=X, [DL]= Volume (0-0x30) Default=0x30
  90. 0x07 7 Specify Equalizer * [DH]=X, [DL]= EQ(0/1/2/3/4/5) [Normal/Pop/Rock/Jazz/Classic/Base]
  91. 0x08 8 Specify repeat(NUM) * [DH]=highByte(NUM), [DL]=lowByte(NUM).Repeat the specified track number
  92. 0x09 9 Specify playback source (Datasheet) ? [DH]=X, [DL]= (0/1/2/3/4)Unknown. Seems to be overrided by automatic detection
  93. (Datasheet: U/TF/AUX/SLEEP/FLASH)
  94. 0x0A 10 Enter into standby – low power loss * [DH]=X, [DL]=X Works, but no command found yet to end standby
  95. (insert TF-card again will end standby mode)
  96. 0x0B 11 Normal working (Datasheet) ? Unknown. No error code, but no function found
  97. 0x0C 12 Reset module * [DH]=X, [DL]=X Resets all (Track = 0x01, Volume = 0x30)
  98. Will return 0x3F initialization parameter (0x02 for TF-card)
  99. "Clap" sound after excecuting command (no solution found)
  100. 0x0D 13 Play * [DH]=X, [DL]=X Play current selected track
  101. 0x0E 14 Pause * [DH]=X, [DL]=X Pause track
  102. 0x0F 15 Specify folder and file to playback * [DH]=Folder, [DL]=File
  103. Important: Folders must be named 01~99, files must be named 001~255
  104. 0x10 16 Volume adjust set (Datasheet) ? Unknown. No error code. Does not change the volume gain.
  105. 0x11 17 Loop play * [DH]=X, [DL]=(0x01:play, 0x00:stop play)
  106. Loop play all the tracks. Start at track 1.
  107. 0x12 18 Play mp3 file [NUM] in mp3 folder * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  108. Play mp3 file in folder named mp3 in your TF-card. File format exact
  109. 4-digit number (0001~2999) e.g. 0235.mp3
  110. 0x13 19 Unknown ? Unknown: Returns error code 0x07
  111. 0x14 20 Unknown ? Unknown: Returns error code 0x06
  112. 0x15 21 Unknown ? Unknown: Returns no error code, but no function found
  113. 0x16 22 Stop * [DH]=X, [DL]=X, Stop playing current track
  114. 0x17 23 Loop Folder 01 * [DH]=x, [DL]=1~255, Loops all tracks in folder named "01"
  115. 0x18 24 Random play * [DH]=X, [DL]=X Random all tracks, always starts at track 1
  116. 0x19 25 Single loop * [DH]=0, [DL]=0 Loops the track that is playing
  117. 0x1A 26 Pause * [DH]=X, [DL]=(0x01:pause, 0x00:stop pause)
  118.  
  119. Commands with returned parameters (*=Confirmed command ?=Unknown, not clear or not validated)
  120. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. CMD CMD
  122. HEX Dec Function Description Parameters(2 x 8 bit)
  123. ==== === =================================== ===========================================================================
  124. 0x3A 58 Medium inserted * [DH]=0, [DL]=(1:U-disk, 2:TF-card)
  125. 0x3B 59 Medium ejected * [DH]=0, [DL]=(1:U-disk, 2:TF-card)
  126. 0x3C 60 Finished track on U-disk * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  127. Not validated. Returns track number when song is finished on U-Disk
  128. 0x3D 61 Finished track on TF-card * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  129. Returns track number when song is finished on TF
  130. 0x3E 62 Finished track on Flash * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  131. Not validated. Returns track number when song is finished on Flash
  132. 0x3F 63 Initialization parameters * [DH]=0, [DL]= 0 ~ 0x0F. Returned code when Reset (0x12) is used.
  133. (each bit represent one device of the low-four bits)
  134. See Datasheet. 0x02 is TF-card. Error 0x01 when no medium is inserted.
  135. 0x40 64 Error ? [DH]=0, [DL]= 0~7 Error code(Returned codes not yet analyzed)
  136. 0x41 65 Reply ? [DH]=0, [DL]= 0~? Return code when command feedback is high
  137. 0x00 no Error (Other returned code not known)
  138. 0x42 66 The current status * [DH] = Device number [DL] = 0 no play, 1 play
  139. 0x43 67 The current volume * [DH]=0, [DL]= Volume (0-30)
  140. 0x44 68 The current EQ * [DH]=0, [DL]= EQ(0/1/2/3/4/5) [Normal/Pop/Rock/Jazz/Classic/Base]
  141. 0x45 69 The current playback mode * [DH]=0, [DL]= (0x00: no CMD 0x08 used, 0x02: CMD 0x08 used, not usefull)
  142. 0x46 70 The current software version * [DH]=0, [DL]= Software version. (My version is 5)
  143. 0x47 71 The total number of U-disk files * [DH]=highByte(NUM), [DL]=lowByte(NUM). Not validated
  144. 0x48 72 The total number of TF-card files * [DH]=highByte(NUM), [DL]=lowByte(NUM)
  145. 0x49 73 The total number of flash files * [DH]=highByte(NUM), [DL]=lowByte(NUM). Not validated
  146. 0x4A 74 Keep on (Datasheet) ? Unknown. No returned parameter
  147. 0x4B 75 The current track of U-Disk * [DH]=highByte(NUM), [DL]=lowByte(NUM), Current track on all media
  148. 0x4C 76 The current track of TF card * [DH]=highByte(NUM), [DL]=lowByte(NUM), Current track on all media
  149. 0x4D 77 The current track of Flash * [DH]=highByte(NUM), [DL]=lowByte(NUM), Current track on all media
  150. 0x4E 78 Folder "01" [DH]=x, [DL]=1 * [DH]=0, [DL]=(NUM) Change to first track in folder "01"
  151. Returns number of files in folder "01"
  152. 0x4F 79 The total number of folders * [DH]=0, [DL]=(NUM), Total number of folders, including root directory
  153.  
  154. Additional info can be found on DFRobot site, but is not very reliable
  155. Additional info:http://www.dfrobot.com/index.php?route=product/product&product;_id=1121
  156.  
  157. Ype Brada 2015-04-06
  158. */
  159.  
  160. #include "SoftwareSerial.h"
  161. # define Start_Byte 0x7E
  162. # define Version_Byte 0xFF
  163. # define Command_Length 0x06
  164. # define End_Byte 0xEF
  165. # define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
  166. SoftwareSerial mySerial(10, 11);
  167.  
  168. void setup () {
  169. Serial.begin(9600);
  170. mySerial.begin (9600);
  171. execute_CMD(0x3F, 0, 0); // Send request for initialization parameters
  172. while (mySerial.available()<10) // Wait until initialization parameters are received (10 bytes)
  173. delay(30); // Pretty long delays between succesive commands needed (not always the same)
  174. // Initialize sound to very low volume. Adept according used speaker and wanted volume
  175. execute_CMD(0x06, 0, 5); // Set the volume (0x00~0x30)
  176. }
  177.  
  178. void loop () {
  179. if (Serial.available())
  180. {
  181. // Input Serial monitor: Command and the two parameters in decimal numbers (NOT HEX)
  182. // E.g. 3,0,1 (or 3 0 1 or 3;0;1) will play first track on the TF-card
  183. byte Command = Serial.parseInt();
  184. byte Parameter1 = Serial.parseInt();
  185. byte Parameter2 = Serial.parseInt();
  186. // Write the input at the screen
  187. Serial.print("Command : 0x");if (Command < 16) Serial.print("0"); Serial.print(Command, HEX);
  188. Serial.print("("); Serial.print(Command, DEC);
  189. Serial.print("); Parameter: 0x");if (Parameter1 < 16) Serial.print("0");Serial.print(Parameter1, HEX);
  190. Serial.print("("); Serial.print(Parameter1, DEC);
  191. Serial.print("), 0x");if (Parameter2 < 16) Serial.print("0");Serial.print(Parameter2, HEX);
  192. Serial.print("("); Serial.print(Parameter2, DEC);Serial.println(")");
  193. // Excecute the entered command and parameters
  194. execute_CMD(Command, Parameter1, Parameter2);
  195. }
  196.  
  197. if (mySerial.available()>=10)
  198. {
  199. // There is at least 1 returned message (10 bytes each)
  200.  
  201. // Read the returned code
  202. byte Returned[10];
  203. for (byte k=0; k<10; k++)
  204. Returned[k] = mySerial.read();
  205. // Wtite the returned code at the screen
  206. Serial.print("Returned: 0x"); if (Returned[3] < 16) Serial.print("0"); Serial.print(Returned[3],HEX);
  207. Serial.print("("); Serial.print(Returned[3], DEC);
  208. Serial.print("); Parameter: 0x"); if (Returned[5] < 16) Serial.print("0"); Serial.print(Returned[5],HEX);
  209. Serial.print("("); Serial.print(Returned[5], DEC);
  210. Serial.print("), 0x"); if (Returned[6] < 16) Serial.print("0"); Serial.print(Returned[6],HEX);
  211. Serial.print("("); Serial.print(Returned[6], DEC); Serial.println(")");
  212. }
  213. }
  214. void execute_CMD(byte CMD, byte Par1, byte Par2)
  215. // Excecute the command and parameters
  216. {
  217. // Calculate the checksum (2 bytes)
  218. word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
  219. // Build the command line
  220. byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
  221. Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
  222. //Send the command line to the module
  223. for (byte k=0; k<10; k++)
  224. {
  225. mySerial.write( Command_line[k]);
  226. }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement