JQ6500 MP3 Player Arduino Library
A simple library to control a JQ6500 MP3 Player Module from an Arduino.
JQ6500_Serial Class Reference

Public Member Functions

 JQ6500_Serial (Stream *dev)
 Create JQ6500 object. More...
 
 JQ6500_Serial (Stream &dev)
 
void play ()
 Start playing the current file.
 
void restart ()
 Restart the current (possibly paused) track from the beginning. More...
 
void pause ()
 Pause the current file. More...
 
void next ()
 Play the next file.
 
void prev ()
 Play the previous file.
 
void nextFolder ()
 Play the next folder.
 
void prevFolder ()
 Play the previous folder.
 
void playFileByIndexNumber (unsigned int fileNumber)
 Play a specific file based on it's (FAT table) index number. More...
 
void playFileNumberInFolderNumber (unsigned int folderNumber, unsigned int fileNumber)
 Play a specific file in a specific folder based on the name of those folder and file. More...
 
void volumeUp ()
 Increase the volume by 1 (volume ranges 0 to 30).
 
void volumeDn ()
 Decrease the volume by 1 (volume ranges 0 to 30).
 
void setVolume (byte volumeFrom0To30)
 Set the volume to a specific level (0 to 30). More...
 
void setEqualizer (byte equalizerMode)
 Set the equalizer to one of 6 preset modes. More...
 
void setLoopMode (byte loopMode)
 Set the looping mode. More...
 
void setSource (byte source)
 Set the source to read mp3 data from. More...
 
void sleep ()
 Put the device to sleep. More...
 
void reset ()
 Reset the device (softly). More...
 
byte getStatus ()
 Get the status from the device. More...
 
byte getVolume ()
 Get the current volume level. More...
 
byte getEqualizer ()
 Get the equalizer mode. More...
 
byte getLoopMode ()
 Get loop mode. More...
 
unsigned int countFiles (byte source)
 Count the number of files on the specified media. More...
 
unsigned int countFolders (byte source)
 Count the number of folders on the specified media. More...
 
unsigned int currentFileIndexNumber (byte source)
 For the currently playing (or paused, or file that would be played next if stopped) file, return the file's (FAT table) index number. More...
 
unsigned int currentFilePositionInSeconds ()
 For the currently playing or paused file, return the current position in seconds. More...
 
unsigned int currentFileLengthInSeconds ()
 For the currently playing or paused file, return the total length of the file in seconds. More...
 
void currentFileName (char *buffer, unsigned int bufferLength)
 Get the name of the "current" file on the SD Card. More...
 

Protected Member Functions

void sendCommand (byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength)
 Send a command to the JQ6500 module,. More...
 
void sendCommand (byte command)
 
void sendCommand (byte command, byte arg1)
 
void sendCommand (byte command, byte arg1, byte arg2)
 
unsigned int sendCommandWithUnsignedIntResponse (byte command)
 Send a command to the JQ6500 module, and get a response. More...
 
unsigned int getVersion ()
 
int waitUntilAvailable (unsigned long maxWaitTime=1000)
 

Protected Attributes

Stream * _serial
 

Static Protected Attributes

static const uint8_t MP3_CMD_BEGIN = 0x7E
 
static const uint8_t MP3_CMD_END = 0xEF
 
static const uint8_t MP3_CMD_PLAY = 0x0D
 
static const uint8_t MP3_CMD_PAUSE = 0x0E
 
static const uint8_t MP3_CMD_NEXT = 0x01
 
static const uint8_t MP3_CMD_PREV = 0x02
 
static const uint8_t MP3_CMD_PLAY_IDX = 0x03
 
static const uint8_t MP3_CMD_NEXT_FOLDER = 0x0F
 
static const uint8_t MP3_CMD_PREV_FOLDER = 0x0F
 
static const uint8_t MP3_CMD_PLAY_FILE_FOLDER = 0x12
 
static const uint8_t MP3_CMD_VOL_UP = 0x04
 
static const uint8_t MP3_CMD_VOL_DN = 0x05
 
static const uint8_t MP3_CMD_VOL_SET = 0x06
 
static const uint8_t MP3_CMD_EQ_SET = 0x07
 
static const uint8_t MP3_CMD_LOOP_SET = 0x11
 
static const uint8_t MP3_CMD_SOURCE_SET = 0x09
 
static const uint8_t MP3_CMD_SLEEP = 0x0A
 
static const uint8_t MP3_CMD_RESET = 0x0C
 
static const uint8_t MP3_CMD_STATUS = 0x42
 
static const uint8_t MP3_CMD_VOL_GET = 0x43
 
static const uint8_t MP3_CMD_EQ_GET = 0x44
 
static const uint8_t MP3_CMD_LOOP_GET = 0x45
 
static const uint8_t MP3_CMD_VER_GET = 0x46
 
static const uint8_t MP3_CMD_COUNT_SD = 0x47
 
static const uint8_t MP3_CMD_COUNT_MEM = 0x49
 
static const uint8_t MP3_CMD_COUNT_FOLDERS = 0x53
 
static const uint8_t MP3_CMD_CURRENT_FILE_IDX_SD = 0x4B
 
static const uint8_t MP3_CMD_CURRENT_FILE_IDX_MEM = 0x4D
 
static const uint8_t MP3_CMD_CURRENT_FILE_POS_SEC = 0x50
 
static const uint8_t MP3_CMD_CURRENT_FILE_LEN_SEC = 0x51
 
static const uint8_t MP3_CMD_CURRENT_FILE_NAME = 0x52
 

Constructor & Destructor Documentation

◆ JQ6500_Serial()

JQ6500_Serial::JQ6500_Serial ( Stream *  dev)
inline

Create JQ6500 object.

You can use any Serial libraries that implement a Stream object, for example:

JQ6500_Serial mp3(Serial);

For a 5v Arduino:

  • TX on JQ6500 connects to D8 on the Arduino
  • RX on JQ6500 connects to one end of a 1k resistor, other end of resistor connects to D9 on the Arduino

For a 3v3 Arduino:

  • TX on JQ6500 connects to D8 on the Arduino
  • RX on JQ6500 connects to D9 on the Arduino

Of course, power and ground are also required, VCC on JQ6500 is 5v tolerant (but RX isn't totally, hence the resistor above).

And then you can use in your setup():

mp3.begin(9600)
mp3.reset();

and all the other commands :-)

Member Function Documentation

◆ countFiles()

unsigned int JQ6500_Serial::countFiles ( byte  source)

Count the number of files on the specified media.

Parameters
sourceOne of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
Returns
Number of files present on that media.

◆ countFolders()

unsigned int JQ6500_Serial::countFolders ( byte  source)

Count the number of folders on the specified media.

Note that only SD Card can have folders.

Parameters
sourceOne of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
Returns
Number of folders present on that media.

◆ currentFileIndexNumber()

unsigned int JQ6500_Serial::currentFileIndexNumber ( byte  source)

For the currently playing (or paused, or file that would be played next if stopped) file, return the file's (FAT table) index number.

This number can be used with playFileByIndexNumber();

Parameters
sourceOne of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
Returns
Number of file.

◆ currentFileLengthInSeconds()

unsigned int JQ6500_Serial::currentFileLengthInSeconds ( )

For the currently playing or paused file, return the total length of the file in seconds.

Returns
Length of audio file in seconds.

◆ currentFileName()

void JQ6500_Serial::currentFileName ( char *  buffer,
unsigned int  bufferLength 
)

Get the name of the "current" file on the SD Card.

The current file is the one that is playing, paused, or if stopped then could be next to play or last played, uncertain.

It would be best to only consult this when playing or paused and you know that the SD Card is the active source.

Unfortunately there is no way to query the device to find out which media is the active source (at least not that I know of).

◆ currentFilePositionInSeconds()

unsigned int JQ6500_Serial::currentFilePositionInSeconds ( )

For the currently playing or paused file, return the current position in seconds.

Returns
Number of seconds into the file currently played.

◆ getEqualizer()

byte JQ6500_Serial::getEqualizer ( )

Get the equalizer mode.

Returns
One of the following,
  • MP3_EQ_NORMAL
  • MP3_EQ_POP
  • MP3_EQ_ROCK
  • MP3_EQ_JAZZ
  • MP3_EQ_CLASSIC
  • MP3_EQ_BASS

◆ getLoopMode()

byte JQ6500_Serial::getLoopMode ( )

Get loop mode.

Returns
One of the following,
  • MP3_LOOP_ALL - Loop through all files.
  • MP3_LOOP_FOLDER - Loop through all files in the same folder (SD Card only)
  • MP3_LOOP_ONE - Loop one file.
  • MP3_LOOP_RAM - Loop one file (uncertain how it is different to the previous!)
  • MP3_LOOP_NONE - No loop, just play one file and then stop. (aka MP3_LOOP_ONE_STOP)

◆ getStatus()

byte JQ6500_Serial::getStatus ( )

Get the status from the device.

CAUTION! This is somewhat unreliable for the following reasons...

  1. When playing from the on board memory (MP3_SRC_BUILTIN), STOPPED sems to never be returned, only PLAYING and PAUSED
  2. Sometimes PAUSED is returned when it is PLAYING, to try and catch this getStatus() actually queries the module several times to ensure that it is really sure about what it tells us.
Returns
One of MP3_STATUS_PAUSED, MP3_STATUS_PLAYING and MP3_STATUS_STOPPED

◆ getVolume()

byte JQ6500_Serial::getVolume ( )

Get the current volume level.

Returns
Value between 0 and 30

◆ pause()

void JQ6500_Serial::pause ( )

Pause the current file.

To unpause, use play(), to unpause and go back to beginning of track use restart()

◆ playFileByIndexNumber()

void JQ6500_Serial::playFileByIndexNumber ( unsigned int  fileNumber)

Play a specific file based on it's (FAT table) index number.

Note that the index number has nothing to do with the file name (except if you uploaded/copied them to the media in order of file name).

To sort your SD Card FAT table, search for a FAT sorting utility for your operating system of choice.

◆ playFileNumberInFolderNumber()

void JQ6500_Serial::playFileNumberInFolderNumber ( unsigned int  folderNumber,
unsigned int  fileNumber 
)

Play a specific file in a specific folder based on the name of those folder and file.

Only applies to SD Card.

To use this function, folders must be named from 00 to 99, and the files in those folders must be named from 000.mp3 to 999.mp3

So to play the file on the SD Card "/03/006.mp3" use mp3.playFileNumberInFolderNumber(3, 6);

◆ reset()

void JQ6500_Serial::reset ( )

Reset the device (softly).

It may be necessary in practice to actually power-cycle the device as sometimes it can get a bit confused, especially if changing SD Cards on-the-fly which really doesn't work too well.

So if designing a PCB/circuit including JQ6500 modules it might be worth while to include such ability (ie, power the device through a MOSFET which you can turn on/off at will).

◆ restart()

void JQ6500_Serial::restart ( )

Restart the current (possibly paused) track from the beginning.

Note that this is not an actual command the JQ6500 knows what we do is mute, advance to the next track, pause, unmute, and go back to the previous track (which will cause it to start playing.

That said, it appears to work just fine.

◆ sendCommand()

void JQ6500_Serial::sendCommand ( byte  command,
byte  arg1,
byte  arg2,
char *  responseBuffer,
unsigned int  bufferLength 
)
protected

Send a command to the JQ6500 module,.

Parameters
commandByte value of to send as from the datasheet.
arg1First (if any) argument byte
arg2Second (if any) argument byte
responseBufferBuffer to store a single line of response, if NULL, no response is read.
buffLengthLength of response buffer including NULL terminator.

◆ sendCommandWithUnsignedIntResponse()

unsigned int JQ6500_Serial::sendCommandWithUnsignedIntResponse ( byte  command)
protected

Send a command to the JQ6500 module, and get a response.

For the query commands, the JQ6500 generally sends an integer response (over the UART as 4 hexadecimal digits).

Parameters
commandByte value of to send as from the datasheet.
Returns
Response from module.

◆ setEqualizer()

void JQ6500_Serial::setEqualizer ( byte  equalizerMode)

Set the equalizer to one of 6 preset modes.

Parameters
equalizerModeOne of the following,
  • MP3_EQ_NORMAL
  • MP3_EQ_POP
  • MP3_EQ_ROCK
  • MP3_EQ_JAZZ
  • MP3_EQ_CLASSIC
  • MP3_EQ_BASS

◆ setLoopMode()

void JQ6500_Serial::setLoopMode ( byte  loopMode)

Set the looping mode.

Parameters
loopModeOne of the following,
  • MP3_LOOP_ALL - Loop through all files.
  • MP3_LOOP_FOLDER - Loop through all files in the same folder (SD Card only)
  • MP3_LOOP_ONE - Loop one file.
  • MP3_LOOP_RAM - Loop one file (uncertain how it is different to the previous!)
  • MP3_LOOP_NONE - No loop, just play one file and then stop. (aka MP3_LOOP_ONE_STOP)

◆ setSource()

void JQ6500_Serial::setSource ( byte  source)

Set the source to read mp3 data from.

Parameters
sourceOne of the following,
  • MP3_SRC_BUILTIN - Files read from the on-board flash memory
  • MP3_SRC_SDCARD - Files read from the SD Card (JQ6500-28P only)

◆ setVolume()

void JQ6500_Serial::setVolume ( byte  volumeFrom0To30)

Set the volume to a specific level (0 to 30).

Parameters
volumeFrom0To30Level of volume to set from 0 to 30

◆ sleep()

void JQ6500_Serial::sleep ( )

Put the device to sleep.

Not recommanded if you are using SD Card as for some reason it appears to cause the SD Card to not be recognised again until the device is totally powered off and on again :-/


The documentation for this class was generated from the following files: