JQ6500 MP3 Player Arduino Library
A simple library to control a JQ6500 MP3 Player Module from an Arduino.
|
Inherits SoftwareSerial.
Public Member Functions | |
JQ6500_Serial (short rxPin, short txPin) | |
Create JQ6500 object. More... | |
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). More... | |
void | volumeDn () |
Decrease the volume by 1 (volume ranges 0 to 30). More... | |
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 () |
size_t | readBytesUntilAndIncluding (char terminator, char *buffer, size_t length, byte maxOneLineOnly=0) |
int | waitUntilAvailable (unsigned long maxWaitTime=1000) |
|
inline |
Create JQ6500 object.
Example, create global instance:
JQ6500_Serial mp3(8,9);
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 :-)
unsigned int JQ6500_Serial::countFiles | ( | byte | source | ) |
Count the number of files on the specified media.
source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD |
unsigned int JQ6500_Serial::countFolders | ( | byte | source | ) |
Count the number of folders on the specified media.
Note that only SD Card can have folders.
source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD |
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();
source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD |
unsigned int JQ6500_Serial::currentFileLengthInSeconds | ( | ) |
For the currently playing or paused file, return the total length of the file in seconds.
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).
unsigned int JQ6500_Serial::currentFilePositionInSeconds | ( | ) |
For the currently playing or paused file, return the current position in seconds.
byte JQ6500_Serial::getEqualizer | ( | ) |
Get the equalizer mode.
byte JQ6500_Serial::getLoopMode | ( | ) |
Get loop mode.
byte JQ6500_Serial::getStatus | ( | ) |
Get the status from the device.
CAUTION! This is somewhat unreliable for the following reasons...
byte JQ6500_Serial::getVolume | ( | ) |
Get the current volume level.
void JQ6500_Serial::pause | ( | ) |
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.
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);
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).
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.
|
protected |
Send a command to the JQ6500 module,.
command | Byte value of to send as from the datasheet. |
arg1 | First (if any) argument byte |
arg2 | Second (if any) argument byte |
responseBuffer | Buffer to store a single line of response, if NULL, no response is read. |
buffLength | Length of response buffer including NULL terminator. |
|
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).
command | Byte value of to send as from the datasheet. |
void JQ6500_Serial::setEqualizer | ( | byte | equalizerMode | ) |
Set the equalizer to one of 6 preset modes.
equalizerMode | One of the following, |
void JQ6500_Serial::setLoopMode | ( | byte | loopMode | ) |
Set the looping mode.
loopMode | One of the following, |
void JQ6500_Serial::setSource | ( | byte | source | ) |
Set the source to read mp3 data from.
source | One of the following, |
void JQ6500_Serial::setVolume | ( | byte | volumeFrom0To30 | ) |
Set the volume to a specific level (0 to 30).
volumeFrom0To30 | Level of volume to set from 0 to 30 |
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 :-/
void JQ6500_Serial::volumeDn | ( | ) |
Decrease the volume by 1 (volume ranges 0 to 30).
void JQ6500_Serial::volumeUp | ( | ) |
Increase the volume by 1 (volume ranges 0 to 30).