【热门器件来 Arrow 】DFR0299 MP3播放器评测
收到了DRR0299这块MP3模块,非常的小巧,看着还是比较精致的,下边就简单测一下吧!
这个就是他的原型图
这个是接上线的
看了一些他的引脚介绍图跟他的一些说明,你会发现他是可以进行串口通信的, 这个就非常的好操作了。
方法一:
你可以找一块开发板,比如STM32的L476,他支持在线编译。你接好线,配置一些IO口
这个发放就先不用了,指引出来
方法二:
这里我们就不这么麻烦了直接用串口吧,下个串口调试器
下边是一个测试的例子: - DFPlayer_Mini_Mp3, This library provides a quite complete function for *
- * DFPlayer mini mp3 module. *
- * www.github.com/dfrobot/DFPlayer_Mini_Mp3 (github as default source provider)*
- * DFRobot-A great source for opensource hardware and robot. *
- * *
- * This file is part of the DFplayer_Mini_Mp3 library. *
- * *
- * DFPlayer_Mini_Mp3 is free software: you can redistribute it and/or *
- * modify it under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation, either version 3 of *
- * the License, or any later version. *
- * *
- * DFPlayer_Mini_Mp3 is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU Lesser General Public License for more details. *
- * *
- * DFPlayer_Mini_Mp3 is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with DFPlayer_Mini_Mp3. If not, see *
- * <http://www.gnu.org/licenses/>. *
- * *
- ******************************************************************************/
- /*
- * Copyright: DFRobot
- * name: DFPlayer_Mini_Mp3 test code
- * Author: lisper <lisper.li@dfrobot.com>
- * Date: 2014-05-22
- * Description: mp3 library for DFPlayer mini board
- *
- * this code is test on leonardo
- * you can try input:
- * play //play current music
- * play 3 //play mp3/0003.mp3
- * next //play next
- * prev //paly previous
- * pause //pause current play
- * stop //stop current play
- * state //get current state of module
- * current //get current track of tf card
- * volume //get current volume
- * volume 20 //set volume to 20 (0~30)
- * single open/close //set single loop open or close
- * reply open/close //set if need reply
- */
-
- #include <SoftwareSerial.h>
- #include <DFRobot_utility.h>
- #include "DFPlayer_Mini_Mp3.h"
- #define BUFSIZE 20 //buf size
- #define CMDNUM 8 //cmdbuf size
- uint8_t buf[BUFSIZE]; //data buffer for read from Serial
- char *cmdbuf[CMDNUM]; //for split string from buf
- //
- void setup () {
- Serial1.begin (9600);
- Serial.begin (9600);
- while (!Serial);
- mp3_set_serial (Serial1); //set Serial1 for DFPlayer-mini mp3 module
- mp3_set_volume (15);
- mp3_get_tf_sum ();
- print_info ();
- }
- void print_info () {
- Serial.println ("you send:");
- printHex (send_buf, 10);
- delay (100);
- int recv_leng = serialRead (Serial1, recv_buf, 10, 3);
- if (recv_leng) {
- Serial.println ("you get:");
- printHex (recv_buf, recv_leng);
- }
- }
- //
- void loop () {
- int leng;
- leng = serialRead (Serial1, buf, BUFSIZE, 3); //first read data from Serial1
- if (leng) {
- Serial.print ("=>");
- printHex (buf, leng);
- }
- leng = serialRead (Serial, buf, BUFSIZE, 3); //read command to buf from Serial (PC)
- if (leng) {
- buf[leng] = '\0';
- Serial.println ((char*)buf);
- int cmdleng = split(cmdbuf, (char*)buf, 8); //split command string to cmdbuf
- if (cmdleng >= 1) {
- if (strcmp (cmdbuf[0], "next") == 0) {
- mp3_next ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "physical") == 0) {
- if (cmdleng == 2) {
- mp3_play_physical (atoi (cmdbuf[1])); //get arguments
- } else {
- mp3_play_physical ();
- }
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "prev") == 0) {
- mp3_prev ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "stop") == 0) {
- mp3_stop ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "pause") == 0) {
- mp3_pause ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "state") == 0) {
- mp3_get_state ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "sum") == 0) {
- mp3_get_tf_sum ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "current") == 0) {
- mp3_get_tf_current ();
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "volume") == 0) {
- if (cmdleng == 2) {
- mp3_set_volume (atoi (cmdbuf[1]));
- } else {
- mp3_get_volume ();
- }
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "reply") == 0 && cmdleng == 2) {
- if (strcmp (cmdbuf[1], "open") == 0)
- mp3_set_reply (true);
- else if (strcmp (cmdbuf[1], "close") == 0)
- mp3_set_reply (false);
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "play") == 0 && cmdleng == 2) {
- if (cmdleng == 2) {
- mp3_play (atoi (cmdbuf[1]));
- } else {
- mp3_play ();
- }
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "eq") == 0 && cmdleng == 2) {
- mp3_set_EQ (atoi (cmdbuf[1]));
- print_info ();
- }
- else if (strcmp (cmdbuf[0], "single") == 0 && cmdleng == 2) {
- if (strcmp (cmdbuf[1], "open") == 0)
- mp3_single_loop (true);
- else if (strcmp (cmdbuf[1], "close") == 0)
- mp3_single_loop (false);
- print_info ();
- } else {
- Serial.println ("error! no this command");
- }
- }
- }
- }
复制代码这个是切换下一首进行播放音乐。 - #include "Arduino.h"
- #include "SoftwareSerial.h"
- #include "DFRobotDFPlayerMini.h"
- SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
- DFRobotDFPlayerMini myDFPlayer;
- void printDetail(uint8_t type, int value);
- void setup()
- {
- mySoftwareSerial.begin(9600);
- Serial.begin(115200);
- Serial.println();
- Serial.println(F("DFRobot DFPlayer Mini Demo"));
- Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
- if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
- Serial.println(F("Unable to begin:"));
- Serial.println(F("1.Please recheck the connection!"));
- Serial.println(F("2.Please insert the SD card!"));
- while(true);
- }
- Serial.println(F("DFPlayer Mini online."));
- myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
- //----Set volume----
- myDFPlayer.volume(10); //Set volume value (0~30).
- myDFPlayer.volumeUp(); //Volume Up
- myDFPlayer.volumeDown(); //Volume Down
- //----Set different EQ----
- myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
- // myDFPlayer.EQ(DFPLAYER_EQ_POP);
- // myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
- // myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
- // myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
- // myDFPlayer.EQ(DFPLAYER_EQ_BASS);
- //----Set device we use SD as default----
- // myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK);
- myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
- // myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX);
- // myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP);
- // myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH);
- //----Mp3 control----
- // myDFPlayer.sleep(); //sleep
- // myDFPlayer.reset(); //Reset the module
- // myDFPlayer.enableDAC(); //Enable On-chip DAC
- // myDFPlayer.disableDAC(); //Disable On-chip DAC
- // myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15
复制代码
或者你用Arduino IDE来做也非常方便,不过需要注意的是,库文件夹下要直接显示*.cpp和*.h文件,绝对不可以把这些库文件再套到二级以上目录,这样子就会导致IDE无法识别。
|