JQ6500_Serial Class Reference

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)

## Constructor & Destructor Documentation

JQ6500_Serial::JQ6500_Serial | ( | short | rxPin,
|  | short | txPin
| ) |  |

inline

Create JQ6500 object.

Example, create global instance:

    JQ6500_Serial mp3(8,9);

## 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

unsigned int JQ6500_Serial::countFiles | ( | byte | source | ) |

Count the number of files on the specified media.

Parameters

  source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD

Returns
  Number of files present on that media.

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

  source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD

Returns
  Number of folders present on that media.

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

  source | One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD

Returns
  Number of file.

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.

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.

Returns
  Number of seconds into the file currently played.

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

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)

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

byte JQ6500_Serial::getVolume | ( |  | ) |

Get the current volume level.

Returns
  Value between 0 and 30

void JQ6500_Serial::pause | ( |  | ) |

Pause the current file.

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

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.

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

protected

Send a command to the JQ6500 module,.

Parameters

  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.

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

  command | Byte value of to send as from the datasheet.

Returns
  Response from module.

void JQ6500_Serial::setEqualizer | ( | byte | equalizerMode | ) |

Set the equalizer to one of 6 preset modes.

Parameters

  equalizerMode | One of the following,

- MP3_EQ_NORMAL
- MP3_EQ_POP
- MP3_EQ_ROCK
- MP3_EQ_JAZZ
- MP3_EQ_CLASSIC
- MP3_EQ_BASS

void JQ6500_Serial::setLoopMode | ( | byte | loopMode | ) |

Set the looping mode.

Parameters

  loopMode | 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)

void JQ6500_Serial::setSource | ( | byte | source | ) |

Set the source to read mp3 data from.

Parameters

  source | One 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)

void JQ6500_Serial::setVolume | ( | byte | volumeFrom0To30 | ) |

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

Parameters

  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).

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

- /bigdrive/home/boffin/sketchbook/libraries/JQ6500_Serial/JQ6500_Serial.h
- /bigdrive/home/boffin/sketchbook/libraries/JQ6500_Serial/JQ6500_Serial.cpp