红外遥控播放器-播放你的音乐(DFPlayer)
上次一直想做一个音乐播放器,但是不知道何原因一直没能成功,于是在网上找资料,在其他论坛找到一个教程自己来做做看,这个作品是基于DFPlayer和uno板子来做的。大家会问DFPlayer是什么?
DFPlayer Mini 是一款小巧且价格低廉的MP3模块,可以直接接驳扬声器。模块配合供电电池、扬声器、按键可以单独使用,也可以通过串口控制,作为Arduino UNO或者是任何有串口的单片机的一个模块。模块本身完美的集成了MP3、WAV、WMA的硬解码。同时软件支持TF卡驱动,支持FAT16、FAT32文件系统。通过简单的串口指令即可完成播放指定的音乐,以及如何播放音乐等功能,无需繁琐的底层操作,使用方便,稳定可靠。http://image.geek-workshop.com/forum/201507/18/220253rz7uvtq2u8sv8d0s.png http://image.geek-workshop.com/forum/201507/18/220744oryczk1r1q0qkryk.png http://image.geek-workshop.com/forum/201507/18/230506vtwexekz49likze7.jpg 更详尽的文档 可以参考产品资料库找更专业的资料
器材准备:
DFRduino UNO R3IR kit红外遥控套
DFPlayer Mini 播放器模块
杜邦线、电阻等等
http://image.geek-workshop.com/forum/201507/18/222755gxfxvxxxzmzq46xr.jpg
官方声明:此模块可以直接使用Arduino供电,并不会对Arduino本身造成任何影响。
如果使用Arduino供电,切记需要在串口通信端口上增加两个1K电阻用来消除噪音!
以下是搭建好的电路:
http://image.geek-workshop.com/forum/201507/18/223825wb38d68de6zo63do.png
http://image.geek-workshop.com/forum/201507/18/223825pmbb6rg4bcgv8u7m.png
/*
*name: DFPlayer_Mini_Mp3
*version:1.0
*Author: Apple tec.<godfights@163.com>
*Date: 2015-07-16
*Description:红外遥控DFPlayer迷你板
*note: mp3 file must put into mp3 folder in your tf card
*/
#include <IRremote.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
//定义对应16进制数值的常量名
#define POWER 0xFD00FF //电源
#define VOLUP 0xFD807F //VOL+
#define STOP 0xFD40BF //FUNC/STOP
#define PREV 0xFD20DF //后退/上一曲
#define PAUSE 0xFDA05F //暂停/播放
#define NEXT 0xFD609F //前进/下一曲
#define DOWN 0xFD10EF //下一页
#define VOLDOWN 0xFD906F //VOL-
#define UP 0xFD50AF //上一页
#define ZERO 0xFD30CF //0
#define EQ 0xFDB04F //EQ
#define REPT 0xFD708F //ST/REPT
#define ONE 0xFD08F7 //1
#define TWO 0xFD8877 //2
#define THREE 0xFD48B7 //3
#define FOUR 0xFD28D7 //4
#define FIVE 0xFDA857 //5
#define SIX 0xFD6897 //6
#define SEVEN 0xFD18E7 //7
#define EIGHT 0xFD9867 //8
#define NINE 0xFD58A7 //9
int recvPin = 2; //红外接收器到ardunio的端口
boolean a = true; //播放逻辑设定
int i = 20; //初始化音量
int z = 0; //初始化音效
IRrecv recv(recvPin); //初始化接收
decode_results res; //储存接收到的数据
void setup() {
Serial.begin(9600); //初始化串口
recv.enableIRIn(); //允许接收数据
mp3_set_serial (Serial); //设置串行DFPlayer-mini mp3模块
mp3_set_volume (i); //初始化音量
mp3_set_EQ (z); //初始化音效
}
void loop() {
if(recv.decode(&res)) { //判断是否接受到数据
switch(res.value) { //判断按下的按钮
case POWER: //停止播放
if (a == false) {
a = !a;
mp3_stop ();
}
break;
case PREV: //上一首
if (a == true) {
a = !a;
}
mp3_prev ();
break;
case NEXT: //下一首
if (a == true) {
a = !a;
}
mp3_next ();
break;
case PAUSE: //暂停与播放(暂停具有断点播放)
if (a == true) {
a = !a;
mp3_play ();
}
else {
a = !a;
mp3_pause ();
}
break;
case VOLUP: //音量加
if (i < 30) {
i = i+1;
mp3_set_volume (i);
}
break;
case VOLDOWN: //音量减
if (i > 0) {
i = i-1;
mp3_set_volume (i);
}
break;
case EQ: //音效模式切换
if (z < 5) {
z = z+1;
}
else {
z = 0;
}
mp3_set_EQ (z);
break;
case REPT : //随机模式播放
if (a == true) {
a = !a;
}
mp3_random_play ();
break;
case ONE:
if (a == true) {
a = !a;
}
mp3_play (1);
break;
case TWO:
if (a == true) {
a = !a;
}
mp3_play (2);
break;
case THREE:
if (a == true) {
a = !a;
}
mp3_play (3);
break;
case FOUR:
if (a == true) {
a = !a;
}
mp3_play (4);
break;
case FIVE:
if (a == true) {
a = !a;
}
mp3_play (5);
break;
case SIX:
if (a == true) {
a = !a;
}
mp3_play (6);
break;
case SEVEN:
if (a == true) {
a = !a;
}
mp3_play (7);
break;
case EIGHT:
if (a == true) {
a = !a;
}
mp3_play (8);
break;
case NINE:
if (a == true) {
a = !a;
}
mp3_play (9);
break;
default:
;
}
recv.resume(); //接收下一个数据
}
}
一切顺利,你就会得到一个可以用红外遥控器控制的音乐播放器。
http://image.geek-workshop.com/forum/201507/18/225501n8ss1qgfq19dwq2q.png
http://image.geek-workshop.com/forum/201507/18/225522udldizjlix3xyz2j.png
* 以下是使用 DFPlayer Mini Module 的注意事項,请仔细阅读!
*DFPlayer Mini 可以读取 MP3 & WAV 格式的文件(实测可以解码320K的超高品质音乐),但无法播放时长在1秒以下的音频。
*所有音乐文件一定要放在mp3文件夹内,而mp3文件命名需要是4位数字,例如"0001.mp3",放置在mp3文件夹下。如需中英文命名,可以添加在数字后。例如"0001hello.mp3"或者"0001后来.mp3",详见数据手册。
代码中使用的DFPlayer mini库文件已修改,增加了全曲循环功能。
以下是修改后的库文件:
file:///c:/users/admin/appdata/roaming/360se6/User Data/temp/222616u3de8kfrdu1ge0gt.png
file:///c:/users/admin/appdata/roaming/360se6/User Data/temp/222616u3de8kfrdu1ge0gt.png
你的sketch 我无法通过arduino验证。另外我特想知道这个DFPlayer Mini的ADKey是怎么连的,我照图纸连怎么模块灯也不亮,一点反应都没有。图纸是不是错的。 gada888 发表于 2015-11-10 15:09
你的sketch 我无法通过arduino验证。另外我特想知道这个DFPlayer Mini的ADKey是怎么连的,我照图纸连 ...
其实 我没没弄响 gada888 发表于 2015-11-10 15:09
你的sketch 我无法通过arduino验证。另外我特想知道这个DFPlayer Mini的ADKey是怎么连的,我照图纸连 ...
arduino校验失败是不是因为你没加载库文件?我这边试了下可以的。另外你是说wiki里的AD按键模式?MP3模块上的灯只有在播放MP3时才会亮,是不是你的MP3存放的位置不对?建议先确定模块会唱歌,tf卡内文件没问题后在按照图纸连接 大连林海 发表于 2015-11-10 16:03
其实 我没没弄响
感谢回复,你是说你也搞不定ADKEY吗 Cain 发表于 2015-11-10 16:31
arduino校验失败是不是因为你没加载库文件?我这边试了下可以的。另外你是说wiki里的AD按键模式?MP3模块 ...
感谢回复,tf卡没问题,和arduino 连接试过有音的。 gada888 发表于 2015-11-10 21:15
感谢回复,tf卡没问题,和arduino 连接试过有音的。
对,就是说那个wiki里的AD模式,感觉那个是骗人的。根本不起作用。 Cain 发表于 2015-11-10 16:31
arduino校验失败是不是因为你没加载库文件?我这边试了下可以的。另外你是说wiki里的AD按键模式?MP3模块 ...
我下载了库文件错误代码这个 要怎么解决啊?谢谢
Arduino:1.6.5 (Mac OS X), 板:"Arduino/Genuino Uno"
In file included from sketch_dec14d.ino:3:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:20: error: redefinition of 'uint8_t send_buf '
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:9: error: 'uint8_t send_buf ' previously defined here
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:3:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:20: error: redefinition of 'uint8_t recv_buf '
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:9: error: 'uint8_t recv_buf ' previously declared here
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:7:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:20: error: redefinition of 'uint8_t send_buf '
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:9: error: 'uint8_t send_buf ' previously defined here
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:7:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:20: error: redefinition of 'uint8_t recv_buf '
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:9: error: 'uint8_t recv_buf ' previously declared here
uint8_t recv_buf;
^
编译有误。
Cain 发表于 2015-11-10 16:31
arduino校验失败是不是因为你没加载库文件?我这边试了下可以的。另外你是说wiki里的AD按键模式?MP3模块 ...
我下载了库文件错误代码这个 要怎么解决啊?谢谢
Arduino:1.6.5 (Mac OS X), 板:"Arduino/Genuino Uno"
In file included from sketch_dec14d.ino:3:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:20: error: redefinition of 'uint8_t send_buf '
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:9: error: 'uint8_t send_buf ' previously defined here
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:3:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:20: error: redefinition of 'uint8_t recv_buf '
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:9: error: 'uint8_t recv_buf ' previously declared here
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:7:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:20: error: redefinition of 'uint8_t send_buf '
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:45:9: error: 'uint8_t send_buf ' previously defined here
uint8_t send_buf = {
^
In file included from sketch_dec14d.ino:7:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:20: error: redefinition of 'uint8_t recv_buf '
uint8_t recv_buf;
^
In file included from sketch_dec14d.ino:1:0:
/Documents/Arduino/libraries/DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3.h:47:9: error: 'uint8_t recv_buf ' previously declared here
uint8_t recv_buf;
^
编译有误。
大连林海,您好,图中接音频输出的那个接口是怎么弄的呀?
或者有什么可以替代吗?
谢谢 模块自身的UART参数是怎样的,买了一块回来,在电脑上做测试,波特率为9600,但是好像并不能通信起来 之前买的DFPlayer Mini全都出了问题,后来发现是模块的问题,正版的36快一块,我买的15快一块。买的山寨的了。 gada888 发表于 2015-11-10 21:15
感谢回复,tf卡没问题,和arduino 连接试过有音的。
我这边上传项目一直超时,怎么弄
页:
[1]