├── LICENSE ├── README.md ├── examples ├── DFPlayer_ESP8266_Basic │ └── DFPlayer_ESP8266_Basic.ino ├── DFPlayer_ESP8266_GD3200B_Basic │ └── DFPlayer_ESP8266_GD3200B_Basic.ino ├── DFPlayer_ESP8266_HW_Serial │ └── DFPlayer_ESP8266_HW_Serial.ino └── DFPlayer_STM32_Basic │ └── DFPlayer_STM32_Basic.ino ├── images ├── DFPlayer_GD3200_Modification.jpg └── DFPlayer_Mini_Modification.jpg ├── keywords.txt ├── library.json ├── library.properties └── src ├── DFPlayer.cpp └── DFPlayer.h /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![license-badge][]][license] ![version] [![stars][]][stargazers] ![hit-count] [![github-issues][]][issues] 2 | 3 | # DFPlayer Mini 4 | This is small and fast Arduino library for: 5 | - DFPlayer Mini, MP3-TF-16P, FN-M16P (**YX5200** chip, **YX5300** chip or **JL AAxxxx** chip from Jieli) 6 | - FN-M10P, FN-M10P (**FN6100** chip) 7 | - DFPlayer Mini HW-247A (**GD3200B** chip) 8 | 9 | ![alt text][dfplayer_mini_mod_image] 10 | 11 | DFPlayer Mini features: 12 | - +3.2v..+5.0v, typical +4.2v 13 | - average curren 24mA 14 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 15 | - micro SD-card, up to 32GB (FAT16, FAT32) 16 | - USB-Disk up to 32GB (FAT16, FAT32) 17 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 18 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 19 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function (move jumper to STBY->BUSY, see picture above) 20 | - UART to communicate, 9600bps (parity: none/data bits: 8/stop bits: 1/flow control: none) 21 | 22 | NOTE: 23 | - If you hear a loud noise, add a 1K resistors in series with DFPlayer TX-pin & RX-pin. 24 | - Move the jumper from right to left to automatically switch the amplifier to standby. 25 | - Files are in the root must contain 4 digits with leading zeros. For example: SD_ROOT/0001 - My favorite song.mp3. Player sorts the root by the time of writing to the card. Do not copy 0003.mp3 and then 0001.mp3 as 0003.mp3 will play first. 26 | - Folders must contain 2 digits with leading zeros. Number of folders 01..99. Files inside must contain 3 digits with leading zeros. The number of files in each folder is 001..255. For example: SD_ROOT/01/001 - My favorite song.mp3. Unlike the root, files from folders can be read by the file number. 27 | - Folder "mp3" and "advert". Files inside this folders must contain 4 digits with leading zeros. The number of files is 0001..9999 and can be read by file number. For example: SD_ROOT/mp3/ 0001 - My favorite song.mp3. Files from "advert" are played only if a track is already playing. Then the module pauses the current one, plays the file from "advert" and unpauses the main one. 28 | 29 | ## Library APIs supports all modules features: 30 | ```c++ 31 | void begin(Stream& stream, uint16_t threshold = 350, DFPLAYER_MODULE_TYPE = DFPLAYER_MINI, bool feedback = false, bool bootDelay = true); 32 | 33 | void setModel(DFPLAYER_MODULE_TYPE = DFPLAYER_MINI); 34 | void setTimeout(uint16_t threshold); //usually 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip 35 | void setFeedback(bool enable); 36 | 37 | void setSource(uint8_t source); //all sources may not be supported by some modules 38 | void playTrack(uint16_t track); 39 | void next(); 40 | void previous(); 41 | void pause(); 42 | void resume(); 43 | void stop(); 44 | 45 | void playFolder(uint8_t folder, uint8_t track); 46 | void playMP3Folder(uint16_t track); 47 | void play3000Folder(uint16_t track); //may not be supported by some modules 48 | void playAdvertFolder(uint16_t track); 49 | void playAdvertFolder(uint8_t folder, uint8_t track); //may not be supported by some modules 50 | void stopAdvertFolder(); 51 | 52 | void setVolume(uint8_t volume); 53 | void volumeUp(); 54 | void volumeDown(); 55 | void enableDAC(bool enable); //flase=mute/true=unmute 56 | void setDACGain(uint8_t gain, bool enable = true); //may not be supported by some modules 57 | void setEQ(uint8_t preset); //may not be supported by some modules 58 | 59 | void repeatTrack(uint16_t track); 60 | void repeatCurrentTrack(bool enable); 61 | void repeatAll(bool enable); 62 | void repeatFolder(uint16_t folder); 63 | void randomAll(); 64 | 65 | void sleep(); 66 | void wakeup(uint8_t source = 2); 67 | void enableStandby(bool enable, uint8_t source = 2); 68 | void reset(); 69 | 70 | uint8_t getStatus(); 71 | uint8_t getVolume(); 72 | uint8_t getEQ(); //may not be supported by some modules 73 | uint8_t getPlayMode(); //may not be supported by some modules 74 | uint8_t getVersion(); 75 | uint16_t getTotalTracksSD(); 76 | uint16_t getTotalTracksUSB(); 77 | uint16_t getTotalTracksNORFlash(); //may not be supported by some modules 78 | uint16_t getTrackSD(); 79 | uint16_t getTrackUSB(); 80 | uint16_t getTrackNORFlash(); //may not be supported by some modules 81 | uint8_t getTotalTracksFolder(uint8_t folder); 82 | uint8_t getTotalFolders(); //may not be supported by some modules 83 | uint8_t getCommandStatus(); 84 | ``` 85 | 86 | Supports: 87 | - Arduino AVR 88 | - Arduino ESP8266 89 | - Arduino ESP32 90 | - Arduino STM32 91 | 92 | 93 | [license-badge]: https://img.shields.io/badge/License-GPLv3-blue.svg 94 | [license]: https://choosealicense.com/licenses/gpl-3.0/ 95 | [version]: https://img.shields.io/badge/Version-3.0.0-green.svg 96 | [stars]: https://img.shields.io/github/stars/enjoyneering/DFPlayer.svg 97 | [stargazers]: https://github.com/enjoyneering/DFPlayer/stargazers 98 | [hit-count]: https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fenjoyneering%2FDFPlayer%2Ftree%2Fmain&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false 99 | [github-issues]: https://img.shields.io/github/issues/enjoyneering/DFPlayer.svg 100 | [issues]: https://github.com/enjoyneering/DFPlayer/issues/ 101 | 102 | [dfplayer_mini_mod_image]: https://github.com/enjoyneering/DFPlayer/blob/main/images/DFPlayer_Mini_Modification.jpg 103 | -------------------------------------------------------------------------------- /examples/DFPlayer_ESP8266_Basic/DFPlayer_ESP8266_Basic.ino: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino sketch for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 12 | - micro SD-card, up to 32GB (FAT16, FAT32) 13 | - USB-Disk up to 32GB (FAT16, FAT32) 14 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 15 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 16 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 17 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 18 | 19 | NOTE: 20 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX pin 21 | - move the jumper from right to left to automatically switch the amplifier to standby 22 | 23 | Frameworks & Libraries: 24 | ESP8266 Core - https://github.com/esp8266/Arduino 25 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 26 | 27 | 28 | GNU GPL license, all text above must be included in any redistribution, 29 | see link for details - https://www.gnu.org/licenses/licenses.html 30 | */ 31 | /***************************************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | 37 | #define MP3_RX_PIN 4 //GPIO4/D2 to DFPlayer Mini TX 38 | #define MP3_TX_PIN 5 //GPIO5/D1 to DFPlayer Mini RX 39 | #define MP3_SERIAL_SPEED 9600 //DFPlayer Mini suport only 9600-baud 40 | #define MP3_SERIAL_BUFFER_SIZE 32 //software serial buffer size in bytes, to send 8-bytes you need 11-bytes buffer (start byte+8-data bytes+parity-byte+stop-byte=11-bytes) 41 | #define MP3_SERIAL_TIMEOUT 350 //average DFPlayer response timeout 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip 42 | 43 | 44 | SoftwareSerial mp3Serial; 45 | DFPlayer mp3; 46 | 47 | 48 | /**************************************************************************/ 49 | /* 50 | setup() 51 | 52 | Main setup 53 | 54 | NOTE: 55 | - moduleType: 56 | - DFPLAYER_MINI: 57 | - DFPlayer Mini module 58 | - MP3-TF-16P module 59 | - FN-M16P module 60 | - YX5200 chip 61 | - YX5300 chip 62 | - JL AAxxxx chip 63 | - DFPLAYER_FN_X10P: 64 | - FN-M10P module 65 | - FN-S10P module 66 | - FN6100 chip 67 | - DFPLAYER_HW_247A: 68 | - HW-247A module 69 | - GD3200B chip 70 | - DFPLAYER_NO_CHECKSUM: 71 | - no checksum calculation (not recomended for MCU without external 72 | crystal oscillator) 73 | */ 74 | /**************************************************************************/ 75 | void setup() 76 | { 77 | Serial.begin(115200); 78 | 79 | mp3Serial.begin(MP3_SERIAL_SPEED, SWSERIAL_8N1, MP3_RX_PIN, MP3_TX_PIN, false, MP3_SERIAL_BUFFER_SIZE, 0); //false=signal not inverted, 0=ISR/RX buffer size (shared with serial TX buffer) 80 | 81 | mp3.begin(mp3Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_MINI, false); //"DFPLAYER_MINI" see NOTE, false=no response from module after the command 82 | 83 | mp3.stop(); //if player was runing during ESP8266 reboot 84 | 85 | mp3.reset(); //reset all setting to default 86 | 87 | mp3.setSource(2); //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash 88 | 89 | mp3.setEQ(0); //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 90 | mp3.setVolume(25); //0..30, module persists volume on power failure 91 | 92 | mp3.sleep(); //inter sleep mode, 24mA 93 | 94 | mp3.wakeup(2); //exit sleep mode & initialize source 1=USB-Disk, 2=TF-Card, 3=Aux, 5=NOR Flash 95 | 96 | mp3Serial.enableRx(true); //enable interrupts on RX-pin for better response detection, less overhead than mp3Serial.listen() 97 | 98 | Serial.println(mp3.getStatus()); //0=stop, 1=playing, 2=pause, 3=sleep or standby, 4=communication error, 5=unknown state 99 | Serial.println(mp3.getVolume()); //0..30 100 | Serial.println(mp3.getCommandStatus()); //1=module busy, 2=module sleep, 3=request not fully received, 4=checksum not match 101 | //5=requested folder/track out of range, 6=requested folder/track not found 102 | //7=advert available while track is playing, 8=SD card not found, 9=???, 10=module sleep 103 | //11=OK command accepted, 12=OK playback completed, 13=OK module ready after reboot 104 | 105 | mp3Serial.enableRx(false); //disable interrupts on RX-pin, less overhead than mp3Serial.listen() 106 | } 107 | 108 | 109 | /**************************************************************************/ 110 | /* 111 | loop() 112 | 113 | Main loop 114 | */ 115 | /**************************************************************************/ 116 | void loop() 117 | { 118 | mp3.playTrack(1); //play track #1, don’t copy 0003.mp3 and then 0001.mp3, because 0003.mp3 will be played firts 119 | //mp3.playMP3Folder(1); //1=track, folder name must be "mp3" or "MP3" & files in folder must start with 4 decimal digits with leading zeros 120 | //mp3.playFolder(1, 2); //1=folder/2=track, folder name must be 01..99 & files in folder must start with 3 decimal digits with leading zeros 121 | 122 | delay(60000); //play for 60 seconds 123 | 124 | mp3.pause(); 125 | 126 | delay(10000); //pause for 10 seconds 127 | } 128 | -------------------------------------------------------------------------------- /examples/DFPlayer_ESP8266_GD3200B_Basic/DFPlayer_ESP8266_GD3200B_Basic.ino: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino sketch for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 12 | - micro SD-card, up to 32GB (FAT16, FAT32) 13 | - USB-Disk up to 32GB (FAT16, FAT32) 14 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 15 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 16 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 17 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 18 | 19 | NOTE: 20 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX pin 21 | - move the jumper from right to left to automatically switch the amplifier to standby 22 | 23 | Frameworks & Libraries: 24 | ESP8266 Core - https://github.com/esp8266/Arduino 25 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 26 | 27 | 28 | GNU GPL license, all text above must be included in any redistribution, 29 | see link for details - https://www.gnu.org/licenses/licenses.html 30 | */ 31 | /***************************************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | 37 | #define MP3_RX_PIN 4 //GPIO4/D2 to DFPlayer Mini TX 38 | #define MP3_TX_PIN 5 //GPIO5/D1 to DFPlayer Mini RX 39 | #define MP3_SERIAL_SPEED 9600 //DFPlayer Mini suport only 9600-baud 40 | #define MP3_SERIAL_BUFFER_SIZE 32 //software serial buffer size in bytes, to send 8-bytes you need 11-bytes buffer (start byte+8-data bytes+parity-byte+stop-byte=11-bytes) 41 | #define MP3_SERIAL_TIMEOUT 350 //average DFPlayer response timeout for GD3200B chip 350msec..500msec 42 | 43 | 44 | SoftwareSerial mp3Serial; 45 | DFPlayer mp3; 46 | 47 | 48 | /**************************************************************************/ 49 | /* 50 | setup() 51 | 52 | Main setup 53 | 54 | NOTE: 55 | - moduleType: 56 | - DFPLAYER_MINI: 57 | - DFPlayer Mini module 58 | - MP3-TF-16P module 59 | - FN-M16P module 60 | - YX5200 chip 61 | - YX5300 chip 62 | - JL AAxxxx chip 63 | - DFPLAYER_FN_X10P: 64 | - FN-M10P module 65 | - FN-S10P module 66 | - FN6100 chip 67 | - DFPLAYER_HW_247A: 68 | - HW-247A module 69 | - GD3200B chip 70 | - DFPLAYER_NO_CHECKSUM: 71 | - no checksum calculation (not recomended for MCU without external 72 | crystal oscillator) 73 | */ 74 | /**************************************************************************/ 75 | void setup() 76 | { 77 | Serial.begin(115200); 78 | 79 | mp3Serial.begin(MP3_SERIAL_SPEED, SWSERIAL_8N1, MP3_RX_PIN, MP3_TX_PIN, false, MP3_SERIAL_BUFFER_SIZE, 0); //false=signal not inverted, 0=ISR/RX buffer size (shared with serial TX buffer) 80 | 81 | mp3.begin(mp3Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_HW_247A, false); //"DFPLAYER_HW_247A" see NOTE, false=no feedback from module after the command 82 | 83 | mp3.stop(); //if player was runing during ESP8266 reboot 84 | 85 | mp3.reset(); //reset all setting to default 86 | 87 | mp3.setSource(2); //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash 88 | 89 | mp3.setEQ(0); //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 90 | mp3.setVolume(25); //0..30, module persists volume on power failure 91 | 92 | mp3.sleep(); //inter sleep mode, 24mA 93 | 94 | mp3.wakeup(2); //exit sleep mode & initialize source 1=USB-Disk, 2=TF-Card, 3=Aux, 5=NOR Flash 95 | 96 | mp3Serial.enableRx(true); //enable interrupts on RX-pin for better response detection, less overhead than mp3Serial.listen() 97 | 98 | Serial.println(mp3.getStatus()); //0=stop, 1=playing, 2=pause, 3=sleep or standby, 4=communication error, 5=unknown state 99 | Serial.println(mp3.getVolume()); //0..30 100 | Serial.println(mp3.getCommandStatus()); //1=module busy, 2=module sleep, 3=request not fully received, 4=checksum not match 101 | //5=requested folder/track out of range, 6=requested folder/track not found 102 | //7=advert available while track is playing, 8=SD card not found, 9=???, 10=module sleep 103 | //11=OK command accepted, 12=OK playback completed, 13=OK module ready after reboot 104 | 105 | mp3Serial.enableRx(false); //disable interrupts on RX-pin, less overhead than mp3Serial.listen() 106 | } 107 | 108 | 109 | /**************************************************************************/ 110 | /* 111 | loop() 112 | 113 | Main loop 114 | */ 115 | /**************************************************************************/ 116 | void loop() 117 | { 118 | mp3.playTrack(1); //play track #1, don’t copy 0003.mp3 and then 0001.mp3, because 0003.mp3 will be played firts 119 | //mp3.playMP3Folder(1); //1=track, folder name must be "mp3" or "MP3" & files in folder must start with 4 decimal digits with leading zeros 120 | //mp3.playFolder(1, 2); //1=folder/2=track, folder name must be 01..99 & files in folder must start with 3 decimal digits with leading zeros 121 | 122 | delay(60000); //play for 60 seconds 123 | 124 | mp3.pause(); 125 | 126 | delay(10000); //pause for 10 seconds 127 | } 128 | -------------------------------------------------------------------------------- /examples/DFPlayer_ESP8266_HW_Serial/DFPlayer_ESP8266_HW_Serial.ino: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino sketch for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 12 | - micro SD-card, up to 32GB (FAT16, FAT32) 13 | - USB-Disk up to 32GB (FAT16, FAT32) 14 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 15 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 16 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 17 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 18 | 19 | NOTE: 20 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX pin 21 | - move the jumper from right to left to automatically switch the amplifier to standby 22 | 23 | Frameworks & Libraries: 24 | ESP8266 Core - https://github.com/esp8266/Arduino 25 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 26 | 27 | 28 | GNU GPL license, all text above must be included in any redistribution, 29 | see link for details - https://www.gnu.org/licenses/licenses.html 30 | */ 31 | /***************************************************************************************************/ 32 | 33 | #include 34 | 35 | 36 | #define MP3_SERIAL_SPEED 9600 //DFPlayer Mini suport only 9600-baud 37 | #define MP3_SERIAL_TIMEOUT 350 //average DFPlayer response timeout 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip 38 | 39 | 40 | DFPlayer mp3; //connect DFPlayer RX-pin to GPIO15(TX) & DFPlayer TX-pin to GPIO13(RX) 41 | 42 | 43 | /**************************************************************************/ 44 | /* 45 | setup() 46 | 47 | Main setup 48 | 49 | NOTE: 50 | - moduleType: 51 | - DFPLAYER_MINI: 52 | - DFPlayer Mini module 53 | - MP3-TF-16P module 54 | - FN-M16P module 55 | - YX5200 chip 56 | - YX5300 chip 57 | - JL AAxxxx chip 58 | - DFPLAYER_FN_X10P: 59 | - FN-M10P module 60 | - FN-S10P module 61 | - FN6100 chip 62 | - DFPLAYER_HW_247A: 63 | - HW-247A module 64 | - GD3200B chip 65 | - DFPLAYER_NO_CHECKSUM: 66 | - no checksum calculation (not recomended for MCU without external 67 | crystal oscillator) 68 | */ 69 | /**************************************************************************/ 70 | void setup() 71 | { 72 | Serial.begin(MP3_SERIAL_SPEED, SERIAL_8N1); //hardware serial on GPIO01(TX) & GPIO03(RX) after boot 73 | 74 | mp3.begin(Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_HW_247A, false); //"DFPLAYER_HW_247A" see NOTE, false=no feedback from module after the command 75 | 76 | Serial.swap(); //now hardware serial on GPIO15(TX) & GPIO13(RX) 77 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 78 | 79 | mp3.stop(); //if player was runing during ESP8266 reboot 80 | mp3.reset(); //reset all setting to default 81 | 82 | mp3.setSource(2); //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash 83 | 84 | mp3.setEQ(0); //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 85 | mp3.setVolume(25); //0..30, module persists volume on power failure 86 | 87 | mp3.sleep(); //inter standby mode, 24mA 88 | 89 | Serial.swap(); //now hardware serial on GPIO01(TX) & GPIO03(RX) 90 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 91 | } 92 | 93 | 94 | /**************************************************************************/ 95 | /* 96 | loop() 97 | 98 | Main loop 99 | */ 100 | /**************************************************************************/ 101 | void loop() 102 | { 103 | Serial.swap(); //now hardware serial on GPIO15(TX) & GPIO13(RX) 104 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 105 | 106 | mp3.wakeup(2); //exit standby mode & initialize sourse 1=USB-Disk, 2=TF-Card, 3=Aux, 5=NOR Flash 107 | 108 | mp3.playTrack(1); //play track #1, don’t copy 0003.mp3 and then 0001.mp3, because 0003.mp3 will be played firts 109 | //mp3.playMP3Folder(1); //1=track, folder name must be "mp3" or "MP3" & files in folder must start with 4 decimal digits with leading zeros 110 | //mp3.playFolder(1, 2); //1=folder/2=track, folder name must be 01..99 & files in folder must start with 3 decimal digits with leading zeros 111 | 112 | mp3.setResponse(true); //enable=request feedback to return not only errors but also OK statuses 113 | 114 | uint8_t response = mp3.getVolume(); //0..30 115 | 116 | Serial.swap(); //now hardware serial on GPIO01(TX) & GPIO03(RX) 117 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 118 | 119 | Serial.println(response); //print volume to Arduino Serial Monitor 120 | 121 | Serial.swap(); //now hardware serial on GPIO15(TX) & GPIO13(RX) 122 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 123 | 124 | response = mp3.getCommandStatus(); //1=module busy, 2=module sleep, 3=request not fully received, 4=checksum not match 125 | //5=requested folder/track out of range, 6=requested folder/track not found 126 | //7=advert available while track is playing, 8=SD card not found, 9=???, 10=module sleep 127 | //11=OK command accepted, 12=OK playback completed, 13=OK module ready after reboot 128 | 129 | Serial.swap(); //now hardware serial on GPIO01(TX) & GPIO03(RX) 130 | Serial.flush(); //clear serial library buffer, ALWAYS CLEAN BUFFER AFTER SERIAL SWAP!!! 131 | 132 | Serial.println(response); //print command status to Arduino Serial Monitor 133 | } 134 | -------------------------------------------------------------------------------- /examples/DFPlayer_STM32_Basic/DFPlayer_STM32_Basic.ino: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino sketch for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 12 | - micro SD-card, up to 32GB (FAT16, FAT32) 13 | - USB-Disk up to 32GB (FAT16, FAT32) 14 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 15 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 16 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 17 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 18 | 19 | NOTE: 20 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX pin 21 | - move the jumper from right to left to automatically switch the amplifier to standby 22 | 23 | Frameworks & Libraries: 24 | ESP8266 Core - https://github.com/esp8266/Arduino 25 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 26 | 27 | 28 | GNU GPL license, all text above must be included in any redistribution, 29 | see link for details - https://www.gnu.org/licenses/licenses.html 30 | */ 31 | /***************************************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | 37 | #define MP3_RX_PIN 10 //PA0 38 | #define MP3_TX_PIN 11 //PA1 39 | #define MP3_SERIAL_SPEED 9600 //DFPlayer Mini suport only 9600-baud 40 | #define MP3_SERIAL_TIMEOUT 350 //average DFPlayer response timeout 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip 41 | 42 | 43 | SoftwareSerial mp3Serial(MP3_RX_PIN, MP3_TX_PIN, false); //false=signal not inverted 44 | DFPlayer mp3; 45 | 46 | 47 | /**************************************************************************/ 48 | /* 49 | setup() 50 | 51 | Main setup 52 | 53 | NOTE: 54 | - moduleType: 55 | - DFPLAYER_MINI: 56 | - DFPlayer Mini module 57 | - MP3-TF-16P module 58 | - FN-M16P module 59 | - YX5200 chip 60 | - YX5300 chip 61 | - JL AAxxxx chip 62 | - DFPLAYER_FN_X10P: 63 | - FN-M10P module 64 | - FN-S10P module 65 | - FN6100 chip 66 | - DFPLAYER_HW_247A: 67 | - HW-247A module 68 | - GD3200B chip 69 | - DFPLAYER_NO_CHECKSUM: 70 | - no checksum calculation (not recomended for MCU without external 71 | crystal oscillator) 72 | */ 73 | /**************************************************************************/ 74 | void setup() 75 | { 76 | Serial.begin(115200); 77 | 78 | mp3Serial.begin(MP3_SERIAL_SPEED); 79 | 80 | mp3.begin(mp3Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_MINI, false); //"DFPLAYER_HW_247A" see NOTE, false=no feedback from module after the command 81 | 82 | mp3.stop(); //if player was runing during ESP8266 reboot 83 | mp3.reset(); //reset all setting to default 84 | 85 | mp3.setSource(2); //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash 86 | 87 | mp3.setEQ(0); //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 88 | mp3.setVolume(25); //0..30, module persists volume on power failure 89 | 90 | mp3.sleep(); //inter sleep mode, 24mA 91 | 92 | mp3Serial.listen(); //enable interrupts on RX-pin for better response detection 93 | 94 | Serial.println(mp3.getStatus()); //0=stop, 1=playing, 2=pause, 3=sleep or standby, 4=communication error, 5=unknown state 95 | Serial.println(mp3.getVolume()); //0..30 96 | Serial.println(mp3.getCommandStatus()); //1=module busy, 2=module sleep, 3=request not fully received, 4=checksum not match 97 | //5=requested folder/track out of range, 6=requested folder/track not found 98 | //7=advert available while track is playing, 8=SD card not found, 9=???, 10=module sleep 99 | //11=OK command accepted, 12=OK playback completed, 13=OK module ready after reboot 100 | 101 | mp3Serial.stopListening(); //disable interrupts on RX-pin 102 | } 103 | 104 | 105 | /**************************************************************************/ 106 | /* 107 | loop() 108 | 109 | Main loop 110 | */ 111 | /**************************************************************************/ 112 | void loop() 113 | { 114 | mp3.playTrack(1); //play track #1, don’t copy 0003.mp3 and then 0001.mp3, because 0003.mp3 will be played firts 115 | //mp3.playMP3Folder(1); //1=track, folder name must be "mp3" or "MP3" & files in folder must start with 4 decimal digits with leading zeros 116 | //mp3.playFolder(1, 2); //1=folder/2=track, folder name must be 01..99 & files in folder must start with 3 decimal digits with leading zeros 117 | 118 | delay(60000); //play for 60 seconds 119 | 120 | mp3.pause(); 121 | 122 | delay(10000); //pause for 10 seconds 123 | } 124 | -------------------------------------------------------------------------------- /images/DFPlayer_GD3200_Modification.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enjoyneering/DFPlayer/4bb0976b21c9394cc8e2b672c8014ed095bd05cf/images/DFPlayer_GD3200_Modification.jpg -------------------------------------------------------------------------------- /images/DFPlayer_Mini_Modification.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enjoyneering/DFPlayer/4bb0976b21c9394cc8e2b672c8014ed095bd05cf/images/DFPlayer_Mini_Modification.jpg -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map DFPlayer 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | 15 | setModel KEYWORD2 16 | setTimeout KEYWORD2 17 | setFeedback KEYWORD2 18 | 19 | setSource KEYWORD2 20 | playTrack KEYWORD2 21 | next KEYWORD2 22 | previous KEYWORD2 23 | pause KEYWORD2 24 | resume KEYWORD2 25 | stop KEYWORD2 26 | 27 | playFolder KEYWORD2 28 | playMP3Folder KEYWORD2 29 | play3000Folder KEYWORD2 30 | playAdvertFolder KEYWORD2 31 | stopAdvertFolder KEYWORD2 32 | 33 | setVolume KEYWORD2 34 | volumeUp KEYWORD2 35 | volumeDown KEYWORD2 36 | enableDAC KEYWORD2 37 | setDACGain KEYWORD2 38 | setEQ KEYWORD2 39 | 40 | repeatTrack KEYWORD2 41 | repeatCurrentTrack KEYWORD2 42 | repeatAll KEYWORD2 43 | repeatFolder KEYWORD2 44 | randomAll KEYWORD2 45 | 46 | 47 | sleep KEYWORD2 48 | wakeup KEYWORD2 49 | enableStandby KEYWORD2 50 | reset KEYWORD2 51 | 52 | getStatus KEYWORD2 53 | getVolume KEYWORD2 54 | getEQ KEYWORD2 55 | getPlayMode KEYWORD2 56 | getVersion KEYWORD2 57 | getTotalTracksSD KEYWORD2 58 | getTotalTracksUSB KEYWORD2 59 | getTotalTracksNORFlash KEYWORD2 60 | getTrackSD KEYWORD2 61 | getTrackUSB KEYWORD2 62 | getTrackNORFlash KEYWORD2 63 | getTotalTracksFolder KEYWORD2 64 | getTotalFolders KEYWORD2 65 | getCommandStatus KEYWORD2 66 | 67 | ####################################### 68 | # Instances (KEYWORD2) 69 | ####################################### 70 | 71 | DFPlayer KEYWORD2 72 | 73 | ####################################### 74 | # Constants (LITERAL1) 75 | ####################################### 76 | 77 | DFPLAYER_MINI LITERAL1 78 | DFPLAYER_FN_X10P LITERAL1 79 | DFPLAYER_HW_247A LITERAL1 80 | DFPLAYER_NO_CHECKSUM LITERAL1 81 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DFPlayer", 3 | "keywords": "dfplayer, mini, yx5200, gd3200, mh2024k, m16p, mp3, serial, esp8266, avr, stm32, driver", 4 | "description": "Arduino library for interacting with the DFPlayer Mini MP3 module", 5 | "authors": 6 | { 7 | "name": "ejoyneering", 8 | "email": "enjoyneering@protonmail.com" 9 | }, 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/enjoyneering/DFPlayer.git" 14 | }, 15 | "version": "3.0.0", 16 | "frameworks": "arduino", 17 | "platforms": "*" 18 | } 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name = DFPlayer Mini 2 | version = 3.0.0 3 | author = Enjoyneering 4 | maintainer = Enjoyneering 5 | sentence = Arduino library for interacting with the DFPlayer Mini MP3 module 6 | paragraph = Arduino library for interacting with the DFPlayer Mini MP3 module 7 | category = Device Control 8 | url = https://github.com/enjoyneering/DFPlayer 9 | architectures = * 10 | depends = SoftwareSerial, EspSoftwareSerial 11 | -------------------------------------------------------------------------------- /src/DFPlayer.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino library for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC 12 | - 90dB output dynamic range 13 | - SNR over 85dB 14 | - micro SD-card, up to 32GB (FAT16, FAT32) 15 | - USB-Disk up to 32GB (FAT16, FAT32) 16 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 17 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 18 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 19 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 20 | 21 | NOTE: 22 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX-pin 23 | 24 | Frameworks & Libraries: 25 | Arduino Core - https://github.com/arduino/Arduino/tree/master/hardware 26 | ATtiny Core - https://github.com/SpenceKonde/ATTinyCore 27 | ESP8266 Core - https://github.com/esp8266/Arduino 28 | ESP32 Core - https://github.com/espressif/arduino-esp32 29 | STM32 Core - https://github.com/stm32duino/Arduino_Core_STM32 30 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 31 | 32 | 33 | GNU GPL license, all text above must be included in any redistribution, 34 | see link for details - https://www.gnu.org/licenses/licenses.html 35 | */ 36 | /***************************************************************************************************/ 37 | 38 | #include "DFPlayer.h" 39 | 40 | 41 | /**************************************************************************/ 42 | /* 43 | Constructor 44 | */ 45 | /**************************************************************************/ 46 | DFPlayer::DFPlayer() 47 | { 48 | //empty 49 | } 50 | 51 | 52 | /**************************************************************************/ 53 | /* 54 | begin() 55 | 56 | Class initialization 57 | 58 | NOTE: 59 | - command feedback timeout 100msec..350msec 60 | - for "moduleType" see "setModel()" NOTE 61 | - 0x01=module return feedback after the command, 0x00=module not return feedback 62 | - wait for player to boot, 1.5sec..3sec depends on SD-card size 63 | 64 | - DAC is turned on by default after boot or reset 65 | - average consumption 15mA without SD-card, 24mA with SD-card 66 | 67 | - boards boot time: 68 | - Arduino ATmega328... 2.1sec 69 | - Arduino SAM21....... 1.7sec 70 | - ESP8266............. 0.3sec 71 | - DFPlayer............ 3.0sec 72 | */ 73 | /**************************************************************************/ 74 | void DFPlayer::begin(Stream &stream, uint16_t threshold, DFPLAYER_MODULE_TYPE moduleType, bool feedback, bool bootDelay) 75 | { 76 | _serial = &stream; //serial stream 77 | _threshold = threshold; //timeout for feedback (delay after read command), in msec 78 | _ack = feedback; //0x01=module return feedback after the command, 0x00=module not return feedback after the command 79 | _moduleType = moduleType; //DFPlayer or Clone, differ in how checksum is calculated 80 | 81 | if (bootDelay == true) {delay(DFPLAYER_BOOT_DELAY);} //wait for player to boot 82 | //if (millis() < 6000) {delay(6000 - millis()); //minimum 2100msec + 3000msec = 5100msec, see NOTE 83 | } 84 | 85 | 86 | /**************************************************************************/ 87 | /* 88 | setModel() 89 | 90 | Set module type, DFPlayer or Clone 91 | 92 | NOTE: 93 | - moduleType: 94 | - DFPLAYER_MINI: 95 | - DFPlayer Mini 96 | - MP3-TF-16P 97 | - FN-M16P (for YX5200 chip, YX5300 chip or JL AAxxxx chip from Jieli) 98 | - DFPLAYER_FN_X10P: 99 | - FN-M10P 100 | - FN-S10P (FN6100 chip) 101 | - DFPLAYER_HW_247A: 102 | - DFPlayer Mini HW-247A (GD3200B chip) 103 | - DFPLAYER_NO_CHECKSUM: 104 | - no checksum calculation (not recomended for MCU without external 105 | crystal oscillator) 106 | 107 | - DFPlayer clones have more or less the same commands, the difference 108 | is in the checksum calculation 109 | */ 110 | /**************************************************************************/ 111 | void DFPlayer::setModel(DFPLAYER_MODULE_TYPE moduleType) 112 | { 113 | _moduleType = moduleType; 114 | } 115 | 116 | 117 | /**************************************************************************/ 118 | /* 119 | setTimeout() 120 | 121 | Set feedback timeout (delay after read command), in msec 122 | 123 | NOTE: 124 | - average feedback timeout 100msec(YX5200/AAxxxx)..350msec(GD3200B/MH2024K) 125 | */ 126 | /**************************************************************************/ 127 | void DFPlayer::setTimeout(uint16_t threshold) 128 | { 129 | _threshold = threshold; //command feedback timeout, in msec 130 | } 131 | 132 | 133 | /**************************************************************************/ 134 | /* 135 | setFeedback() 136 | 137 | Set whether module should return a feedback after write command 138 | 139 | NOTE: 140 | - 0x01=module return feedback, 0x00=module not return feedback 141 | */ 142 | /**************************************************************************/ 143 | void DFPlayer::setFeedback(bool enable) 144 | { 145 | _ack = enable; //1=enable feedback, 0=disable feedback 146 | } 147 | 148 | 149 | /**************************************************************************/ 150 | /* 151 | setSource() 152 | 153 | Set playback source 154 | 155 | NOTE: 156 | - source: 157 | - 1=USB-Disk 158 | - 2=TF-Card 159 | - 3=Aux 160 | - 4=sleep (for YX5200)/NOR-Flash (for GD3200) 161 | - 5=NOR-Flash 162 | - 6=Sleep 163 | - source 3..6 may not be supported by some modules!!! 164 | 165 | - module automatically detect source if source is on-line 166 | - module automatically enter standby after setting source 167 | - this command interrupt playback!!! 168 | - wait 200ms to select source 169 | */ 170 | /**************************************************************************/ 171 | void DFPlayer::setSource(uint8_t source) 172 | { 173 | source = constrain(source, 1, 6); //source limit 1..6 174 | 175 | _sendData(DFPLAYER_SET_PLAY_SRC, 0, source); 176 | 177 | if (source != 6) {delay(200);} //6=Sleep 178 | } 179 | 180 | 181 | /**************************************************************************/ 182 | /* 183 | playTrack() 184 | 185 | Play tracks by number, sorted in chronological order 186 | 187 | NOTE: 188 | - files in the root must start with 4 decimal digits with leading zeros 189 | - example: SD_ROOT/0001 - My favorite song.mp3 190 | - don’t copy 0003.mp3 & then 0001.mp3, because 0003.mp3 will be 191 | played firts 192 | */ 193 | /**************************************************************************/ 194 | void DFPlayer::playTrack(uint16_t track) 195 | { 196 | track = constrain(track, 1, 9999); //track limit 1..9999 197 | 198 | _sendData(DFPLAYER_PLAY_TRACK, (track >> 8), track); 199 | } 200 | 201 | 202 | /**************************************************************************/ 203 | /* 204 | next() 205 | 206 | Play next track in chronological order 207 | 208 | NOTE: 209 | - files in the root must start with 4 decimal digits with leading zeros 210 | - example: SD_ROOT/0001 - My favorite song.mp3 211 | - don’t copy 0003.mp3 & then 0001.mp3, because 0003.mp3 will be 212 | played firts 213 | */ 214 | /**************************************************************************/ 215 | void DFPlayer::next() 216 | { 217 | _sendData(DFPLAYER_PLAY_NEXT, 0, 0); 218 | } 219 | 220 | 221 | /**************************************************************************/ 222 | /* 223 | previous() 224 | 225 | Play previous track in chronological order 226 | 227 | NOTE: 228 | - files in the root must start with 4 decimal digits with leading zeros 229 | - example: SD_ROOT/0001 - My favorite song.mp3 230 | - don’t copy 0003.mp3 & then 0001.mp3, because 0003.mp3 will be 231 | played firts 232 | */ 233 | /**************************************************************************/ 234 | void DFPlayer::previous() 235 | { 236 | _sendData(DFPLAYER_PLAY_PREV, 0, 0); 237 | } 238 | 239 | 240 | /**************************************************************************/ 241 | /* 242 | pause() 243 | 244 | Pause current track 245 | */ 246 | /**************************************************************************/ 247 | void DFPlayer::pause() 248 | { 249 | _sendData(DFPLAYER_PAUSE, 0, 0); 250 | } 251 | 252 | 253 | /**************************************************************************/ 254 | /* 255 | resume() 256 | 257 | Resume playing current track, after pause or stop 258 | */ 259 | /**************************************************************************/ 260 | void DFPlayer::resume() 261 | { 262 | _sendData(DFPLAYER_RESUME_PLAYBACK, 0, 0); 263 | } 264 | 265 | 266 | /**************************************************************************/ 267 | /* 268 | stop() 269 | 270 | Stop playing current track 271 | 272 | NOTE: 273 | - always call stop() after pause(), otherwise a new track from another 274 | folder won't play 275 | */ 276 | /**************************************************************************/ 277 | void DFPlayer::stop() 278 | { 279 | _sendData(DFPLAYER_STOP_PLAYBACK, 0, 0); 280 | } 281 | 282 | 283 | /**************************************************************************/ 284 | /* 285 | playFolder() 286 | 287 | Play specific track from specific folder 288 | 289 | NOTE: 290 | - folder name must be 01..99 291 | - up to 001..255 songs in each folder 292 | 293 | - files in folder must start with 3 decimal digits with leading zeros 294 | - example: SD_ROOT/01/001 - My favorite song.mp3 295 | */ 296 | /**************************************************************************/ 297 | void DFPlayer::playFolder(uint8_t folder, uint8_t track) 298 | { 299 | folder = constrain(folder, 1, 99); //folder limit 1..99 300 | track = constrain(track, 1, 255); //track limit 1..255 301 | 302 | _sendData(DFPLAYER_PLAY_FOLDER, folder, track); 303 | } 304 | 305 | 306 | /**************************************************************************/ 307 | /* 308 | playMP3Folder() 309 | 310 | Play specific track number from "mp3" folder 311 | 312 | NOTE: 313 | - folder name must be "mp3" or "MP3" 314 | - up to 0001..9999 songs in each folder 315 | 316 | - files in folder must start with 4 decimal digits with leading zeros 317 | - example: SD_ROOT/mp3/0001 - My favorite song.mp3 318 | - module speed will decrease as the folder gets bigger, place no more 319 | than 3000 tracks to keep the speed 320 | */ 321 | /**************************************************************************/ 322 | void DFPlayer::playMP3Folder(uint16_t track) 323 | { 324 | track = constrain(track, 1, 9999); //track limit 1..9999 325 | 326 | _sendData(DFPLAYER_PLAY_MP3_FOLDER, (track >> 8), track); 327 | } 328 | 329 | 330 | /**************************************************************************/ 331 | /* 332 | play3000Folder() 333 | 334 | Play specific track number from folder, if you need more than 256 335 | tracks in a folder 336 | 337 | NOTE: 338 | - folder name must be 01..15 339 | - up to 0001..3000 songs in each folder 340 | - feature may not be supported by some modules!!! 341 | 342 | - files in folder must start with 4 decimal digits with leading zeros 343 | - example: SD_ROOT/01/0001 - My favorite song.mp3 344 | */ 345 | /**************************************************************************/ 346 | void DFPlayer::play3000Folder(uint16_t track) 347 | { 348 | track = constrain(track, 1, 3000); //track limit 1..3000 349 | 350 | _sendData(DFPLAYER_PLAY_3000_FOLDER, (track >> 8), track); 351 | } 352 | 353 | 354 | /**************************************************************************/ 355 | /* 356 | playAdvertFolder() 357 | 358 | Interrupt current track & play specific track number from "advert" 359 | folder, than resume current track 360 | 361 | NOTE: 362 | - folder name must be "advert" or "ADVERT" 363 | - up to 0001..9999 songs in each folder 364 | - command does't work when module is paused or stopped 365 | 366 | - files in folder must start with 4 decimal digits with leading zeros 367 | - example: SD_ROOT/advert/0001 - My favorite song.mp3 368 | */ 369 | /**************************************************************************/ 370 | void DFPlayer::playAdvertFolder(uint16_t track) 371 | { 372 | track = constrain(track, 1, 9999); //track limit 1..9999 373 | 374 | _sendData(DFPLAYER_PLAY_ADVERT_FOLDER, (track >> 8), track); 375 | } 376 | 377 | 378 | /**************************************************************************/ 379 | /* 380 | playAdvertFolder() 381 | 382 | Interrupt current track & play specific track number from specific 383 | "advert1".."advert9" folder, than resume current track 384 | 385 | NOTE: 386 | - folder name must be "advert1".."advert9" or or "ADVERT1".."ADVERT9" 387 | - up to 001..255 songs in each folder 388 | - feature may not be supported by some modules!!! 389 | 390 | - files in folder must start with 3 decimal digits with leading zeros 391 | - example: SD_ROOT/advert1/001 - My favorite song.mp3 392 | */ 393 | /**************************************************************************/ 394 | void DFPlayer::playAdvertFolder(uint8_t folder, uint8_t track) 395 | { 396 | folder = constrain(folder, 1, 9); //folder limit 1..9 397 | track = constrain(track, 1, 255); //track limit 1..255 398 | 399 | _sendData(DFPLAYER_PLAY_ADVERT_FOLDER_N, folder, track); 400 | } 401 | 402 | 403 | /**************************************************************************/ 404 | /* 405 | stopAdvertFolder() 406 | 407 | Stop interrupting current track while playing track from "advert" folder 408 | 409 | NOTE: 410 | - see playAdvertFolder() for details 411 | */ 412 | /**************************************************************************/ 413 | void DFPlayer::stopAdvertFolder() 414 | { 415 | _sendData(DFPLAYER_STOP_ADVERT_FOLDER, 0, 0); 416 | } 417 | 418 | 419 | /************************************************************************************/ 420 | /* 421 | setVolume() 422 | 423 | Set volume 424 | 425 | NOTE: 426 | - volume range 0..30 427 | */ 428 | /************************************************************************************/ 429 | void DFPlayer::setVolume(uint8_t volume) 430 | { 431 | volume = constrain(volume, 0, 30); //volume limit 0..30 432 | 433 | _sendData(DFPLAYER_SET_VOL, 0, volume); 434 | } 435 | 436 | 437 | /************************************************************************************/ 438 | /* 439 | volumeUp() 440 | 441 | Increment volume by 1 442 | */ 443 | /************************************************************************************/ 444 | void DFPlayer::volumeUp() 445 | { 446 | _sendData(DFPLAYER_SET_VOL_UP, 0, 0); 447 | } 448 | 449 | 450 | /************************************************************************************/ 451 | /* 452 | volumeDown() 453 | 454 | Decrement volume by 1 455 | */ 456 | /************************************************************************************/ 457 | void DFPlayer::volumeDown() 458 | { 459 | _sendData(DFPLAYER_SET_VOL_DOWN, 0, 0); 460 | } 461 | 462 | 463 | /**************************************************************************/ 464 | /* 465 | enableDAC() 466 | 467 | Enable/disable DAC, aka mute/unmute 468 | 469 | NOTE: 470 | - 1=enable, 0=disable/high resistance 471 | - DAC is turned on by default after boot or reset 472 | */ 473 | /**************************************************************************/ 474 | void DFPlayer::enableDAC(bool enable) 475 | { 476 | _sendData(DFPLAYER_SET_DAC, 0, !enable); //0=enable, 1=disable/high resistance 477 | } 478 | 479 | 480 | /**************************************************************************/ 481 | /* 482 | setDACGain() 483 | 484 | Set DAC output gain/output voltage swing 485 | 486 | NOTE: 487 | - HD-byte value, 0x01=enable gain & 0x00=disable gain 488 | - LD-byte value, 0..31=gain 489 | 490 | - feature may not be supported by some modules!!! 491 | */ 492 | /**************************************************************************/ 493 | void DFPlayer::setDACGain(uint8_t gain, bool enable) 494 | { 495 | gain = constrain(gain, 0, 31); //gain limit 0..31 496 | 497 | _sendData(DFPLAYER_SET_DAC_GAIN, enable, gain); 498 | } 499 | 500 | 501 | /************************************************************************************/ 502 | /* 503 | setEQ() 504 | 505 | Set equalizer 506 | 507 | NOTE: 508 | - 0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 509 | - feature may not be supported by some modules!!! 510 | */ 511 | /************************************************************************************/ 512 | void DFPlayer::setEQ(uint8_t preset) 513 | { 514 | preset = constrain(preset, 0, 5); //preset limit 0..5 515 | 516 | _sendData(DFPLAYER_SET_EQ, 0, preset); 517 | } 518 | 519 | 520 | /**************************************************************************/ 521 | /* 522 | repeatTrack() 523 | 524 | Playing & looping track number in chronological order 525 | 526 | NOTE: 527 | - command does't work when module is paused or stopped 528 | 529 | - don’t copy 0003.mp3 & then 0001.mp3, because 0003.mp3 will be 530 | played firts 531 | */ 532 | /**************************************************************************/ 533 | void DFPlayer::repeatTrack(uint16_t track) 534 | { 535 | track = constrain(track, 1, 9999); //track limit 1..9999 536 | 537 | _sendData(DFPLAYER_LOOP_TRACK, (track >> 8), track); 538 | } 539 | 540 | 541 | /**************************************************************************/ 542 | /* 543 | repeatCurrentTrack() 544 | 545 | Loop currently played track 546 | 547 | NOTE: 548 | - 0=stop repeating, 1=repeat currently played file 549 | - command does't work when module is paused or stopped 550 | - any playback command will switch back to normal playback mode 551 | */ 552 | /**************************************************************************/ 553 | void DFPlayer::repeatCurrentTrack(bool enable) 554 | { 555 | _sendData(DFPLAYER_LOOP_CURRENT_TRACK, 0, !enable); //0=repeat, 1=stop repeat 556 | } 557 | 558 | 559 | /**************************************************************************/ 560 | /* 561 | repeatAll() 562 | 563 | Repeat playback all files in chronological order until it receives 564 | stop or pause command 565 | 566 | NOTE: 567 | - 0x00=stop repeat playback & 0x01=start repeat playback 568 | - command does't work when module is paused or stopped 569 | - any playback command will switch back to normal playback mode 570 | 571 | - files in the root must start with 4 decimal digits with leading zeros 572 | - example: SD_ROOT/0001 - My favorite song.mp3 573 | - don’t copy 0003.mp3 & then 0001.mp3, because 0003.mp3 will be 574 | played firts 575 | */ 576 | /**************************************************************************/ 577 | void DFPlayer::repeatAll(bool enable) 578 | { 579 | _sendData(DFPLAYER_REPEAT_ALL, 0, enable); //0x00=stop repeat playback & 0x01=start repeat playback 580 | } 581 | 582 | 583 | /**************************************************************************/ 584 | /* 585 | repeatFolder() 586 | 587 | Repeat playback all tracks in chronological order until stop command 588 | 589 | NOTE: 590 | - up to 01..99 folder 591 | - command does't work when module is paused or stopped 592 | - any playback command will switch back to normal playback mode 593 | - folder must start with 2 decimal digits with leading zeros 594 | */ 595 | /**************************************************************************/ 596 | void DFPlayer::repeatFolder(uint16_t folder) 597 | { 598 | folder = constrain(folder, 1, 99); //folder limit 1..99 599 | 600 | _sendData(DFPLAYER_REPEAT_FOLDER, 0, folder); 601 | } 602 | 603 | 604 | /**************************************************************************/ 605 | /* 606 | randomAll() 607 | 608 | Play all tracks in random order 609 | 610 | NOTE: 611 | - any playback command will switch back to normal playback mode ?? 612 | */ 613 | /**************************************************************************/ 614 | void DFPlayer::randomAll() 615 | { 616 | _sendData(DFPLAYER_RANDOM_ALL_FILES, 0, 0); 617 | } 618 | 619 | 620 | /**************************************************************************/ 621 | /* 622 | sleep() 623 | 624 | Enable sleep mode 625 | 626 | NOTE: 627 | - use "wakeup()" to exit sleep 628 | - module does't respond to any playback commands in sleep mode, other 629 | commands OK 630 | - looks like does nothing, consumption before & after command 24mA 631 | 632 | - source: 633 | - 1=USB-Disk 634 | - 2=TF-Card 635 | - 3=Aux 636 | - 4=sleep (for YX5200)/NOR-Flash (for GD3200) 637 | - 5=NOR-Flash 638 | - 6=Sleep 639 | - source 3..6 may not be supported by some modules!!! 640 | */ 641 | /**************************************************************************/ 642 | void DFPlayer::sleep() 643 | { 644 | setSource(6); //6=Sleep 645 | } 646 | 647 | 648 | /**************************************************************************/ 649 | /* 650 | wakeup() 651 | 652 | Disable sleep mode 653 | 654 | NOTE: 655 | - source will be selected automatically if only one is present 656 | - source: 657 | - 1=USB-Disk 658 | - 2=TF-Card 659 | - 3=Aux 660 | - 4=sleep (for YX5200)/NOR-Flash (for GD3200) 661 | - 5=NOR-Flash 662 | - 6=Sleep 663 | - source 3..6 may not be supported by some modules!!! 664 | */ 665 | /**************************************************************************/ 666 | void DFPlayer::wakeup(uint8_t source) 667 | { 668 | if (source != 6) {setSource(source);} //6=Sleep prohibited 669 | } 670 | 671 | 672 | /**************************************************************************/ 673 | /* 674 | enableStandby() 675 | 676 | Enable/disable standby or normal mode 677 | 678 | NOTE: 679 | - true=enable standby, false=normal mode 680 | - standby not the same as sleep mode 681 | - use "wakeup()" to exit standby 682 | - module does't respond to any playback commands in standby mode, 683 | other commands OK 684 | - looks like does nothing, consumption before & after command 24mA 685 | 686 | - source: 687 | - 1=USB-Disk 688 | - 2=TF-Card 689 | - 3=Aux 690 | - 4=sleep (for YX5200)/NOR-Flash (for GD3200) 691 | - 5=NOR-Flash 692 | - 6=Sleep 693 | - source 3..6 may not be supported by some modules!!! 694 | */ 695 | /**************************************************************************/ 696 | void DFPlayer::enableStandby(bool enable, uint8_t source) 697 | { 698 | if (enable == true) 699 | { 700 | _sendData(DFPLAYER_SET_STANDBY_MODE, 0, 0); 701 | } 702 | else 703 | { 704 | wakeup(source); //for some reason "DFPLAYER_SET_NORMAL_MODE" doesn't work here 705 | } 706 | } 707 | 708 | 709 | /**************************************************************************/ 710 | /* 711 | reset() 712 | 713 | Reset all settings to factory default 714 | 715 | NOTE: 716 | - wait for player to boot, 1.5sec..3sec depends on SD-card size 717 | */ 718 | /**************************************************************************/ 719 | void DFPlayer::reset() 720 | { 721 | _sendData(DFPLAYER_RESET, 0, 0); 722 | 723 | delay(DFPLAYER_BOOT_DELAY); //wait for player to boot 724 | } 725 | 726 | 727 | /**************************************************************************/ 728 | /* 729 | getStatus() 730 | 731 | Get current module status 732 | 733 | NOTE: 734 | - this command does't interrupt current playback 735 | - status list: 736 | - 0, stop 737 | - 1, playing 738 | - 2, pause 739 | - 3, sleep, standby 740 | - 4, communication error 741 | - 5, unknown state 742 | 743 | - module response: 744 | - 7E FF 06 42 00 yy xx zz ww EF 745 | - yy=01 USB, yy=02 TF-card (for YX5200 chip, YX5300 chip or JL AAxxxx chip from Jieli only) 746 | - xx=00 stop 747 | - xx=01 playing 748 | - xx=02 pause 749 | - yy=00 750 | - xx=00 stop (for GD3200B chip only) 751 | - xx=01 playing (for GD3200B chip only) 752 | - xx=02 standby/sleep 753 | */ 754 | /**************************************************************************/ 755 | uint8_t DFPlayer::getStatus() 756 | { 757 | _sendData(DFPLAYER_GET_STATUS, 0, 0); 758 | 759 | switch (_getResponse(DFPLAYER_GET_STATUS)) 760 | { 761 | case 0x0200: 762 | return 0; //TF-card stop 763 | 764 | case 0x0201: 765 | return 1; //TF-card playing 766 | 767 | case 0x0202: 768 | return 2; //TF-card pause 769 | 770 | case 0x0002: 771 | return 3; //sleep or standby 772 | 773 | case 0x0001: 774 | return ((_moduleType != DFPLAYER_HW_247A) ? 5 : 1); //5=unknown state, 1=GD3200B playing 775 | 776 | case 0x0000: 777 | return ((_moduleType != DFPLAYER_HW_247A) ? 4 : 0); //4=communication error, 0=GD3200B stop 778 | 779 | default: 780 | return 5; //unknown state 781 | } 782 | } 783 | 784 | 785 | /**************************************************************************/ 786 | /* 787 | getVolume() 788 | 789 | Get current volume 790 | 791 | NOTE: 792 | - volume range 0..30 793 | - this command does't interrupt current playback 794 | - return "0" on communication error 795 | */ 796 | /**************************************************************************/ 797 | uint8_t DFPlayer::getVolume() 798 | { 799 | _sendData(DFPLAYER_GET_VOL, 0, 0); 800 | 801 | return _getResponse(DFPLAYER_GET_VOL); 802 | } 803 | 804 | 805 | /**************************************************************************/ 806 | /* 807 | getEQ() 808 | 809 | Get current EQ 810 | 811 | NOTE: 812 | - 0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass 813 | - this command does't interrupt current playback 814 | - feature may not be supported by some modules!!! 815 | - return "0" on communication error 816 | */ 817 | /**************************************************************************/ 818 | uint8_t DFPlayer::getEQ() 819 | { 820 | _sendData(DFPLAYER_GET_EQ, 0, 0); 821 | 822 | return _getResponse(DFPLAYER_GET_EQ); 823 | } 824 | 825 | 826 | /**************************************************************************/ 827 | /* 828 | getPlayMode() 829 | 830 | Get current play mode 831 | 832 | NOTE: 833 | - 0=loop all, 1=loop folder, 2=loop track, 3=random, 4=disable 834 | - this command does't interrupt current playback 835 | - feature may not be supported by some modules!!! 836 | - return "0" on communication error 837 | */ 838 | /**************************************************************************/ 839 | uint8_t DFPlayer::getPlayMode() 840 | { 841 | _sendData(DFPLAYER_GET_PLAY_MODE, 0, 0); 842 | 843 | return _getResponse(DFPLAYER_GET_PLAY_MODE); 844 | } 845 | 846 | 847 | /**************************************************************************/ 848 | /* 849 | getVersion() 850 | 851 | Get software version 852 | 853 | NOTE: 854 | - my JL AAxxxx chip return 0x08 855 | - my GD3200B chip return 856 | - 0A 77 77 77 2E 67 64 6B 65 6A 69 2E 63 6F 6D 0A .www.gdkeji.com. 857 | 47 44 33 32 30 30 42 2D 56 34 2E 30 0A 32 30 32 GD3200B-V4.0.202 858 | 30 2D 31 31 2D 32 35 20 32 32 3A 30 31 0A 0-11-25 22:01. 859 | 860 | - this command does't interrupt current playback 861 | - return "0" on communication error 862 | */ 863 | /**************************************************************************/ 864 | uint8_t DFPlayer::getVersion() 865 | { 866 | _sendData(DFPLAYER_GET_VERSION, 0, 0); 867 | 868 | return _getResponse(DFPLAYER_GET_VERSION); //TODO: parse GD3200B version 869 | } 870 | 871 | 872 | /**************************************************************************/ 873 | /* 874 | getTotalTracksSD() 875 | 876 | Get total number of tracks on TF-Card 877 | 878 | NOTE: 879 | - return number even if SD-card is removed 880 | - this command interrupt current playback!!! 881 | - return "0" on communication error 882 | */ 883 | /**************************************************************************/ 884 | uint16_t DFPlayer::getTotalTracksSD() 885 | { 886 | _sendData(DFPLAYER_GET_QNT_TF_FILES, 0, 0); 887 | 888 | return _getResponse(DFPLAYER_GET_QNT_TF_FILES); 889 | } 890 | 891 | 892 | /**************************************************************************/ 893 | /* 894 | getTotalTracksUSB() 895 | 896 | Get total number of tracks on USB-Disk 897 | 898 | NOTE: 899 | - this command interrupt current playback!!! 900 | - return "0" on communication error 901 | */ 902 | /**************************************************************************/ 903 | uint16_t DFPlayer::getTotalTracksUSB() 904 | { 905 | _sendData(DFPLAYER_GET_QNT_USB_FILES, 0, 0); 906 | 907 | return _getResponse(DFPLAYER_GET_QNT_USB_FILES); 908 | } 909 | 910 | 911 | /**************************************************************************/ 912 | /* 913 | getTotalTracksNORFlash() 914 | 915 | Get total number of tracks on NOR-Flash 916 | 917 | NOTE: 918 | - this command interrupt current playback!!! 919 | - feature may not be supported by some modules!!! 920 | - return "0" on communication error 921 | */ 922 | /**************************************************************************/ 923 | uint16_t DFPlayer::getTotalTracksNORFlash() 924 | { 925 | _sendData(DFPLAYER_GET_QNT_FLASH_FILES, 0, 0); 926 | 927 | return _getResponse(DFPLAYER_GET_QNT_FLASH_FILES); 928 | } 929 | 930 | 931 | /**************************************************************************/ 932 | /* 933 | getTrackSD() 934 | 935 | Get currently playing track number on TF-Card 936 | 937 | NOTE: 938 | - return track number while track is playing 939 | - this command does't interrupt current playback 940 | - return "0" on communication error 941 | */ 942 | /**************************************************************************/ 943 | uint16_t DFPlayer::getTrackSD() 944 | { 945 | _sendData(DFPLAYER_GET_TF_TRACK, 0, 0); 946 | 947 | return _getResponse(DFPLAYER_GET_TF_TRACK); 948 | } 949 | 950 | 951 | /**************************************************************************/ 952 | /* 953 | getTrackUSB() 954 | 955 | Get currently playing track number on USB-Disk 956 | 957 | NOTE: 958 | - return track number while track is playing 959 | - this command does't interrupt current playback 960 | - return "0" on communication error 961 | */ 962 | /**************************************************************************/ 963 | uint16_t DFPlayer::getTrackUSB() 964 | { 965 | _sendData(DFPLAYER_GET_USB_TRACK, 0, 0); 966 | 967 | return _getResponse(DFPLAYER_GET_USB_TRACK); 968 | } 969 | 970 | 971 | /**************************************************************************/ 972 | /* 973 | getTrackNORFlash() 974 | 975 | Get currently playing track number on NOR-Flash 976 | 977 | NOTE: 978 | - feature may not be supported by some modules!!! 979 | - return "0" on communication error 980 | */ 981 | /**************************************************************************/ 982 | uint16_t DFPlayer::getTrackNORFlash() 983 | { 984 | _sendData(DFPLAYER_GET_FLASH_TRACK, 0, 0); 985 | 986 | return _getResponse(DFPLAYER_GET_FLASH_TRACK); 987 | } 988 | 989 | 990 | /**************************************************************************/ 991 | /* 992 | getTotalTracksFolder() 993 | 994 | Get total number of tracks in folder 995 | 996 | NOTE: 997 | - this command interrupt current playback!!! 998 | - return "0" on communication error 999 | */ 1000 | /**************************************************************************/ 1001 | uint8_t DFPlayer::getTotalTracksFolder(uint8_t folder) 1002 | { 1003 | _sendData(DFPLAYER_GET_QNT_FOLDER_FILES, 0, folder); 1004 | 1005 | return _getResponse(DFPLAYER_GET_QNT_FOLDER_FILES); 1006 | } 1007 | 1008 | 1009 | /**************************************************************************/ 1010 | /* 1011 | getTotalFolders() 1012 | 1013 | Get total number of root folders in current source 1014 | 1015 | NOTE: 1016 | - only work with USB-Disk & TF-card!!! 1017 | - this command interrupt current playback!!! 1018 | - feature may not be supported by some modules!!! 1019 | - return "0" on communication error 1020 | 1021 | - my module doesn't support this command, 1-st time it returns 0x04 1022 | & 2-nd time 0x07 than stop play 1023 | */ 1024 | /**************************************************************************/ 1025 | uint8_t DFPlayer::getTotalFolders() 1026 | { 1027 | _sendData(DFPLAYER_GET_QNT_FOLDERS, 0, 0); 1028 | 1029 | return _getResponse(DFPLAYER_GET_QNT_FOLDERS); 1030 | } 1031 | 1032 | 1033 | /**************************************************************************/ 1034 | /* 1035 | getCommandStatus() 1036 | 1037 | Get player status after last TX command 1038 | 1039 | NOTE: 1040 | - module returned codes at the end of any playback operation or if any 1041 | command error 1042 | 1043 | - error values: 1044 | - 0x01, error module busy (this info is returned when the initialization is not done) 1045 | - 0x02, error module in sleep mode (supports only specified device in sleep mode) 1046 | - 0x03, error serial receiving error (request not fully received) 1047 | - 0x04, error checksum incorrect 1048 | - 0x05, error requested rack/folder is out of out of range 1049 | - 0x06, error requested track/folder is not found 1050 | - 0x07, error advert insertion error (inserting operation available when a track is being played) 1051 | - 0x08, error SD-card reading failed (SD-card pulled out or damaged) 1052 | - 0x09, error ??? 1053 | - 0x0A, error entered sleep mode 1054 | 1055 | - extra values: 1056 | - 0x0B, OK, command is accepted (returned only if ACK/feedback byte is set to 0x01) 1057 | - 0x0C, OK, track playback is completed, module return this status automatically after the track has been played 1058 | - 0x0D, OK, ready after boot or reset with DL-byte current source???, module return this status automatically after boot or reset 1059 | - 0x00, unknown status 1060 | */ 1061 | /**************************************************************************/ 1062 | uint8_t DFPlayer::getCommandStatus() 1063 | { 1064 | switch (_dataBuffer[3]) 1065 | { 1066 | case DFPLAYER_RETURN_ERROR: 1067 | return _dataBuffer[6]; //error values, see NOTE 1068 | 1069 | case DFPLAYER_RETURN_CODE_OK_ACK: 1070 | return 0x0B; 1071 | 1072 | case DFPLAYER_RETURN_CODE_DONE: 1073 | return 0x0C; 1074 | 1075 | case DFPLAYER_RETURN_CODE_READY: 1076 | return 0x0D; 1077 | 1078 | default: 1079 | return 0x00; 1080 | } 1081 | } 1082 | 1083 | 1084 | /**********************************private*********************************/ 1085 | /**************************************************************************/ 1086 | /* 1087 | _sendData() 1088 | 1089 | Send data via Serial port 1090 | 1091 | NOTE: 1092 | - DFPlayer TX data frame format: 1093 | 0 1 2 3 4 5 6 7 8 9-byte 1094 | START, VER, LEN, CMD, ACK, DH, DL, SUMH, SUML, END 1095 | -------- checksum -------- 1096 | */ 1097 | /**************************************************************************/ 1098 | void DFPlayer::_sendData(uint8_t command, uint8_t dataMSB, uint8_t dataLSB) 1099 | { 1100 | _dataBuffer[0] = DFPLAYER_UART_START_BYTE; 1101 | _dataBuffer[1] = DFPLAYER_UART_VERSION; 1102 | _dataBuffer[2] = DFPLAYER_UART_DATA_LEN; 1103 | _dataBuffer[3] = command; 1104 | _dataBuffer[4] = _ack; 1105 | _dataBuffer[5] = dataMSB; 1106 | _dataBuffer[6] = dataLSB; 1107 | 1108 | int16_t checksum; 1109 | 1110 | switch (_moduleType) 1111 | { 1112 | case DFPLAYER_MINI: 1113 | case DFPLAYER_HW_247A: 1114 | checksum = 0; //0x0000, DON'T TOUCH!!! 1115 | checksum = checksum - _dataBuffer[1] - _dataBuffer[2] - _dataBuffer[3] - _dataBuffer[4] - _dataBuffer[5] - _dataBuffer[6]; 1116 | break; 1117 | 1118 | case DFPLAYER_FN_X10P: 1119 | checksum = 35535; //0xFFFF, DON'T TOUCH!!! 1120 | checksum = checksum - _dataBuffer[1] - _dataBuffer[2] - _dataBuffer[3] - _dataBuffer[4] - _dataBuffer[5] - _dataBuffer[6] + 1; 1121 | break; 1122 | 1123 | case DFPLAYER_NO_CHECKSUM: 1124 | default: 1125 | //empty //no checksum calculation, not recomended for MCU without external crystal oscillator 1126 | break; 1127 | } 1128 | 1129 | switch (_moduleType) 1130 | { 1131 | case DFPLAYER_MINI: 1132 | case DFPLAYER_FN_X10P: 1133 | case DFPLAYER_HW_247A: 1134 | _dataBuffer[7] = checksum >> 8; 1135 | _dataBuffer[8] = checksum; 1136 | 1137 | _dataBuffer[9] = DFPLAYER_UART_END_BYTE; 1138 | 1139 | _serial->write(_dataBuffer, DFPLAYER_UART_FRAME_SIZE); 1140 | 1141 | if (_moduleType == DFPLAYER_HW_247A) {delay(_threshold);} //GD3200B/MH2024K chip so slow & need delay after write command 1142 | break; 1143 | 1144 | case DFPLAYER_NO_CHECKSUM: 1145 | default: 1146 | _dataBuffer[7] = DFPLAYER_UART_END_BYTE; 1147 | 1148 | _serial->write(_dataBuffer, (DFPLAYER_UART_FRAME_SIZE - 2)); //-2=SUMH & SUML not used 1149 | break; 1150 | } 1151 | } 1152 | 1153 | 1154 | /**************************************************************************/ 1155 | /* 1156 | _readData() 1157 | 1158 | Read MP3 player command feedback 1159 | 1160 | NOTE: 1161 | - command feedback timeout 100msec(YX5200/AAxxxx)..350msec(GD3200B/MH2024K) 1162 | 1163 | - DFPlayer RX data frame format: 1164 | 0 1 2 3 4 5 6 7 8 9-byte 1165 | START, VER, LEN, CMD, ACK, DH, DL, SUMH, SUML, END 1166 | */ 1167 | /**************************************************************************/ 1168 | bool DFPlayer::_readData() 1169 | { 1170 | memset(_dataBuffer, 0x00, DFPLAYER_UART_FRAME_SIZE); //clear data buffer 1171 | 1172 | _serial->flush(); //clear serial FIFO 1173 | _serial->setTimeout(_threshold); //set maximum msec to wait for "readBytes()", delay after read command 1174 | 1175 | /* read serial, wait for data during "setTimeout()" period than error (received less than expected) */ 1176 | if (_serial->readBytes(_dataBuffer, DFPLAYER_UART_FRAME_SIZE) != DFPLAYER_UART_FRAME_SIZE) {return false;} 1177 | 1178 | /* check for start byte missing, version byte missing, length byte missing, end byte missing */ 1179 | return ((_dataBuffer[0] == DFPLAYER_UART_START_BYTE) && (_dataBuffer[1] == DFPLAYER_UART_VERSION) && (_dataBuffer[2] == DFPLAYER_UART_DATA_LEN) && (_dataBuffer[9] == DFPLAYER_UART_END_BYTE)); 1180 | } 1181 | 1182 | 1183 | /**************************************************************************/ 1184 | /* 1185 | _getResponse() 1186 | 1187 | Get command feedback value from MP3 player 1188 | 1189 | NOTE: 1190 | - return "0" on communication error 1191 | */ 1192 | /**************************************************************************/ 1193 | uint16_t DFPlayer::_getResponse(uint8_t command) 1194 | { 1195 | if ((_readData() == true) && (_dataBuffer[3] == command)) {return ((uint16_t)_dataBuffer[5] << 8) | _dataBuffer[6];} //return DH, DL 1196 | return 0; 1197 | } 1198 | -------------------------------------------------------------------------------- /src/DFPlayer.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************************************/ 2 | /* 3 | This is an Arduino library for DFPlayer Mini MP3 module 4 | 5 | written by : enjoyneering 6 | source code: https://github.com/enjoyneering/DFPlayer 7 | 8 | DFPlayer Mini features: 9 | - 3.2v..5.0v, typical 4.2v 10 | - 15mA without flash drive, typical 24mA 11 | - 24-bit DAC with 90dB output dynamic range and SNR over 85dB 12 | - micro SD-card, up to 32GB (FAT16, FAT32) 13 | - USB-Disk up to 32GB (FAT16, FAT32) 14 | - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz 15 | - supports up to 100 folders, each folder can be assigned to 001..255 songs 16 | - built-in 3W mono amplifier, NS8002 AB-Class with standby function 17 | - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none) 18 | 19 | NOTE: 20 | - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX-pin 21 | 22 | Frameworks & Libraries: 23 | Arduino Core - https://github.com/arduino/Arduino/tree/master/hardware 24 | ATtiny Core - https://github.com/SpenceKonde/ATTinyCore 25 | ESP8266 Core - https://github.com/esp8266/Arduino 26 | ESP32 Core - https://github.com/espressif/arduino-esp32 27 | STM32 Core - https://github.com/stm32duino/Arduino_Core_STM32 28 | EspSoftwareSerial - https://github.com/plerup/espsoftwareserial 29 | 30 | 31 | GNU GPL license, all text above must be included in any redistribution, 32 | see link for details - https://www.gnu.org/licenses/licenses.html 33 | */ 34 | /***************************************************************************************************/ 35 | 36 | #ifndef DFPLAYER_h 37 | #define DFPLAYER_h 38 | 39 | #include 40 | 41 | 42 | 43 | /* UART frame values */ 44 | #define DFPLAYER_UART_FRAME_SIZE 0x0A //total number of bytes in UART packet, same for cmd & feedback 45 | #define DFPLAYER_UART_START_BYTE 0x7E //start byte 46 | #define DFPLAYER_UART_VERSION 0xFF //protocol version 47 | #define DFPLAYER_UART_DATA_LEN 0x06 //number of data bytes, except start byte, checksum & end byte 48 | #define DFPLAYER_UART_END_BYTE 0xEF //end byte 49 | 50 | /* command controls */ 51 | #define DFPLAYER_PLAY_NEXT 0x01 //play next uploaded file 52 | #define DFPLAYER_PLAY_PREV 0x02 //play prev uploaded file 53 | #define DFPLAYER_PLAY_TRACK 0x03 //play tracks in chronological order, by upload time 54 | #define DFPLAYER_SET_VOL_UP 0x04 //increment volume by 1 55 | #define DFPLAYER_SET_VOL_DOWN 0x05 //decrement volume by 1 56 | #define DFPLAYER_SET_VOL 0x06 //set volume, range 0..30 57 | #define DFPLAYER_SET_EQ 0x07 //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass (may not be supported by some modules) 58 | #define DFPLAYER_LOOP_TRACK 0x08 //playing & looping track number 0001..9999 59 | #define DFPLAYER_SET_PLAY_SRC 0x09 //1=USB-Disk, 2=TF-Card, 3=Aux, 4=sleep(YX5200)/NOR-Flash(GD3200), 5=NOR-Flash, 6=Sleep (3..6 may not be supported by some modules) 60 | #define DFPLAYER_SET_STANDBY_MODE 0x0A //put player in standby mode, not the same as sleep mode 61 | #define DFPLAYER_SET_NORMAL_MODE 0x0B //pull player out of standby mode (may not be supported by some modules) 62 | #define DFPLAYER_RESET 0x0C //reset module, set all settings to factory default 63 | #define DFPLAYER_RESUME_PLAYBACK 0x0D //resume playing current track 64 | #define DFPLAYER_PAUSE 0x0E //pause playing current track 65 | #define DFPLAYER_PLAY_FOLDER 0x0F //play track number 1..255 from folder number 1..99 66 | #define DFPLAYER_SET_DAC_GAIN 0x10 //set DAC output gain/output voltage swing (may not be supported by some modules) 67 | #define DFPLAYER_REPEAT_ALL 0x11 //repeat playback all files in chronological order 68 | #define DFPLAYER_PLAY_MP3_FOLDER 0x12 //play track number 0001..9999 from "mp3" folder 69 | #define DFPLAYER_PLAY_ADVERT_FOLDER 0x13 //interrupt current track & play track number 0001..9999 from "advert" folder, than resume current track 70 | #define DFPLAYER_PLAY_3000_FOLDER 0x14 //play track number 0001..3000 from folder that supports 3000 tracks (may not be supported by some modules) 71 | #define DFPLAYER_STOP_ADVERT_FOLDER 0x15 //stop interrupting current track while playing track from "advert" folder 72 | #define DFPLAYER_STOP_PLAYBACK 0x16 //stop playing current track 73 | #define DFPLAYER_REPEAT_FOLDER 0x17 //repeat playback folder number 01..99 74 | #define DFPLAYER_RANDOM_ALL_FILES 0x18 //play all tracks in random order 75 | #define DFPLAYER_LOOP_CURRENT_TRACK 0x19 //loop currently played track 76 | #define DFPLAYER_SET_DAC 0x1A //enable/disable DAC (mute/unmute), 0=enable, 1=disable 77 | #define DFPLAYER_PLAY_ADVERT_FOLDER_N 0x25 //interrupt current track & play track number 001..255 from "advert1".."advert9" folder, than resume current track (may not be supported by some modules) 78 | 79 | /* request command controls */ 80 | #define DFPLAYER_GET_STATUS 0x42 //get current stutus, see NOTE 81 | #define DFPLAYER_GET_VOL 0x43 //get current volume, range 0..30 82 | #define DFPLAYER_GET_EQ 0x44 //get current EQ, 0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass (may not be supported by some modules) 83 | #define DFPLAYER_GET_PLAY_MODE 0x45 //get current loop mode, 0=loop all, 1=loop folder, 2=loop track, 3=random, 4=disable (may not be supported by some modules) 84 | #define DFPLAYER_GET_VERSION 0x46 //get software version 85 | #define DFPLAYER_GET_QNT_USB_FILES 0x47 //get total number of tracks on USB-Disk 86 | #define DFPLAYER_GET_QNT_TF_FILES 0x48 //get total number of tracks on TF-card 87 | #define DFPLAYER_GET_QNT_FLASH_FILES 0x49 //get total number of tracks on NOR-Flash (may not be supported by some modules) 88 | #define DFPLAYER_GET_USB_TRACK 0x4B //get currently playing track number on USB-Disk 89 | #define DFPLAYER_GET_TF_TRACK 0x4C //get currently playing track number on TF-card 90 | #define DFPLAYER_GET_FLASH_TRACK 0x4D //get currently playing track number on NOR-Flash (may not be supported by some modules) 91 | #define DFPLAYER_GET_QNT_FOLDER_FILES 0x4E //get total number of tracks in folder 92 | #define DFPLAYER_GET_QNT_FOLDERS 0x4F //get total number of folders in current source (may not be supported by some modules) 93 | 94 | /* module returned codes at the end of any playback operation or if any command error, located in 4-th RX byte */ 95 | #define DFPLAYER_RETURN_CODE_OK_ACK 0x41 //OK, command is accepted (returned only if ACK/feedback byte is set to 0x01) 96 | #define DFPLAYER_RETURN_ERROR 0x40 //error, module return this status automatically if command is not accepted (details located in 7-th RX byte) 97 | #define DFPLAYER_RETURN_CODE_DONE 0x3D //track playback is is completed, module return this status automatically after the track has been played 98 | #define DFPLAYER_RETURN_CODE_READY 0x3F //ready after boot or reset, module return this status automatically after boot or reset 99 | 100 | /* misc */ 101 | #define DFPLAYER_BOOT_DELAY 3000 //average player boot time 1500sec..3000msec, depends on SD-card size 102 | #define DFPLAYER_CMD_DELAY 350 //average read command timeout 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip 103 | 104 | 105 | /* list of supported modules */ 106 | typedef enum : uint8_t 107 | { 108 | DFPLAYER_MINI = 0x00, //DFPlayer Mini, MP3-TF-16P, FN-M16P (YX5200 chip, YX5300 chip or JL AAxxxx chip from Jieli) 109 | DFPLAYER_FN_X10P = 0x01, //FN-M10P, FN-S10P (FN6100 chip) 110 | DFPLAYER_HW_247A = 0x02, //DFPlayer Mini HW-247A (GD3200B chip) 111 | DFPLAYER_NO_CHECKSUM = 0x03 //no checksum calculation, not recomended for MCU without external crystal oscillator 112 | } 113 | DFPLAYER_MODULE_TYPE; 114 | 115 | 116 | class DFPlayer 117 | { 118 | public: 119 | DFPlayer(); 120 | 121 | void begin(Stream& stream, uint16_t threshold = DFPLAYER_CMD_DELAY, DFPLAYER_MODULE_TYPE = DFPLAYER_MINI, bool feedback = false, bool bootDelay = true); 122 | 123 | void setModel(DFPLAYER_MODULE_TYPE = DFPLAYER_MINI); 124 | void setTimeout(uint16_t threshold); 125 | void setFeedback(bool enable); 126 | 127 | void setSource(uint8_t source); 128 | void playTrack(uint16_t track); 129 | void next(); 130 | void previous(); 131 | void pause(); 132 | void resume(); 133 | void stop(); 134 | 135 | void playFolder(uint8_t folder, uint8_t track); 136 | void playMP3Folder(uint16_t track); 137 | void play3000Folder(uint16_t track); 138 | void playAdvertFolder(uint16_t track); 139 | void playAdvertFolder(uint8_t folder, uint8_t track); 140 | void stopAdvertFolder(); 141 | 142 | void setVolume(uint8_t volume); 143 | void volumeUp(); 144 | void volumeDown(); 145 | void enableDAC(bool enable); 146 | void setDACGain(uint8_t gain, bool enable = true); 147 | void setEQ(uint8_t preset); 148 | 149 | void repeatTrack(uint16_t track); 150 | void repeatCurrentTrack(bool enable); 151 | void repeatAll(bool enable); 152 | void repeatFolder(uint16_t folder); 153 | void randomAll(); 154 | 155 | void sleep(); 156 | void wakeup(uint8_t source = 2); 157 | void enableStandby(bool enable, uint8_t source = 2); 158 | void reset(); 159 | 160 | uint8_t getStatus(); 161 | uint8_t getVolume(); 162 | uint8_t getEQ(); 163 | uint8_t getPlayMode(); 164 | uint8_t getVersion(); 165 | uint16_t getTotalTracksSD(); 166 | uint16_t getTotalTracksUSB(); 167 | uint16_t getTotalTracksNORFlash(); 168 | uint16_t getTrackSD(); 169 | uint16_t getTrackUSB(); 170 | uint16_t getTrackNORFlash(); 171 | uint8_t getTotalTracksFolder(uint8_t folder); 172 | uint8_t getTotalFolders(); 173 | uint8_t getCommandStatus(); 174 | 175 | private: 176 | Stream* _serial; 177 | uint16_t _threshold; //timeout responses, in msec 178 | uint8_t _dataBuffer[DFPLAYER_UART_FRAME_SIZE]; //shared buffer between TX & RX 179 | DFPLAYER_MODULE_TYPE _moduleType; //DFPlayer or Clone, differ in how checksum is calculated 180 | bool _ack; //true=request response from module after the command 181 | 182 | uint16_t _getResponse(uint8_t command); 183 | void _sendData(uint8_t command, uint8_t dataMSB, uint8_t dataLSB); 184 | bool _readData(); 185 | }; 186 | 187 | #endif 188 | --------------------------------------------------------------------------------