JQ6500 MP3 Player Arduino Library
A simple library to control a JQ6500 MP3 Player Module from an Arduino.
JQ6500_Serial.h
Go to the documentation of this file.
1 
29 // Please note, the Arduino IDE is a bit retarded, if the below define has an
30 // underscore other than _h, it goes mental. Wish it wouldn't mess
31 // wif ma files!
32 #ifndef JQ6500Serial_h
33 #define JQ6500Serial_h
34 
35 #include <SoftwareSerial.h>
36 
37 #define MP3_EQ_NORMAL 0
38 #define MP3_EQ_POP 1
39 #define MP3_EQ_ROCK 2
40 #define MP3_EQ_JAZZ 3
41 #define MP3_EQ_CLASSIC 4
42 #define MP3_EQ_BASS 5
43 
44 #define MP3_SRC_SDCARD 1
45 #define MP3_SRC_BUILTIN 4
46 
47 // Looping options, ALL, FOLDER, ONE and ONE_STOP are the
48 // only ones that appear to do much interesting
49 // ALL plays all the tracks in a repeating loop
50 // FOLDER plays all the tracks in the same folder in a repeating loop
51 // ONE plays the same track repeating
52 // ONE_STOP does not loop, plays the track and stops
53 // RAM seems to play one track and someties disables the ability to
54 // move to next/previous track, really weird.
55 
56 #define MP3_LOOP_ALL 0
57 #define MP3_LOOP_FOLDER 1
58 #define MP3_LOOP_ONE 2
59 #define MP3_LOOP_RAM 3
60 #define MP3_LOOP_ONE_STOP 4
61 #define MP3_LOOP_NONE 4
62 
63 #define MP3_STATUS_STOPPED 0
64 #define MP3_STATUS_PLAYING 1
65 #define MP3_STATUS_PAUSED 2
66 
67 // The response from a status query we get is for some reason
68 // a bit... iffy, most of the time it is reliable, but sometimes
69 // instead of a playing (1) response, we get a paused (2) response
70 // even though it is playing. Stopped responses seem reliable.
71 // So to work around this when getStatus() is called we actually
72 // request the status this many times and only if one of them is STOPPED
73 // or they are all in agreement that it is playing or paused then
74 // we return that status. If some of them differ, we do another set
75 // of tests etc...
76 #define MP3_STATUS_CHECKS_IN_AGREEMENT 4
77 
78 #define MP3_DEBUG 0
79 
80 class JQ6500_Serial : public SoftwareSerial
81 {
82 
83  public:
84 
112  JQ6500_Serial(short rxPin, short txPin) : SoftwareSerial(rxPin,txPin) { };
113 
117  void play();
118 
131  void restart();
132 
137  void pause();
138 
142  void next();
143 
147  void prev();
148 
152  void nextFolder();
153 
157  void prevFolder();
158 
167  void playFileByIndexNumber(unsigned int fileNumber);
168 
180  void playFileNumberInFolderNumber(unsigned int folderNumber, unsigned int fileNumber);
181 
184  void volumeUp();
185 
188  void volumeDn();
189 
195  void setVolume(byte volumeFrom0To30);
196 
210  void setEqualizer(byte equalizerMode); // EQ_NORMAL to EQ_BASS
211 
223  void setLoopMode(byte loopMode);
224 
233  void setSource(byte source); // SRC_BUILTIN or SRC_SDCARD
234 
243  void sleep();
244 
257  void reset();
258 
259  // Status querying commands
273  byte getStatus();
274 
280  byte getVolume();
281 
294  byte getEqualizer();
295 
307  byte getLoopMode();
308 
316  unsigned int countFiles(byte source);
317 
326  unsigned int countFolders(byte source);
327 
337  unsigned int currentFileIndexNumber(byte source);
338 
345  unsigned int currentFilePositionInSeconds();
346 
353  unsigned int currentFileLengthInSeconds();
354 
368  void currentFileName(char *buffer, unsigned int bufferLength);
369 
370 
371  protected:
372 
381  void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength);
382 
383  // Just some different versions of that for ease of use
384  void sendCommand(byte command);
385  void sendCommand(byte command, byte arg1);
386  void sendCommand(byte command, byte arg1, byte arg2);
387 
397  unsigned int sendCommandWithUnsignedIntResponse(byte command);
398 
399  // This seems not that useful since there only seems to be a version 1 anway :/
400  unsigned int getVersion();
401 
402  size_t readBytesUntilAndIncluding(char terminator, char *buffer, size_t length, byte maxOneLineOnly = 0);
403 
404  int waitUntilAvailable(unsigned long maxWaitTime = 1000);
405 
406 };
407 
408 #endif
void nextFolder()
Play the next folder.
Definition: JQ6500_Serial.cpp:69
unsigned int sendCommandWithUnsignedIntResponse(byte command)
Send a command to the JQ6500 module, and get a response.
Definition: JQ6500_Serial.cpp:198
JQ6500_Serial(short rxPin, short txPin)
Create JQ6500 object.
Definition: JQ6500_Serial.h:112
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.
Definition: JQ6500_Serial.cpp:79
void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength)
Send a command to the JQ6500 module,.
Definition: JQ6500_Serial.cpp:220
void setVolume(byte volumeFrom0To30)
Set the volume to a specific level (0 to 30).
Definition: JQ6500_Serial.cpp:94
void pause()
Pause the current file.
Definition: JQ6500_Serial.cpp:49
void reset()
Reset the device (softly).
Definition: JQ6500_Serial.cpp:119
void volumeDn()
Decrease the volume by 1 (volume ranges 0 to 30).
Definition: JQ6500_Serial.cpp:89
unsigned int currentFileLengthInSeconds()
For the currently playing or paused file, return the total length of the file in seconds.
Definition: JQ6500_Serial.cpp:189
unsigned int countFolders(byte source)
Count the number of folders on the specified media.
Definition: JQ6500_Serial.cpp:164
void play()
Start playing the current file.
Definition: JQ6500_Serial.cpp:34
byte getLoopMode()
Get loop mode.
Definition: JQ6500_Serial.cpp:147
void setEqualizer(byte equalizerMode)
Set the equalizer to one of 6 preset modes.
Definition: JQ6500_Serial.cpp:99
void restart()
Restart the current (possibly paused) track from the beginning.
Definition: JQ6500_Serial.cpp:39
byte getEqualizer()
Get the equalizer mode.
Definition: JQ6500_Serial.cpp:146
void next()
Play the next file.
Definition: JQ6500_Serial.cpp:54
void currentFileName(char *buffer, unsigned int bufferLength)
Get the name of the "current" file on the SD Card.
Definition: JQ6500_Serial.cpp:191
byte getVolume()
Get the current volume level.
Definition: JQ6500_Serial.cpp:145
void volumeUp()
Increase the volume by 1 (volume ranges 0 to 30).
Definition: JQ6500_Serial.cpp:84
unsigned int currentFileIndexNumber(byte source)
For the currently playing (or paused, or file that would be played next if stopped) file...
Definition: JQ6500_Serial.cpp:174
unsigned int currentFilePositionInSeconds()
For the currently playing or paused file, return the current position in seconds. ...
Definition: JQ6500_Serial.cpp:188
unsigned int countFiles(byte source)
Count the number of files on the specified media.
Definition: JQ6500_Serial.cpp:150
Definition: JQ6500_Serial.h:80
void setLoopMode(byte loopMode)
Set the looping mode.
Definition: JQ6500_Serial.cpp:104
void prev()
Play the previous file.
Definition: JQ6500_Serial.cpp:59
byte getStatus()
Get the status from the device.
Definition: JQ6500_Serial.cpp:126
void prevFolder()
Play the previous folder.
Definition: JQ6500_Serial.cpp:74
void setSource(byte source)
Set the source to read mp3 data from.
Definition: JQ6500_Serial.cpp:109
void playFileByIndexNumber(unsigned int fileNumber)
Play a specific file based on it's (FAT table) index number.
Definition: JQ6500_Serial.cpp:64
void sleep()
Put the device to sleep.
Definition: JQ6500_Serial.cpp:114