A cheap serial wav/mp3 player. Arduino and ESP8266 Library

Giovanni Bernardo | July 9th, 2017
Categories: Arduino - Domotic - ESP8266 - Microcontrollers - Multimedia

I was in search of a simple and cheap solution for implementing a sort of audio message center for my domotic system. The audio subsystem will be used for presence simulator in the house and for alarms (gas leaks, heartquakes in the nearby, weather alerts and so on).

After a little serching I’ve found a lot of cheap chinese wav/mp3 serial modules suitable for usage with Arduino, picmicro and all other mcus with harware or software UART.

I’ve choosen a module with a little on-board amplifier (3W) with connection for an external 8Ω speaker. This module has also a trans-flash (microsd) card socket, a standard 3.5mm socket for headphones and a led that turns on when an audio file is being played.

This module can read both classical microsd (up to 2Gb) and SDHC (above 2Gb up to 32Gb). Only 4 pins are available (GND, VCC, RX, TX). Serial port settings are 9600,8,n,1. Power supply for the module is 5V and the serial line works at 3.3V so it is perfect for usage with ESP8266 (ESP-01) or Arduino Leonardo.

It is great for toys, christmas crib and other space constrain devices since has an integrated power amplifier.

This is the module which I’m talking about:

There are few infos about chip used in this module. Vendor from Aliexpress gave me a pdf with the serial commands for this module and a simple Arduino Sketch. 

This module costs about €7, but there are a lot of cheaper ones (less than €3!), based on YX5300 IC. I’ve preferred this since have an on-board amplifier and then I can connect a speaker without making other connections.

Two ICs on board are the power amplifier (marked 8002A, using Google you can found a lot of datasheets) and the multi-function IC that reads files from microSD, receives serial commands, decodes WAV/MP3 files and bring audio to a DAC output that feeds both amplifier and audio-out socket.

This IC has no markings, so it has stimulated my curiosity.

Searching on the net I’ve found a similar module but instead of the microSD reader has a flash IC on-board and a micro-USB socket (this IC act as a bridge between USB port and flash). This second module is popular as  JQ8400FL (FL probably stands for FLASH).

This second module hasn’t same serial commands of mine, so my library is not compatible. Giving a look to schematics of two modules, connections are similar: on my module there are 2 not used pins (5 and 6) marked as USB D+/D- (in the FL module those pins are connected to USB socket). Then there are small differences (resistor values) but I think that the main IC is produced in 2 different revisions: one for using a flash memory and another for using a Trans-Flash.

After further investigations I’ve found on a chinese component market an IC marked as JQ8400TF (TF = Trans-Flash ?). Bingo. Unfortunately there are no datasheets but I take for good the PDF vendor sent me.  Another equivalent chip of JQ8400TF seems to be the QJ004-16S (probably are the same IC!).

Serial commands

My module requires a start byte (ox7E) followed by number of commands bytes (excluding start and stop bytes), then follow the byte identyifing commands and eventually parameters bytes. Finally there is a stop byte (0xEF). Module don’t requires Line Feed nor Carriage Return bytes. So schema is: ([start] [number of bytes of command excluding start and stop] [commando] [parameters if required] [stop])

Unlike other modules, this doesn’t use a checksum routine.

There are classical commands you can expect from an audio player:

0x01PLAYfa partire il play (è necessario aver "iniettato" prima una canzone). Oppure fa ripartire il play dopo una pausa/stop
0x02PAUSEMette in pausa la canzone (il successivo play riprende dal punto in cui si è data pausa)
0x03NEXT SONGEsegue il play del file successivo a quello attuale
0x04PREV SONGEsegue il play del file precedente a quello attuale
0x05VOLUME UPAumenta il volume di un passo
0x06VOLUME DOWNDiminuisce il volume di un passo
0x0AFORWARDEsegue il play veloce in avanti
0x0BREWINDEsegue il play veloce all'indietro
0x0ESTOPFerma la canzone

In my library (source code) I refer to these commands as 1-byte commands since these commands doesn’t require a parameter. Example, send “play” command:

0x7E 0x02 0x01 0xEF


  • ox7E: start byte
  • 0x02: this command is 2 bytes excluding start and stop (command byte + number of bytes byte)
  • 0x01: play command
  • 0xEF: stop byte

This module works with file indexes. Index of every file is the ordinal number you’ll image seeing files ordered by ascending name in your pc. The file on top of the list will be the 1, the second file will be 2 and so on. For playing the first file you’ll send the command “Play 1”. Better way is name the files as “001.mp3”, “002.wav” ecc, but is good also names as “001-dog.mp3”, “002-siren.wav” ecc… we’ll feed the play command only with index.

The volume command is 0x31 followed by a numeric value (0x00 volume off, 0x30 volume max). Example:

0x7E 0x03 0x30 0x15 0xEF
  • 0x7E : start
  • 0x03 : This command is 3 bytes (this byte, volume command, volume value)
  • 0x30 : volume command
  • 0x15 : volume value (from 0x00 to 0x30)
  • 0xEF : stop

There is an other commands composed of bytes : the media device selection.

This module can read only from SD, there are no alternatives. So at start-up is mandatory give the “read files from Trans-Flash” command (0x35):

0x7E 0x03 0x35 0x01 0xEF
  • 0x73E: Start
  • 0x03: This command is 3 bytes excluding start and stop
  • 0x35: Select device command
  • 0x01: Trans-Flash value (only option available on this module)
  • 0xEF: Stop

In my library, the initialization (.begin method) do select device command and set volume to maximum value.

Now following the very useful commands:

0x31PLAY WITH VOLUMESegue il valore di volume (da 0x00 a 0x30) e il byte dell'indice della canzone (da 0x00 a 0xFF)
0x41PLAY INDEXsegue un valore a 16 bit che indica l'indice del file (da 0x00 a 0xFFFF). Si inviano in pratica due bytes: byte alto e byte basso dell'indice
0x42PLAY DIR/INDEXSeguono due bytes, il primo byte è l'indice della cartella (segue lo stesso ragionamento per l'ordinamento dei files) e il secondo byte è l'indice del file contenuto in quella cartella
0x43INJECT INDEXFa la stessa cosa del comando PLAY INDEX, ma la canzone non parte. Per farla partire verrà inviato il comando semplice PLAY

The most useful command, for me, is PLAY INDEX, this command is followed by a 16bit integer that is the song index. For playing the song wich have index 1, command to send is:

0x7E 0x04 0x41 0x00 0x01 0xEF
  • 0x7E: Start
  • 0x04: This command is 4 bytes excluding start and stop
  • 0x41: Play Index command
  • 0x00: Index High byte
  • 0x01: Index Low byte
  • 0xEF: Stop

The simple Play command won’t start the play unless you’ve injected a song using the Inject Command (0x43). After you’ve injected a song you can use play. The Play index command executes inject+play.

The are other commands (repeat and sequential play up to 15 songs). Those commands in the library are implemented but I haven’t tried it.

Arduino IDE Library

Library I’ve written is for Arduino IDE. I’ve written it for use module with an ESP-01 module but I’ve tested it again an Arduino Duemilanove and an Arduino Leonardo. I’ve explained the commands so if you use another microcontroller, you can write your own library. The Arduino Library uses the hardware serial port (you can select the serial port number on Arduino Mega).

You must downlad the Library from my Github at this address or at the end of this article ad extract it in the personal Libraries folder of Arduino IDE (the one is located in the documents folder, not the one located in application folder!). Using newer versions of Arduino IDE this operation is simple: once you’ve downloaded the .zip file, lauch Arduino IDE, from Sketch” menu, select “#include library” and then “Add from Zip file”, so select the zip file you’ve downloaded.

Library contains a simple example. Firt you must load at least one audio file on the microSD (WAV or MP3 format), then we can try the Play Index command using index 1.

First of all, include the libray:

#include <mp3serial_JQ8400TF.h>

Then instance libray with name you prefer:

mp3Serial mp3(0); // initialize library on serial port 0 (for Arduino duemilanove)

In my example I’ve instanced library using name “mp3”. I’ve put a 0 bewteen brackets to indicate I want to use the only serial port available on Arduino Duemilanove or on the ESP-01 module. If you’re using an Arduino Leonardo, you’ll put 1 for using Serial1 (the one not used form USB port). Serial1 is also available on Arduino Mega. On Arduino Mega you can use also 2 and 3.

In the setup function you must initialize module:

mp3.begin(); // init module

The begin function will start serial port at 9600bps, and gives commands for select Trans-Flash and set the volume to maximum value.

I play the first song:

mp3.playIndex(1); // play first song

The loop function in the example is empty. After you’ve given a play command, you must wait the song finishes or wait some milliseconds first to use antoher play command or the module gives bad responses (squeaky audio).

Library includes all 1 bytes commands:

play(), pause(), next(), prev(), volumeup(), volumedown(), forward(), rewind(), stop()

and 2/3 bytes commands:

play(), pause(), next(), prev(), volumeup(), volumedown(), forward(), rewind(), stop()

You would use a simple method to retrieve the end of play: the pin 4 of the chip is identified as “busy” and is connected to a small led on the module. This pin can be used for this. Module gives also some response after each received command but I’ve not found informations on response bytes.


Mp3/Wav serial module manual (38 downloads) Arduino library for Mp3/Wav module (35 downloads)


Github Repository (here is the most recent library release)


Questo articolo ti è stato utile? Ti ha permesso di risolvere un problema o di migliorare le tue applicazioni? Ci lavori? Ti ha permesso di scrivere la tua tesina? Ti ha semplicemente fatto spendere un po' del tuo tempo in maniera costruttiva? Allora clicca il banner qui sotto:

Settorezero.com è un blog personale di Giovanni Bernardo aperto dal 25 Ottobre 2007. Non è una testata giornalistica né un sito a carattere commerciale.
Settorezero.com, il logo Zroid™ e la tagline "Play embedded electronics™" sono copyright ©2007÷2018 Giovanni Bernardo.
La navigazione su settorezero.com e la fruizione dei contenuti ivi presenti sono soggette ai seguenti Termini di utilizzo - Informativa sulla privacy - Utilizzo dei Cookie.
Il tema di questo sito è basato sul tema Fusion per wordpress, realizzato originariamente da digitalnature e fa uso del plugin Wassup per il computo delle statistiche.
Per poter contattare il gestore del sito potete utilizzare la sezione contatti o inviare una email a gianni[at]settorezero[dot]com.
Per seguire gli aggiornamenti del blog Settorezero, oltre al feed RSS, puoi anche seguire la pagina Facebook o iscriverti al canale Telegram.
Su Twitter, invece, pubblico un po' di tutto e, quando mi va, uso anche Tumblr - Google+ - Blogspot - Youtube.