你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

Arduino Mp3播放器Catalex

[复制链接]
木木&点点 发布时间:2019-3-16 11:59
本帖最后由 点点&木木 于 2019-4-12 20:30 编辑 0 t) K& G6 r. c

: G0 `0 _& d+ H& j, |6 I* [6 I' W. o% x
. o) ~2 I) u3 g5 ?9 S5 n. U& U
硬件组件
Arduino UNO和Genuino UNO         ×  1      
catalex的串口MP3播放器  ×   1      
一些不错的朋克音乐            
5 {; @2 v( ^8 G2 T) A2 b* u

1 ~2 ]" g- T1 q) K7 n2 o
介绍
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png 1.jpg
        arduino uno,mp3模块

$ |* w4 Y0 E& f) l) {5 D; j& @
* r  _8 n9 y& V2 `* M2 K0 j
如何使用CATALEX的SERIAL MP3PLAYER V1.0:
首先,像往常一样下载库:
# I  {: C& I  I; m
#include <SoftwareSerial.h>
4 l3 T2 j. U" l: a, }+ T
" i- f5 x: }' R3 |: i
现在我们选择将哪些Arduino引脚连接到mp3播放器并初始化串行协议。
9 X1 O/ N# p" v5 I9 L4 m  ^9 t9 a
#define ARDUINO_RX 5//should connect to TX of the Serial MP3 Player module 7 [; M; h; u" [8 E7 K" X% N; j$ e
#define ARDUINO_TX 6//connect to RX of the module ( T2 j# O# n4 \0 X0 V: Y/ U7 W
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell to myserial wich pins are TX and RX
0 o+ z1 ]! p, L- L+ r  w
) r4 [9 I& r0 |% I+ ~% `9 o( u' r* \
在这里,我只是从数据表翻译成#define

1 c& U* F2 U$ c# W7 s* B4 [+ @//////////////////////////////////////////////////////////////////////////////////// . C5 K8 M9 }1 V+ h8 o" j
//all the commands needed in the datasheet(http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf) 7 u9 t9 U2 u6 t
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
( \9 o2 Z9 Q- s% E
                                //0X7E FF 06 command 00 00 00 EF;(if command =01 next song order)  
1 Y/ O" }0 w- S
#define NEXT_SONG 0X01  3 Y7 J8 D# E' [# A
#define PREV_SONG 0X02  * V6 I$ ^2 l  r! Z
#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)
) _" i) R! A- s; g2 h( `
#define VOLUME_UP_ONE 0X04
1 s3 ~8 l  u# g4 g7 K! |* J$ p' Y
#define VOLUME_DOWN_ONE 0X05 % C9 U! O  e7 w+ c% ?
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
9 C( q+ [$ D+ a5 Y9 w
#define SET_DAC 0X17 8 g$ u6 [& J; `9 _- V7 J+ ?
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song) ! K8 {: h8 C0 f. L5 }
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
$ ~& K" m- E8 }2 L- x$ b
               #define DEV_TF 0X02 //HELLO,IM THE DATA REQUIRED ! x( ~! d. d: W. q/ ?( p; |+ a" H
#define SLEEP_MODE_START 0X0A 9 u9 W7 f% j- t+ G" d" m
#define SLEEP_MODE_WAKEUP 0X0B : O8 Z( C# Y- l+ L8 }5 ]- L4 Q( ~3 y
#define CMD_RESET 0X0C//CHIP RESET
$ }9 f4 a: ^: [0 A
#define CMD_PLAY 0X0D //RESUME PLAYBACK
% W  Q2 F% ]" @1 u! ]
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED
' E5 e0 h! u4 Z( G4 x. l& a/ [
#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3
- f& M% Z- V9 p
#define STOP_PLAY 0X16 4 W" K9 B3 X3 I
#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)
! @6 D) J5 h- x. c" n
#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close ; u/ S' G  @" i! ~( K' |0 A) `
#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output
7 \* ~  \3 C$ D, V' v
//////////////////////////////////////////////////////////////////////////////////// ( P$ v4 {2 J/ x0 x$ N

" n; w' W# R9 i: u/ f( O- ]
MP3芯片不符合使用此格式的int数组[8]的命令
0x7E FF aa bb 00 xx yy EF ) a5 W0 S/ G; ]5 [3 p- s
! S4 U; i: e8 s0 z
哪里:
第一个和最后一个int用0x7E和0xEF值固定
aa 是版本号,只需输入0x06;
bb 是前一点中列出的实际控制命令
xx 首先是数据的b int
yy 是数据的第二个int
这是构建数组的实际函数。我们只需要选择其中一个#defined命令并输入数据的值。

, H/ }" q) r- R* W' r) P% wvoid sendCommand(int8_t command, int16_t dat)
% L- c$ O9 V" t- W: R
{ # N$ Q) j8 _7 P4 D- ~! d. P
delay(20); / [+ W& X  l8 ~. ^
Send_buf[0] = 0x7e; //starting byte
6 \  I# P7 T- u6 ^" }
Send_buf[1] = 0xff; //version
) T1 h5 T2 K: d/ B% u
Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
: H7 K* J( @! Y8 v! a% u8 a8 J0 }
Send_buf[3] = command; //
- e# L$ M6 b' n% p+ N
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback 6 X9 W- {- T0 ^# `8 c3 z
Send_buf[5] = (int8_t)(dat >> 8);//datah
. U4 v& u3 n4 O% \
Send_buf[6] = (int8_t)(dat); //datal ! y# d( }6 a3 R+ M8 B
Send_buf[7] = 0xef; //ending byte / g. l, I' U' i( q9 l* n3 P: A3 |
for(uint8_t i=0; i<8; i++)// ; i/ m) D  ~; [6 T+ p6 {3 D% a$ g! U
{ & B! @* T$ w7 I! ^# I8 {. s
  mySerial.write(Send_buf) ; : T6 I1 U( _0 W  j  _- Q+ p
} ; _- E1 D( C1 ]  o6 H8 W
}
0 }- J4 B2 x+ x; w1 H% ]; [3 @5 }: j% X* W1 G
# u8 c2 z. j" E; A' b1 F" ]
进入设置功能,我们需要为TF选择合适的设备并给它时间来解决:

, Z. r( e! `- `# s3 R
void setup() {
1 P4 }, `0 D6 W4 S" |( U+ PmySerial.begin(9600);
4 o8 X( D& H. S  @* s! t5 ]6 P1 C//Start our Serial coms for our serial monitor! delay(500);
) D) Q1 S4 |2 z, G//Wait chip initialization is complete   sendCommand(CMD_SEL_DEV, DEV_TF);! ^: _5 d  {. k1 k
//select the TF card   delay(200);/ \" S/ V8 R$ S2 p) I
//wait for 200ms }
) b% j$ D5 m0 O- E% m3 N
  \7 y$ O  w! g- ?9 {
在循环中,我做了一个简单的播放标记为001的歌曲:
void loop() # o7 H# l) \. A4 |) e8 `0 S
{
$ X' z, b9 \1 L6 X
sendCommand(CMD_PLAY_WITHVOLUME, 0X0F01);//play the first song with volume 15 class
' G! `  W7 s% \1 g* f% G; S
delay(1000000);//the programm will send the play option each 100 seconds to the catalex chip
$ D! {' p" x  Z" M. E
} 3 {* ?' `/ t! p# P0 w; D& f" \
1 Q6 L  F2 T, B# N4 E
如何将歌曲上传到SD卡:
正如他们在数据表中所说的英语非常糟糕:
file:///C:/Users/ADMINI~1/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png 1.2.jpg
我在这里做得很好

& Q1 F+ }* ?% M# i" K6 y$ `  q: R" a& E; D1 b: c
Mp3芯片读取.mp3或.wav按字母顺序索引,因此如果我们创建名称为01,02的文件夹,并且带有名称的歌曲001xxxxx.mp3,002xxxx.mp3。我们可以确定我们正在使用的歌曲/文件夹。
- S/ \1 L9 T* l4 g! T' b2 q! j! \
* ]/ ^3 S/ B* G  w9 ^4 B
) o! C9 L. F, W# }* r; Q" C
EXTRA:
" B2 ^+ t! g% Z  R相同的代码,但使用硬件序列(我不得不用我的STM32板)
9 Q# ^9 B) W) x, m- U
( {3 d! @. D4 ~
原理图
2.png
! Y: y# z2 U, Y3 v' Z
; m  N9 f! r, K2 \! ]+ d
代码
//code rearranged by Javier Muñoz10/11/2016 ask me at javimusama@hotmail.com
#include <SoftwareSerial.h>
  e3 L0 X9 {5 }  ]: m4 [
#define ARDUINO_RX 5//should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6//connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);//init the serial protocol, tell tomyserial wich pins are TX and RX

" w: T; \( X: I7 C1 U
////////////////////////////////////////////////////////////////////////////////////
//all the commands needed in thedatasheet(http://geekmatic.in.ua/pdf/Catalex_MP3_board.pdf)
static int8_t Send_buf[8] = {0} ;//The MP3 player undestands orders in a 8 int string
                                 //0X7E FF 06 command 00 00 00 EF;(if command =01 nextsong order)
#define NEXT_SONG 0X01
#define PREV_SONG 0X02
" k9 M* N* b; @+ W
#define CMD_PLAY_W_INDEX 0X03 //DATA IS REQUIRED (number of song)

6 P* {) J8 U7 [$ o# J' N, X% D1 S; A
#define VOLUME_UP_ONE 0X04
#define VOLUME_DOWN_ONE 0X05
#define CMD_SET_VOLUME 0X06//DATA IS REQUIRED (number of volume from 0 up to30(0x1E))
#define SET_DAC 0X17
#define CMD_PLAY_WITHVOLUME 0X22 //data is needed 0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)

+ o! k. j3 F, @- w. _
#define CMD_SEL_DEV 0X09 //SELECT STORAGE DEVICE, DATA IS REQUIRED
                #define DEV_TF 0X02 //HELLO,IM THE DATAREQUIRED

- s3 R: m; P* X, Y
#define SLEEP_MODE_START 0X0A
#define SLEEP_MODE_WAKEUP 0X0B

& P  n0 e: t4 |; u6 _
#define CMD_RESET 0X0C//CHIP RESET
#define CMD_PLAY 0X0D //RESUME PLAYBACK
#define CMD_PAUSE 0X0E //PLAYBACK IS PAUSED

3 ^# d, A. y! G9 ~: S$ O
#define CMD_PLAY_WITHFOLDER 0X0F//DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the songwith the directory \01\002xxxxxx.mp3
  Y0 o+ ~" J1 v8 C! I
#define STOP_PLAY 0X16
/ d4 ~8 s; C  s& a5 ~, e+ Z
#define PLAY_FOLDER 0X17// data is needed 0x7E 06 17 00 01 XX EF;(play the 01folder)(value xx we dont care)
; R) Q# N, M  m8 q, s( _. m
#define SET_CYCLEPLAY 0X19//data is needed 00 start; 01 close

9 ]: Q+ ~! e! _+ }
#define SET_DAC 0X17//data is needed 00 start DAC OUTPUT;01 DAC no output
////////////////////////////////////////////////////////////////////////////////////
) W# L! d. n5 c3 H6 v, f* T

4 J4 A* T9 u/ ~) k5 m
void setup()
{
  Serial.begin(9600);//Start our Serial coms for serial monitor in our pc
mySerial.begin(9600);//Start our Serial coms for THE MP3
delay(500);//Wait chip initialization is complete
   sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
delay(200);//wait for 200ms

4 r7 P% s" ]: Q- h4 x0 B, s4 o
}
void loop()
{
sendCommand(CMD_PLAY_WITHVOLUME, 0X0F01);//play the first song with volume 15 class
delay(1000000);//the programm will send the play optioneach 100 seconds to the catalex chip
}
  r- t+ r; q, H- ~" S  l" U  ?
void sendCommand(int8_t command, int16_t dat)
{
delay(20);
Send_buf[0] = 0x7e; //starting byte
Send_buf[1] = 0xff; //version
Send_buf[2] = 0x06; //the number of bytes of the command without startingbyte and ending byte
Send_buf[3] = command; //
Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
Send_buf[5] = (int8_t)(dat >> 8);//datah
Send_buf[6] = (int8_t)(dat); //datal
Send_buf[7] = 0xef; //ending byte
for(uint8_t i=0; i<8; i++)//
{
   mySerial.write(Send_buf) ;//send bit to serial mp3
   Serial.print(Send_buf,HEX);//send bit to serial monitor in pc
}
Serial.println();
}

  m1 n% X1 e/ Q2 G1 z* l3 {
赞 收藏 评论0 发布时间:2019-3-16 11:59

举报

0个回答
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版