回答

收藏

[评测分享] 【热门器件来 Arrow 】DFR0299 MP3播放器评测

#板卡评测 #板卡评测 2082 人阅读 | 0 人回复 | 2022-12-07

【热门器件来 Arrow 】DFR0299  MP3播放器评测


收到了DRR0299这块MP3模块,非常的小巧,看着还是比较精致的,下边就简单测一下吧!

这个就是他的原型图


这个是接上线的

看了一些他的引脚介绍图跟他的一些说明,你会发现他是可以进行串口通信的, 这个就非常的好操作了。


方法一:

你可以找一块开发板,比如STM32的L476,他支持在线编译。你接好线,配置一些IO口






这个发放就先不用了,指引出来

方法二:

这里我们就不这么麻烦了直接用串口吧,下个串口调试器


下边是一个测试的例子:
  1. DFPlayer_Mini_Mp3, This library provides a quite complete function for      *
  2. * DFPlayer mini mp3 module.                                                   *
  3. * www.github.com/dfrobot/DFPlayer_Mini_Mp3 (github as default source provider)*
  4. *  DFRobot-A great source for opensource hardware and robot.                  *
  5. *                                                                             *
  6. * This file is part of the DFplayer_Mini_Mp3 library.                         *
  7. *                                                                             *
  8. * DFPlayer_Mini_Mp3 is free software: you can redistribute it and/or          *
  9. * modify it under the terms of the GNU Lesser General Public License as       *
  10. * published by the Free Software Foundation, either version 3 of              *
  11. * the License, or any later version.                                          *
  12. *                                                                             *
  13. * DFPlayer_Mini_Mp3 is distributed in the hope that it will be useful,        *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
  16. * GNU Lesser General Public License for more details.                         *
  17. *                                                                             *
  18. * DFPlayer_Mini_Mp3 is distributed in the hope that it will be useful,        *
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of              *
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
  21. * GNU Lesser General Public License for more details.                         *
  22. *                                                                             *
  23. * You should have received a copy of the GNU Lesser General Public            *
  24. * License along with DFPlayer_Mini_Mp3. If not, see                           *
  25. * <http://www.gnu.org/licenses/>.                                             *
  26. *                                                                               *
  27. ******************************************************************************/

  28. /*
  29. *        Copyright:        DFRobot
  30. *        name:                DFPlayer_Mini_Mp3 test code
  31. *        Author:                lisper <lisper.li@dfrobot.com>
  32. *        Date:                2014-05-22
  33. *        Description:        mp3 library for DFPlayer mini board
  34. *
  35. *        this code is test on leonardo
  36. *        you can try input:
  37. *        play                        //play current music
  38. *        play 3                        //play mp3/0003.mp3
  39. *        next                        //play next
  40. *        prev                        //paly previous
  41. *        pause                        //pause        current play
  42. *        stop                        //stop current play
  43. *        state                         //get current state of module
  44. *        current                        //get current track of tf card
  45. *        volume                        //get current volume
  46. *        volume 20                //set volume to 20 (0~30)
  47. *        single open/close         //set single loop open or close
  48. *        reply open/close        //set if need reply
  49. */

  50. #include <SoftwareSerial.h>
  51. #include <DFRobot_utility.h>

  52. #include "DFPlayer_Mini_Mp3.h"

  53. #define BUFSIZE 20        //buf size
  54. #define CMDNUM 8        //cmdbuf size

  55. uint8_t buf[BUFSIZE]; //data buffer for read from Serial
  56. char *cmdbuf[CMDNUM]; //for split string from buf

  57. //
  58. void setup () {
  59.         Serial1.begin (9600);
  60.         Serial.begin (9600);
  61.         while (!Serial);

  62.         mp3_set_serial (Serial1);        //set Serial1 for DFPlayer-mini mp3 module
  63.         mp3_set_volume (15);
  64.         mp3_get_tf_sum ();
  65.         print_info ();
  66. }

  67. void print_info () {
  68.         Serial.println ("you send:");
  69.         printHex (send_buf, 10);
  70.         delay (100);
  71.         int recv_leng = serialRead (Serial1, recv_buf, 10, 3);
  72.         if (recv_leng) {
  73.                 Serial.println ("you get:");
  74.                 printHex (recv_buf, recv_leng);
  75.         }
  76. }

  77. //
  78. void loop () {        
  79.         int leng;
  80.         leng = serialRead (Serial1, buf, BUFSIZE, 3); //first read data from Serial1
  81.         if (leng) {
  82.                 Serial.print ("=>");
  83.                 printHex (buf, leng);
  84.         }
  85.         leng = serialRead (Serial, buf, BUFSIZE, 3); //read command to buf from Serial (PC)
  86.         if (leng) {
  87.                 buf[leng] = '\0';
  88.                 Serial.println ((char*)buf);
  89.                 int cmdleng = split(cmdbuf, (char*)buf, 8); //split command string to cmdbuf
  90.                 if (cmdleng >= 1) {
  91.                         if (strcmp (cmdbuf[0], "next") == 0) {
  92.                                 mp3_next ();
  93.                                 print_info ();
  94.                         }
  95.                         else if (strcmp (cmdbuf[0], "physical") == 0) {
  96.                                 if (cmdleng == 2) {
  97.                                         mp3_play_physical (atoi (cmdbuf[1])); //get arguments
  98.                                 } else {
  99.                                         mp3_play_physical ();
  100.                                 }
  101.                                 print_info ();
  102.                         }
  103.                         else if (strcmp (cmdbuf[0], "prev") == 0) {
  104.                                 mp3_prev ();
  105.                                 print_info ();
  106.                         }
  107.                         else if (strcmp (cmdbuf[0], "stop") == 0) {
  108.                                 mp3_stop ();
  109.                                 print_info ();
  110.                         }
  111.                         else if (strcmp (cmdbuf[0], "pause") == 0) {
  112.                                 mp3_pause ();
  113.                                 print_info ();
  114.                         }
  115.                         else if (strcmp (cmdbuf[0], "state") == 0) {
  116.                                 mp3_get_state ();
  117.                                 print_info ();
  118.                         }
  119.                         else if (strcmp (cmdbuf[0], "sum") == 0) {
  120.                                 mp3_get_tf_sum ();
  121.                                 print_info ();
  122.                         }
  123.                         else if (strcmp (cmdbuf[0], "current") == 0) {
  124.                                 mp3_get_tf_current ();
  125.                                 print_info ();
  126.                         }
  127.                         else if (strcmp (cmdbuf[0], "volume") == 0) {
  128.                                 if (cmdleng == 2) {
  129.                                         mp3_set_volume (atoi (cmdbuf[1]));
  130.                                 } else {
  131.                                         mp3_get_volume ();
  132.                                 }
  133.                                 print_info ();
  134.                         }
  135.                         else if (strcmp (cmdbuf[0], "reply") == 0 && cmdleng == 2) {
  136.                                 if (strcmp (cmdbuf[1], "open") == 0)
  137.                                         mp3_set_reply (true);
  138.                                 else if (strcmp (cmdbuf[1], "close") == 0)
  139.                                         mp3_set_reply (false);
  140.                                 print_info ();
  141.                         }
  142.                         else if (strcmp (cmdbuf[0], "play") == 0 && cmdleng == 2) {
  143.                                 if (cmdleng == 2) {
  144.                                         mp3_play (atoi (cmdbuf[1]));
  145.                                 } else {
  146.                                         mp3_play ();
  147.                                 }
  148.                                 print_info ();
  149.                         }
  150.                         else if (strcmp (cmdbuf[0], "eq") == 0 && cmdleng == 2) {
  151.                                 mp3_set_EQ (atoi (cmdbuf[1]));
  152.                                 print_info ();
  153.                         }
  154.                         else if (strcmp (cmdbuf[0], "single") == 0 && cmdleng == 2) {
  155.                                 if (strcmp (cmdbuf[1], "open") == 0)
  156.                                         mp3_single_loop (true);
  157.                                 else if (strcmp (cmdbuf[1], "close") == 0)
  158.                                         mp3_single_loop (false);
  159.                                 print_info ();
  160.                         } else {
  161.                                 Serial.println ("error! no this command");
  162.                         }
  163.                 }
  164.         }
  165. }
复制代码
这个是切换下一首进行播放音乐。
  1. #include "Arduino.h"
  2. #include "SoftwareSerial.h"
  3. #include "DFRobotDFPlayerMini.h"

  4. SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
  5. DFRobotDFPlayerMini myDFPlayer;
  6. void printDetail(uint8_t type, int value);

  7. void setup()
  8. {
  9.   mySoftwareSerial.begin(9600);
  10.   Serial.begin(115200);

  11.   Serial.println();
  12.   Serial.println(F("DFRobot DFPlayer Mini Demo"));
  13.   Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  14.   if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
  15.     Serial.println(F("Unable to begin:"));
  16.     Serial.println(F("1.Please recheck the connection!"));
  17.     Serial.println(F("2.Please insert the SD card!"));
  18.     while(true);
  19.   }
  20.   Serial.println(F("DFPlayer Mini online."));

  21.   myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms

  22.   //----Set volume----
  23.   myDFPlayer.volume(10);  //Set volume value (0~30).
  24.   myDFPlayer.volumeUp(); //Volume Up
  25.   myDFPlayer.volumeDown(); //Volume Down

  26.   //----Set different EQ----
  27.   myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
  28. //  myDFPlayer.EQ(DFPLAYER_EQ_POP);
  29. //  myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
  30. //  myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
  31. //  myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
  32. //  myDFPlayer.EQ(DFPLAYER_EQ_BASS);

  33.   //----Set device we use SD as default----
  34. //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
  35.   myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
  36. //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
  37. //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
  38. //  myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);

  39.   //----Mp3 control----
  40. //  myDFPlayer.sleep();     //sleep
  41. //  myDFPlayer.reset();     //Reset the module
  42. //  myDFPlayer.enableDAC();  //Enable On-chip DAC
  43. //  myDFPlayer.disableDAC();  //Disable On-chip DAC
  44. //  myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
复制代码




或者你用Arduino IDE来做也非常方便,不过需要注意的是,库文件夹下要直接显示*.cpp和*.h文件,绝对不可以把这些库文件再套到二级以上目录,这样子就会导致IDE无法识别。




分享到:
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条