Sitemap / Advertise

Information



Tags



Share

How to use the Serial MP3 Player (UART) with Speaker by OPEN-SMART with Arduino

Advertisement:


read_later

Read Later

Keywords



Keywords



read_later

Read Later

Information

Tags

Share





Advertisement

Advertisement




Definition

In this tutorial, I will show you how to control a Serial MP3 Player with Speaker by OPEN-SMART to play songs in a micro SD card by sending UART commands to the module.

It is effortless to use a Serial MP3 Player with Arduino as long as you know the UART commands required to trigger the right functions. Do not forget that if you have a Serial MP3 Player with a different brand name, the commands shown below will not work for your module.

Instructions(1)

"The module is a kind of simple MP3 player device which is based on a high-quality MP3 audio chip. It can support 8k Hz ~ 48k Hz sampling frequency MP3 and WAV file formats. There is a TF card socket on board, so you can plug the micro SD card that stores audio files. MCU can control the MP3 playback state by sending commands to the module via UART port, such as switch songs, change the volume and play mode, and so on. You can also debug the module via USB to UART module. It is compatible with Arduino / AVR / ARM / PIC."

"Make sure your micro SD card is formatted as FAT16 or FAT32 and there are some songs in it. You should create folders “01” and “02”, and put some songs with the name 001xxx.mp3 / 002xxx.mp3 / 003xxx.mp3 in the two folders."

In other words, to be able to execute commands accurately, save your songs in a folder named as '01' and add consecutive numbers to song names - 001xxx.mp3, 002xxx.mp3.

Commands(1)

Command Command bytes without checksum(HEX) Remark
[Play] 7E 02 01 EF Resume playback
[Pause] 7E 02 02 EF Playback is paused
[Next Song] 7E 02 03 EF
[Previous Song] 7E 02 04 EF
[Volume up] 7E 02 05 EF Volume increased one
[Volume down] 7E 02 06 EF Volume decrease one
[Forward] 7E 02 0A EF Fast forward
[Rewind] 7E 02 0B EF Fast rewind
[Stop play] 7E 02 0E EF
[Stop inject] 7E 02 0F EF Stop injecting the song
[Select device] 7E 03 35 01 EF Select storage device to TF card
[Set IC mode] 7E 03 35 02 EF Wake up
7E 03 35 03 EF Sleep
7E 03 35 05 EF Reset
[Play with index] 7E 04 41 00 01 EF Play the first song
7E 04 41 00 0A EF Play the tenth song
[Play with folder and file name] 7E 04 42 01 01 EF Play the song with the directory: /01/001xxx.mp3
7E 04 42 01 02 EF Play the song with the directory: /01/002xxx.mp3
[Inject with index] 7E 04 43 00 01 EF Inject the fist song in the TF card
[Set volume] 7E 03 31 0F EF Set the volume to 15 (0x0F is 15)
[Play with volume] 7E 04 31 1E 01 EF Set the volume to 30 (0x1E is 30) and play the first
7E 04 31 0F 02 EF Set the volume to 15(0x0f is 15) and play the second song
[Set play mode] 7E 03 33 00 EF All songs cycle play
7E 03 33 01 EF Start up single cycle play
7E 04 33 00 01 EF Single cycle play the first song
[Play combine] 7E 08 45 01 05 02 01 01 03 EF Play combination of the fifth song in the folder “01”, the first song in the folder “02” and the third in the folder “01”

Code

To send UART commands to the Serial MP3 Player with Arduino Nano, I created a function named as send_command_to_MP3_player. It transfers each byte in the requested command to the Serial MP3 Player via the SoftwareSerial library, depending on the length of the requested command - 4, 5, or 6.

As shown below, separate the command you want to send to the Serial MP3 Player by bytes - 0x7e. All commands start with '7E' and end with 'EF'. The second byte is the number of the bytes in between - '02', '03', '04'.

- Include the SoftwareSerial library.

- Define the RX and TX pins to establish UART communication with the MP3 Player Module.

- Define the required MP3 Player Commands:

- 7E 03 35 01 EF (Select the micro SD card as storage)

- 7E 04 41 00 01 EF (Play with index: /01/001xxx.mp3)

- 7E 04 41 00 02 EF (Play with index: /01/002xxx.mp3)

- 7E 02 01 EF (Play or Resume the song)

- 7E 02 02 EF (Pause the song)

- Define the Serial MP3 Player Module by using the SoftwareSerial library.

- Initiate the serial monitor.

- Initiate the Serial MP3 Player Module.

- Select the SD Card.

- Play the second song.

- In the send_command_to_MP3_player funtion, transfer each byte of the given command (UART) to the Serial MP3 Player.


-------------- Arduino --------------

// Connections
// Arduino:           
//                                Serial MP3 Player Module (OPEN-SMART)
// D8 --------------------------- TX
// D7 --------------------------- RX

// Include required libraries:
#include <SoftwareSerial.h>

// Define the RX and TX pins to establish UART communication with the MP3 Player Module.
#define MP3_RX 8 // to TX
#define MP3_TX 7 // to RX

// Define the required MP3 Player Commands:

// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play with index: /01/001xxx.mp3
static int8_t play_first_song[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play with index: /01/002xxx.mp3
static int8_t play_second_song[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF

// Define the Serial MP3 Player Module.
SoftwareSerial MP3(MP3_RX, MP3_TX);

void setup() {
  // Initiate the serial monitor.
  Serial.begin(9600);
  // Initiate the Serial MP3 Player Module.
  MP3.begin(9600);
  // Select the SD Card.
  send_command_to_MP3_player(select_SD_card, 5);
}

void loop() {
	// Play the second song.
	send_command_to_MP3_player(play_second_song, 6);
}


void send_command_to_MP3_player(int8_t command[], int len){
  Serial.print("\nMP3 Command => ");
  for(int i=0;i<len;i++){ MP3.write(command[i]); Serial.print(command[i], HEX); }
  delay(1000);
}

Result:

You can inspect my electronics project in which I used this method to control the Serial MP3 Player by OPEN-SMART with Arduino from here.

References

(1) https://www.theamplituhedron.com/projects/Arduino-RFID-Reading-Time-Checker-with-MP3-Player-and-RTC/Downloads/Serial%20MP3%20Player%20A%20v1.1%20Manual.pdf