Advertisement
Maderdash

mp3Player

Jul 21st, 2022
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. #define ARDUINO_RX 5                             // should connect to TX of the Serial MP3 Player module
  3. #define ARDUINO_TX 6                             // connect to RX of the module
  4. SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX); // init the serial protocol, tell to myserial wich pins are TX and RX
  5. static int8_t Send_buf[8] = {0}; // The MP3 player undestands orders in a 8 int string
  6.                                  // 0X7E FF 06 command 00 00 00 EF;(if command =01 next song order)
  7. #define CMD_PLAY_W_INDEX 0X03    // DATA IS REQUIRED (number of song)
  8. #define CMD_SET_VOLUME 0X06      // DATA IS REQUIRED (number of volume from 0 up to 30(0x1E))
  9. #define SET_DAC 0X17
  10. #define CMD_PLAY_WITHVOLUME 0X22 // data is needed  0x7E 06 22 00 xx yy EF;(xx volume)(yy number of song)
  11. #define CMD_SEL_DEV 0X09         // SELECT STORAGE DEVICE, DATA IS REQUIRED
  12. #define DEV_TF 0X02              // HELLO,IM THE DATA REQUIRED
  13. #define CMD_RESET 0X0C           // CHIP RESET
  14. #define CMD_PLAY 0X0D            // RESUME PLAYBACK
  15. #define CMD_PAUSE 0X0E           // PLAYBACK IS PAUSED
  16. #define CMD_PLAY_WITHFOLDER 0X0F // DATA IS NEEDED, 0x7E 06 0F 00 01 02 EF;(play the song with the directory \01\002xxxxxx.mp3
  17. #define PLAY_FOLDER 0X17         // data is needed 0x7E 06 17 00 01 XX EF;(play the 01 folder)(value xx we dont care)
  18. #define SET_CYCLEPLAY 0X19       // data is needed 00 start; 01 close
  19. #define SET_DAC 0X17             // data is needed 00 start DAC OUTPUT;01 DAC no output
  20.  
  21. void setup(){
  22.   Serial.begin(9600);               // Start our Serial coms for serial monitor in our pc
  23.   mySerial.begin(9600);             // Start our Serial coms for THE MP3
  24.   delay(500);                       // Wait chip initialization is complete
  25.   sendCommand(CMD_SEL_DEV, DEV_TF); // select the TF card
  26.   delay(200);                       // wait for 200ms
  27. }
  28. void loop(){
  29.   sendCommand(CMD_PLAY_WITHVOLUME, 0X0F01); // play the first song with volume 15 class
  30.   delay(1000000);                           // the programm will send the play option each 100 seconds to the catalex chip
  31. }
  32.  
  33. void sendCommand(int8_t command, int16_t dat){
  34.   delay(20);
  35.   Send_buf[0] = 0x7e;               // starting byte
  36.   Send_buf[1] = 0xff;               // version
  37.   Send_buf[2] = 0x06;               // the number of bytes of the command without starting byte and ending byte
  38.   Send_buf[3] = command;            //
  39.   Send_buf[4] = 0x00;               // 0x00 = no feedback, 0x01 = feedback
  40.   Send_buf[5] = (int8_t)(dat >> 8); // datah
  41.   Send_buf[6] = (int8_t)(dat);      // datal
  42.   Send_buf[7] = 0xef;               // ending byte
  43.   for (uint8_t i = 0; i < 8; i++){
  44.     mySerial.write(Send_buf[i]);    // send bit to serial mp3
  45.     Serial.print(Send_buf[i], HEX); // send bit to serial monitor in pc
  46.   }
  47.   Serial.println();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement