本產品停產,請參考 [Grove - MP3 2.0](https://makehub.tw/spot/grove-mp3v2)
原廠只提供範例程式,還得讓使用者自行查閱規格書,再一一合成命令或解析傳回字串,為了替大家節省開發時間,特地撰寫打包了一個基本的 Arduino 驅動程式,放在 https://github.com/MCUapps/Grove_Serial_MP3_Player,目前框架已經完成並測試成功,近期將逐漸補完。
客戶們可以參考函式庫所附的範例 MP3_Console,直接呼叫打包好的函式,並且獲得排列整齊的回傳碼,就能很便利的套用在您自己的應用當中。以下是一個最基本的使用範例。
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "MP3.h"
SoftwareSerial mp3Serial(2, 3); // RX, TX
MP3 player(mp3Serial);
void setup()
{
delay(100);
}
void loop()
{
player.setMode(1);
player.playSong(1);
player.pushSong(2);
player.getStatus();
}
因為晶片的韌體有點愚蠢,若不符合上述條件就不會回應任何命令。所以請先插入符合條件的 microSD 卡再進行開發。
原廠連結:http://www.seeedstudio.com/wiki/Grove_-_Serial_MP3_Player_串口MP3播放器
Grove- Serial MP3 Player是一款基於高品質MP3音頻芯片-WT5001的簡易MP3播放設備。它可以支持8kHz~44.1kHz採樣頻率以及MP3和WAV的文件格式。這款產品有一些外設端口:一個標準的UART Grove接口,一個雙聲道耳機接口,一個外部接口以及一個迷你SD卡槽。您可通過串口工具向模塊發送命令來控制MP3播放狀態,如切歌,調整音量及播放模式等。這個模塊雖然看起來很簡單,但功能強大。想知道它的音質如何?來試試吧!
Model:SEN01300P
Grove - Serial MP3 Player可由Arduino/Seeeduino控制。在這裡我們為您提供了串口MP3測試代碼。相信您能很快上手。獲取更詳細的信息,請參照下面的描述。硬件安裝:
下面的代碼包括播放模式參數,您只需改變參數即可轉換播放模式。
/*****************************************************************************/ // Function: control the seeedstudo Grove MP3 player // Hardware: Grove - Serial MP3 Player /*******************************************************************************/ #include <SoftwareSerial.h> SoftwareSerial mp3(2, 3);//modify this with the connector you are using. void setup() { mp3.begin(9600); Serial.begin(9600); delay(100); if (true ==SetPlayMode(0x01)) Serial.println("Set The Play Mode to 0x01, Single Loop Mode."); else Serial.println("Playmode Set Error"); PauseOnOffCurrentMusic(); } void loop() { SetPlayMode(0x01); delay(1000); SetMusicPlay(00,01); delay(1000); SetVolume(0x0E); while(1); } //Set the music index to play, the index is decided by the input sequence //of the music; //hbyte: the high byte of the index; //lbyte: the low byte of the index; boolean SetMusicPlay(uint8_t hbyte,uint8_t lbyte) { mp3.write(0x7E); mp3.write(0x04); mp3.write(0xA0); mp3.write(hbyte); mp3.write(lbyte); mp3.write(0x7E); delay(10); while(mp3.available()) { if (0xA0==mp3.read()) return true; else return false; } } // Pause on/off the current music boolean PauseOnOffCurrentMusic(void) { mp3.write(0x7E); mp3.write(0x02); mp3.write(0xA3); mp3.write(0x7E); delay(10); while(mp3.available()) { if (0xA3==mp3.read()) return true; else return false; } } //Set the volume, the range is 0x00 to 0x1F boolean SetVolume(uint8_t volume) { mp3.write(0x7E); mp3.write(0x03); mp3.write(0xA7); mp3.write(volume); mp3.write(0x7E); delay(10); while(mp3.available()) { if (0xA7==mp3.read()) return true; else return false; } } boolean SetPlayMode(uint8_t playmode) { if (((playmode==0x00)|(playmode==0x01)|(playmode==0x02)|(playmode==0x03))==false) { Serial.println("PlayMode Parameter Error! "); return false; } mp3.write(0x7E); mp3.write(0x03); mp3.write(0xA9); mp3.write(playmode); mp3.write(0x7E); delay(10); while(mp3.available()) { if (0xA9==mp3.read()) return true; else return false; } }
注意: 1.SetPlayMode(uint8_t playmode)
2.SetVolume(uint8_t volume)
3.SetMusicPlay(uint8_t hbyte,uint8_t lbyte)
4.PauseOnOffCurrentMusic(void) 這個函數用於暫停/繼續當前音樂。 ‧現在您可以聽到SD卡中存儲的音樂了。播放模式中,D1指示燈亮著。如果在暫停模式,指示燈將會閃爍。還有更多體驗等你來發現!
還有另一種用串口工具控制MP3播放器的方法,您需要一個UartSBee將MP3連接到電腦。硬件安裝如下所示:
連接完成後,打開串口工具並發送命令。關於詳細的命令,請看參考部分。
還有更多體驗等你哦。
常見命令描述如下表:
命令名 | 命令格式 | 描述 |
---|---|---|
暫停 | 7E 02 A3 7E | 第一次發送此命令音樂會停止,再發送一次,音樂會繼續。 |
停止 | 7E 02 A4 7E | 這個命令可觸發下一首歌,如正在播放最後一首則會觸發第一首歌曲。 |
下一首 | 7E 02 A5 7E | 這個命令可觸發下一首歌,如正在播放最後一首則會觸發第一首歌曲。 |
上一首 | 7E 02 A6 7E | 這個命令可觸發上一首歌,如正在播放第一首則會觸發最後一首歌曲。 |
聲音控制 | 7E 03 A7 1F 7E | 從00到31共有32個音量級,00音量最小,31音量最大。 |
指定的播放模式 | 7E 03 A9 XX 7E | XX=00單曲播放(默認)。 |
XX=01單曲循環模式。 | ||
XX=02列表循環模式。 | ||
XX=03隨機播放模式。 |
Grove- Serial MP3 PlayerEagle文件
Grove- Serial MP3 Player原理圖文件.PDF
Github上的演示代碼
規格書WT5001
資料來源:https://www.seeedstudio.com/Grove---Serial-MP3-Player-p-1542.html
This product is retired, please consider our Grove - MP3 v2.0 as your alternative choice.