How to make Mp3 Player
Today quote: “My life is my message” – Mahatma Ganhi
Two weeks ago, I posted How to make Mp3 Player with DFPlayer. Today I posted same topics with different module which is named JQ6500-16p. JQ6500-16P has an onboard 16Mbit (2 MMegaByte Flash memory. Using Windows operating system you can upload MP3 very easily. Software is embeded with module so that, don’t need download any software
JQ6500-16p
Bellow images show Pinmap of the module.
PIN | Function |
K1 | Hotkey to play 1st File |
K2 | Hotkey to play 2nd File |
K3 | Hotkey to play 3rd File |
K4 | Hotkey to play 4th File |
K5 | Hotkey to play 5th File |
NXT/VOL+ | Press to play next file; Hold down to increase volume. |
PRV/VOL- | Press to play previous file; Hold down to decrease volume. |
PL/PAUSE | Pauses or Resumes the currently playing file. |
SRC | Changes the file source, from on board memory to the SD Card (28p model only). Note that the source defaults to the SD Card if it is inserted, if not it will fall-back to the on board memory. |
You can check capabilities of DFPlayer with this website.
You can control the module with K1-4 and ADKey pins. Bellow images shows the how to control with ADKey pins.
Embedded Software
When you plug USB to computer. Computer sees module like CD.
When you opened it. Software is open. Software language is Chinese but using of software is very easy. Software have two tab first of them is upload selected mp3. Second is selecting files.
Bellow figures how to upload works.
Work with Arduino
Also you can control with Arduino using TX/RX pins. You can download library from here
To use this library with a 5v Arduino, connect as follows.
JQ6500 Module | Arduino |
---|---|
RX | through a 1K Resistor then to pin 9 |
TX | pin 8 |
GND (any of) | GND |
VCC (any of) | VCC |
To use this library with a 3v3 Arduino, connect as follows…
JQ6500 Module | Arduino |
---|---|
RX | pin 9 |
TX | pin 8 |
GND (any of) | GND |
VCC (any of) | VCC |
You can use pins other than 9 and 8 if you wish, simply set them in your code.
Full Demo Code is bellow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
#include <Arduino.h> #include <SoftwareSerial.h> #include <JQ6500_Serial.h> // Create the mp3 module object, // Arduino Pin 8 is connected to TX of the JQ6500 // Arduino Pin 9 is connected to one end of a 1k resistor, // the other end of the 1k resistor is connected to RX of the JQ6500 // If your Arduino is 3v3 powered, you can omit the 1k series resistor JQ6500_Serial mp3(8,9); void setup() { // put your setup code here, to run once: Serial.begin(9600); mp3.begin(9600); mp3.reset(); statusAndHelpOutput(); } void loop() { byte b; if(Serial.available()) { b = Serial.read(); switch(b) { case 'p': Serial.println("Play"); mp3.play(); return; case 'r': Serial.println("Restart"); mp3.restart(); return; case ' ': Serial.println("Pause"); mp3.pause(); return; case '>': Serial.println("Next"); mp3.next(); return; case '<': Serial.println("Prev"); mp3.prev(); return; case ']': Serial.println("Next Folder"); mp3.nextFolder(); return; case '[': Serial.println("Prev Folder"); mp3.prevFolder(); return; case '+': Serial.println("Vol +"); mp3.volumeUp(); return; case '-': Serial.println("Vol -"); mp3.volumeDn(); return; case 'm': Serial.println("Vol 0"); mp3.setVolume(0); return; case 'v': { char volBuff[10]; memset(volBuff, 0, sizeof(volBuff)); Serial.readBytesUntil('\n',volBuff, sizeof(volBuff)-1); mp3.setVolume(max(0,min(30, atoi(volBuff)))); Serial.print("Vol "); Serial.println(max(0,min(30, atoi(volBuff)))); } return; case 'e': { do { while(!Serial.available()); // Wait b = Serial.read(); if(b != ' ') break; // Allow "e N" or "eN" etc... } while(1); Serial.print("Equalizer "); switch(b) { case 'N': Serial.println("Normal"); mp3.setEqualizer(MP3_EQ_NORMAL); break; case 'P': Serial.println("Pop"); mp3.setEqualizer(MP3_EQ_POP); break; case 'R': Serial.println("Rock"); mp3.setEqualizer(MP3_EQ_ROCK); break; case 'J': Serial.println("Jazz"); mp3.setEqualizer(MP3_EQ_JAZZ); break; case 'C': Serial.println("Classic"); mp3.setEqualizer(MP3_EQ_CLASSIC); break; case 'B': Serial.println("Bass"); mp3.setEqualizer(MP3_EQ_BASS); break; } } return; case 'l': { do { while(!Serial.available()); // Wait b = Serial.read(); if(b != ' ') break; // Allow "e N" or "eN" etc... } while(1); Serial.print("Loop "); switch(b) { case 'A': Serial.println("All"); mp3.setLoopMode(MP3_LOOP_ALL); break; // Plays the tracks one after another and repeats case 'F': Serial.println("Folder"); mp3.setLoopMode(MP3_LOOP_FOLDER); break; // Loop within folder case 'O': Serial.println("One (repeat playing same file)"); mp3.setLoopMode(MP3_LOOP_ONE); break; // | These seem to do the same, repeat the same track over and over case 'R': Serial.println("??? - Don't know what it means exactly, in the datasheet it is \"RAM\""); mp3.setLoopMode(MP3_LOOP_RAM); break; //- case 'N': case 'S': Serial.println("None (play file and stop)"); mp3.setLoopMode(MP3_LOOP_ONE_STOP); break; // Default, plays track and stops } } return; case 's': { do { while(!Serial.available()); // Wait b = Serial.read(); if(b != ' ') break; // Allow "e N" or "eN" etc... } while(1); Serial.print("Source "); switch(b) { case 'S': Serial.println("SD Card (if available)."); mp3.setSource(MP3_SRC_SDCARD); break; case 'B': Serial.println("on board memory.");mp3.setSource(MP3_SRC_BUILTIN); break; } } return; case 'f': { char fnumBuff[10]; memset(fnumBuff, 0, sizeof(fnumBuff)); Serial.readBytesUntil('\n',fnumBuff, sizeof(fnumBuff)-1); unsigned int fnum = strtoul(fnumBuff, NULL, 10); Serial.println(); Serial.print("Play file #"); Serial.print(fnum); Serial.println(F(" (if it exists).")); mp3.playFileByIndexNumber(fnum); // 48 == ord('0') return; } return; case 'F': { char fnumBuff[10]; memset(fnumBuff, 0, sizeof(fnumBuff)); Serial.readBytesUntil('/',fnumBuff, sizeof(fnumBuff)-1); unsigned int folnum = strtoul(fnumBuff, NULL, 10); memset(fnumBuff, 0, sizeof(fnumBuff)); Serial.readBytesUntil('\n',fnumBuff, sizeof(fnumBuff)-1); unsigned int fnum = strtoul(fnumBuff, NULL, 10); fnum = max(1,min(fnum, 999)); folnum = max(1,min(folnum, 99)); Serial.print("Play "); if(folnum < 10) Serial.print('0'); Serial.print(folnum); Serial.print('/'); if(fnum < 10) Serial.print("00"); else if(fnum < 10) Serial.print('0'); Serial.print(fnum); Serial.println(".mp3 (if it exists)."); mp3.playFileNumberInFolderNumber(folnum, fnum); // 48 == ord('0') } return; case '?': statusAndHelpOutput(); return; case 'S': Serial.println("Sleep"); mp3.sleep(); return; case 'z': Serial.println("Reset"); mp3.reset(); return; } } static unsigned long m = millis(); if(millis() > 1000 && m < (millis() - 1000)) { if((mp3.getStatus() == MP3_STATUS_PLAYING)) { Serial.print(F("Playing, Current Position: ")); Serial.print(mp3.currentFilePositionInSeconds()); Serial.print(F("s / ")); Serial.print(mp3.currentFileLengthInSeconds()); Serial.println('s'); } m = millis(); } } void statusAndHelpOutput() { Serial.println(); Serial.println(F("JQ6500 MP3 Player Demo")); Serial.println(F("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")); Serial.print(F("Status : ")); switch(mp3.getStatus()) { case MP3_STATUS_STOPPED: Serial.println(F("Stopped")); break; case MP3_STATUS_PLAYING: Serial.println(F("Playing")); break; case MP3_STATUS_PAUSED: Serial.println(F("Paused")); break; } Serial.print(F("Volume (0-30) : ")); Serial.println(mp3.getVolume()); Serial.print(F("Equalizer : ")); switch(mp3.getEqualizer()) { case MP3_EQ_NORMAL: Serial.println(F("Normal")); break; case MP3_EQ_POP: Serial.println(F("Pop")); break; case MP3_EQ_ROCK: Serial.println(F("Rock")); break; case MP3_EQ_JAZZ: Serial.println(F("Jazz")); break; case MP3_EQ_CLASSIC: Serial.println(F("Classic")); break; case MP3_EQ_BASS: Serial.println(F("Bass")); break; } Serial.print(F("Loop Mode : ")); switch(mp3.getLoopMode()) { case MP3_LOOP_ALL: Serial.println(F("Play all tracks, then repeat.")); break; case MP3_LOOP_FOLDER: Serial.println(F("Play all tracks in folder, then repeat.")); break; case MP3_LOOP_ONE: Serial.println(F("Play one track then repeat (loop track).")); break; case MP3_LOOP_RAM: Serial.println(F("Unknown function exactly, seems to play one track then repeat?")); break; case MP3_LOOP_ONE_STOP: Serial.println(F("Play one track then stop.")); break; } Serial.println(); Serial.print(F("# of On Board Memory Files : ")); Serial.println(mp3.countFiles(MP3_SRC_BUILTIN)); Serial.print(F("\"Current\" On Board Memory File Index: ")); Serial.println(mp3.currentFileIndexNumber(MP3_SRC_BUILTIN)); Serial.println(); Serial.print(F("# of SD Card Files : ")); Serial.println(mp3.countFiles(MP3_SRC_SDCARD)); Serial.print(F("# of SD Card Folders : ")); Serial.println(mp3.countFolders(MP3_SRC_SDCARD)); Serial.print(F("\"Current\" SD Card File Index: ")); Serial.println(mp3.currentFileIndexNumber(MP3_SRC_SDCARD)); Serial.print(F("\"Current\" SD Card File Name : ")); char buff[120]; mp3.currentFileName(buff, sizeof(buff)); Serial.println(buff); Serial.println(); Serial.println(F("Controls (type in serial monitor and hit send): ")); Serial.println(F("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")); Serial.println(F("? Display this menu.\n")); Serial.println(F("p Play\t\t> Next\t\t< Prev\n[space] Pause\tr Restart from start of file\n] Next folder\t[ Prev folder\n")); Serial.println(F("f[1-65534] Play file by (FAT table) index number\nF[01-99]/[001-999].mp3 Play [001-999].mp3 in folder [01-99]\n")); Serial.println(F("+ Vol up\t- Vol down\tm Mute\nv[0-30] Set volume\n\ne[N/P/R/J/C/B] Equalizer (N)ormal, (P)op, (R)ock, (J)azz, (C)lassic, (B)ass\nl[A/F/O/R/N] Loop (A)ll, (F)older, (O)ne, (R)???, (N)o Loop\ns[S/B] Switch to (S)D Card/(B)uilt In Memory\n\n")); } |