feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

View File

@@ -0,0 +1,257 @@
/**
*/
#include "GD5800_Serial.h"
void GD5800_Serial::play()
{
this->sendCommand(0x01);
}
void GD5800_Serial::restart()
{
byte oldVolume = this->getVolume();
this->setVolume(0);
this->next();
this->pause();
this->setVolume(oldVolume);
this->prev();
}
void GD5800_Serial::pause()
{
this->sendCommand(0x02);
}
void GD5800_Serial::next()
{
this->sendCommand(0x03);
}
void GD5800_Serial::prev()
{
this->sendCommand(0x04);
}
void GD5800_Serial::fastReverse()
{
this->sendCommand(0x0B);
}
void GD5800_Serial::fastForward()
{
this->sendCommand(0x0A);
}
void GD5800_Serial::playFileByIndexNumber(unsigned int fileNumber)
{
this->sendCommand(0x41, (fileNumber>>8) & 0xFF, fileNumber & (byte)0xFF);
}
void GD5800_Serial::volumeUp()
{
this->sendCommand(0x05);
}
void GD5800_Serial::volumeDn()
{
this->sendCommand(0x06);
}
void GD5800_Serial::setVolume(byte volumeFrom0To30)
{
this->sendCommand(0x31, volumeFrom0To30);
}
void GD5800_Serial::setEqualizer(byte equalizerMode)
{
this->sendCommand(0x32, equalizerMode);
}
void GD5800_Serial::setLoopMode(byte loopMode)
{
this->sendCommand(0x33, loopMode);
}
byte GD5800_Serial::getStatus()
{
byte statTotal = 0;
byte stat = 0;
do
{
statTotal = 0;
for(byte x = 0; x < MP3_STATUS_CHECKS_IN_AGREEMENT; x++)
{
stat = this->sendCommandWithUnsignedIntResponse(0x42);
if(stat == 0) return 0; // STOP is fairly reliable
statTotal += stat;
}
} while (statTotal != 1 * MP3_STATUS_CHECKS_IN_AGREEMENT && statTotal != 2 * MP3_STATUS_CHECKS_IN_AGREEMENT);
return statTotal / MP3_STATUS_CHECKS_IN_AGREEMENT;
}
byte GD5800_Serial::getVolume() { return this->sendCommandWithUnsignedIntResponse(0x11); }
byte GD5800_Serial::getEqualizer() { return this->sendCommandWithUnsignedIntResponse(0x44); }
byte GD5800_Serial::getLoopMode() { return this->sendCommandWithUnsignedIntResponse(0x13); }
unsigned int GD5800_Serial::countFiles()
{
return this->sendCommandWithUnsignedIntResponse(0x16);
}
unsigned int GD5800_Serial::currentFileIndexNumber()
{
return this->sendCommandWithUnsignedIntResponse(0x1A);
}
// Used for the status commands, they mostly return an 8 to 16 bit integer
// and take no arguments
unsigned int GD5800_Serial::sendCommandWithUnsignedIntResponse(byte command)
{
char buffer[5];
this->sendCommand(command, 0, 0, buffer, sizeof(buffer));
return (unsigned int) strtoul(buffer, NULL, 16);
}
void GD5800_Serial::sendCommand(byte command)
{
this->sendCommand(command, 0, 0, 0, 0);
}
void GD5800_Serial::sendCommand(byte command, byte arg1)
{
this->sendCommand(command, arg1, 0, 0, 0);
}
void GD5800_Serial::sendCommand(byte command, byte arg1, byte arg2)
{
this->sendCommand(command, arg1, arg2, 0, 0);
}
void GD5800_Serial::sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength)
{
// Command structure
// [7E][number bytes following including command and terminator][command byte][?arg1][?arg2][EF]
// Most commands do not have arguments
byte args = 0;
// These ones do
switch(command)
{
case 0x41: args = 2; break;//指定曲目
case 0x31: args = 1; break;//指定音量
case 0x32: args = 1; break;//指定EQ
case 0x09: args = 1; break;//指定设备
case 0x33: args = 1; break;//循环播放
default :args=1;break;
}
#if MP3_DEBUG
char buf[4];
Serial.println();
Serial.print("7E ");
itoa(2+args, buf, 16); Serial.print(buf); Serial.print(" "); memset(buf, 0, sizeof(buf));
itoa(command, buf, 16); Serial.print(buf); Serial.print(" "); memset(buf, 0, sizeof(buf));
if(args>=1) itoa(arg1, buf, 16); Serial.print(buf); Serial.print(" "); memset(buf, 0, sizeof(buf));
if(args>=2) itoa(arg2, buf, 16); Serial.print(buf); Serial.print(" "); memset(buf, 0, sizeof(buf));
Serial.print("EF");
#endif
// The device appears to send some sort of status information (namely "STOP" when it stops playing)
// just discard this right before we send the command
while(this->waitUntilAvailable(10)) this->read();
this->write((byte)0x7E);
this->write(2+args);
this->write(command);
if(args>=1) this->write(arg1);
if(args==2) this->write(arg2);
this->write((byte)0xEF);
unsigned int i = 0;
char j = 0;
if(responseBuffer && bufferLength)
{
memset(responseBuffer, 0, bufferLength);
}
// Allow some time for the device to process what we did and
// respond, up to 1 second, but typically only a few ms.
this->waitUntilAvailable(1000);
#if MP3_DEBUG
Serial.print(" ==> [");
#endif
while(this->waitUntilAvailable(150))
{
j = (char)this->read();
#if MP3_DEBUG
Serial.print(j);
#endif
if(responseBuffer && (i<(bufferLength-1)))
{
responseBuffer[i++] = j;
}
}
#if MP3_DEBUG
Serial.print("]");
Serial.println();
#endif
}
// as readBytes with terminator character
// terminates if length characters have been read, timeout, or if the terminator character detected
// returns the number of characters placed in the buffer (0 means no valid data found)
size_t GD5800_Serial::readBytesUntilAndIncluding(char terminator, char *buffer, size_t length, byte maxOneLineOnly)
{
if (length < 1) return 0;
size_t index = 0;
while (index < length) {
int c = timedRead();
if (c < 0) break;
*buffer++ = (char)c;
index++;
if(c == terminator) break;
if(maxOneLineOnly && ( c == '\n') ) break;
}
return index; // return number of characters, not including null terminator
}
// Waits until data becomes available, or a timeout occurs
int GD5800_Serial::waitUntilAvailable(unsigned long maxWaitTime)
{
unsigned long startTime;
int c = 0;
startTime = millis();
do {
c = this->available();
if (c) break;
} while(millis() - startTime < maxWaitTime);
return c;
}

View File

@@ -0,0 +1,546 @@
/**
* Arduino Library for GD5800 MP3 Module
*
* Copyright (C) 2014 James Sleeman, <http://sparks.gogo.co.nz/GD5800/index.html>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author James Sleeman, http://sparks.gogo.co.nz/
* @license MIT License
* @file
*/
// Please note, the Arduino IDE is a bit retarded, if the below define has an
// underscore other than _h, it goes mental. Wish it wouldn't mess
// wif ma files!
#ifndef GD5800Serial_h
#define GD5800Serial_h
#include <Arduino.h>
#if defined __AVR__ || defined(ESP8266)
#include <SoftwareSerial.h>
#elif defined (ESP32)
#include "ESP32SoftwareSerial.h"
#endif
#define MP3_EQ_NORMAL 0
#define MP3_EQ_POP 1
#define MP3_EQ_ROCK 2
#define MP3_EQ_JAZZ 3
#define MP3_EQ_CLASSIC 4
#define MP3_EQ_BASS 5
// Looping options, ALL, FOLDER, ONE and ONE_STOP are the
// only ones that appear to do much interesting
// ALL plays all the tracks in a repeating loop
// FOLDER plays all the tracks in the same folder in a repeating loop
// ONE plays the same track repeating
// ONE_STOP does not loop, plays the track and stops
// RAM seems to play one track and someties disables the ability to
// move to next/previous track, really weird.
#define MP3_LOOP_ALL 0
#define MP3_LOOP_FOLDER 1
#define MP3_LOOP_ONE 2
#define MP3_LOOP_RAM 3
#define MP3_STATUS_STOPPED 0
#define MP3_STATUS_PLAYING 1
#define MP3_STATUS_PAUSED 2
#define MP3_STATUS_FF 3
#define MP3_STATUS_FR 4
// The response from a status query we get is for some reason
// a bit... iffy, most of the time it is reliable, but sometimes
// instead of a playing (1) response, we get a paused (2) response
// even though it is playing. Stopped responses seem reliable.
// So to work around this when getStatus() is called we actually
// request the status this many times and only if one of them is STOPPED
// or they are all in agreement that it is playing or paused then
// we return that status. If some of them differ, we do another set
// of tests etc...
#define MP3_STATUS_CHECKS_IN_AGREEMENT 4
#define MP3_DEBUG 0
#if defined __AVR__ || defined(ESP8266)
class GD5800_Serial : public SoftwareSerial
{
public:
/** Create GD5800 object.
*
* Example, create global instance:
*
* GD5800_Serial mp3(8,9);
*
* For a 5v Arduino:
* -----------------
* * TX on GD5800 connects to D8 on the Arduino
* * RX on GD5800 connects to one end of a 1k resistor,
* other end of resistor connects to D9 on the Arduino
*
* For a 3v3 Arduino:
* -----------------
* * TX on GD5800 connects to D8 on the Arduino
* * RX on GD5800 connects to D9 on the Arduino
*
* Of course, power and ground are also required, VCC on GD5800 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 :-)
*/
GD5800_Serial(short rxPin, short txPin) : SoftwareSerial(rxPin,txPin) { };
/** Start playing the current file.
*/
void play();
/** Restart the current (possibly paused) track from the
* beginning.
*
* Note that this is not an actual command the GD5800 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 restart();
/** Pause the current file. To unpause, use play(),
* to unpause and go back to beginning of track use restart()
*/
void pause();
/** Play the next file.
*/
void next();
/** Play the previous file.
*/
void prev();
/** fast Reverse.
*/
void fastReverse();
/** fastForward
*/
void fastForward();
void playFileByIndexNumber(unsigned int fileNumber);
/** Increase the volume by 1 (volume ranges 0 to 30). */
void volumeUp();
/** Decrease the volume by 1 (volume ranges 0 to 30). */
void volumeDn();
/** Set the volume to a specific level (0 to 30).
*
* @param volumeFrom0To30 Level of volume to set from 0 to 30
*/
void setVolume(byte volumeFrom0To30);
/** Set the equalizer to one of 6 preset modes.
*
* @param equalizerMode One of the following,
*
* * MP3_EQ_NORMAL
* * MP3_EQ_POP
* * MP3_EQ_ROCK
* * MP3_EQ_JAZZ
* * MP3_EQ_CLASSIC
* * MP3_EQ_BASS
*
*/
void setEqualizer(byte equalizerMode); // EQ_NORMAL to EQ_BASS
/** Set the looping mode.
*
* @param 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 setLoopMode(byte loopMode);
// Status querying commands
/** 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.
*
* @return One of MP3_STATUS_PAUSED, MP3_STATUS_PLAYING and MP3_STATUS_STOPPED
*/
byte getStatus();
/** Get the current volume level.
*
* @return Value between 0 and 30
*/
byte getVolume();
/** Get the equalizer mode.
*
* @return One of the following,
*
* * MP3_EQ_NORMAL
* * MP3_EQ_POP
* * MP3_EQ_ROCK
* * MP3_EQ_JAZZ
* * MP3_EQ_CLASSIC
* * MP3_EQ_BASS
*/
byte getEqualizer();
/** Get loop mode.
*
* @return 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 getLoopMode();
/** Count the number of files on the specified media.
*
* @param source One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
* @return Number of files present on that media.
*
*/
unsigned int countFiles();
/** 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();
*
* @param source One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
* @return Number of file.
*/
unsigned int currentFileIndexNumber();
protected:
/** Send a command to the GD5800 module,
* @param command Byte value of to send as from the datasheet.
* @param arg1 First (if any) argument byte
* @param arg2 Second (if any) argument byte
* @param responseBuffer Buffer to store a single line of response, if NULL, no response is read.
* @param buffLength Length of response buffer including NULL terminator.
*/
void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength);
// Just some different versions of that for ease of use
void sendCommand(byte command);
void sendCommand(byte command, byte arg1);
void sendCommand(byte command, byte arg1, byte arg2);
/** Send a command to the GD5800 module, and get a response.
*
* For the query commands, the GD5800 generally sends an integer response
* (over the UART as 4 hexadecimal digits).
*
* @param command Byte value of to send as from the datasheet.
* @return Response from module.
*/
unsigned int sendCommandWithUnsignedIntResponse(byte command);
// This seems not that useful since there only seems to be a version 1 anway :/
size_t readBytesUntilAndIncluding(char terminator, char *buffer, size_t length, byte maxOneLineOnly = 0);
int waitUntilAvailable(unsigned long maxWaitTime = 1000);
};
#elif defined ESP32
class GD5800_Serial : public Esp32SoftwareSerial
{
public:
/** Create GD5800 object.
*
* Example, create global instance:
*
* GD5800_Serial mp3(8,9);
*
* For a 5v Arduino:
* -----------------
* * TX on GD5800 connects to D8 on the Arduino
* * RX on GD5800 connects to one end of a 1k resistor,
* other end of resistor connects to D9 on the Arduino
*
* For a 3v3 Arduino:
* -----------------
* * TX on GD5800 connects to D8 on the Arduino
* * RX on GD5800 connects to D9 on the Arduino
*
* Of course, power and ground are also required, VCC on GD5800 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 :-)
*/
GD5800_Serial(short rxPin, short txPin) : Esp32SoftwareSerial(rxPin,txPin) { };
/** Start playing the current file.
*/
void play();
/** Restart the current (possibly paused) track from the
* beginning.
*
* Note that this is not an actual command the GD5800 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 restart();
/** Pause the current file. To unpause, use play(),
* to unpause and go back to beginning of track use restart()
*/
void pause();
/** Play the next file.
*/
void next();
/** Play the previous file.
*/
void prev();
/** fast Reverse.
*/
void fastReverse();
/** fastForward
*/
void fastForward();
void playFileByIndexNumber(unsigned int fileNumber);
/** Increase the volume by 1 (volume ranges 0 to 30). */
void volumeUp();
/** Decrease the volume by 1 (volume ranges 0 to 30). */
void volumeDn();
/** Set the volume to a specific level (0 to 30).
*
* @param volumeFrom0To30 Level of volume to set from 0 to 30
*/
void setVolume(byte volumeFrom0To30);
/** Set the equalizer to one of 6 preset modes.
*
* @param equalizerMode One of the following,
*
* * MP3_EQ_NORMAL
* * MP3_EQ_POP
* * MP3_EQ_ROCK
* * MP3_EQ_JAZZ
* * MP3_EQ_CLASSIC
* * MP3_EQ_BASS
*
*/
void setEqualizer(byte equalizerMode); // EQ_NORMAL to EQ_BASS
/** Set the looping mode.
*
* @param 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 setLoopMode(byte loopMode);
// Status querying commands
/** 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.
*
* @return One of MP3_STATUS_PAUSED, MP3_STATUS_PLAYING and MP3_STATUS_STOPPED
*/
byte getStatus();
/** Get the current volume level.
*
* @return Value between 0 and 30
*/
byte getVolume();
/** Get the equalizer mode.
*
* @return One of the following,
*
* * MP3_EQ_NORMAL
* * MP3_EQ_POP
* * MP3_EQ_ROCK
* * MP3_EQ_JAZZ
* * MP3_EQ_CLASSIC
* * MP3_EQ_BASS
*/
byte getEqualizer();
/** Get loop mode.
*
* @return 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 getLoopMode();
/** Count the number of files on the specified media.
*
* @param source One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
* @return Number of files present on that media.
*
*/
unsigned int countFiles();
/** 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();
*
* @param source One of MP3_SRC_BUILTIN and MP3_SRC_SDCARD
* @return Number of file.
*/
unsigned int currentFileIndexNumber();
protected:
/** Send a command to the GD5800 module,
* @param command Byte value of to send as from the datasheet.
* @param arg1 First (if any) argument byte
* @param arg2 Second (if any) argument byte
* @param responseBuffer Buffer to store a single line of response, if NULL, no response is read.
* @param buffLength Length of response buffer including NULL terminator.
*/
void sendCommand(byte command, byte arg1, byte arg2, char *responseBuffer, unsigned int bufferLength);
// Just some different versions of that for ease of use
void sendCommand(byte command);
void sendCommand(byte command, byte arg1);
void sendCommand(byte command, byte arg1, byte arg2);
/** Send a command to the GD5800 module, and get a response.
*
* For the query commands, the GD5800 generally sends an integer response
* (over the UART as 4 hexadecimal digits).
*
* @param command Byte value of to send as from the datasheet.
* @return Response from module.
*/
unsigned int sendCommandWithUnsignedIntResponse(byte command);
// This seems not that useful since there only seems to be a version 1 anway :/
size_t readBytesUntilAndIncluding(char terminator, char *buffer, size_t length, byte maxOneLineOnly = 0);
int waitUntilAvailable(unsigned long maxWaitTime = 1000);
};
#endif
#endif

View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 James Sleeman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,66 @@
GD5800_Serial
=======================
Simple to use Arduino library to interface to GD5800 (GD5800-28P, GD5800-16P) Mp3 Player Modules
For complete documentation about the GD5800 Mp3 Player Module, see:
http://sparks.gogo.co.nz/GD5800/index.html
For a library methods reference see:
http://sparks.gogo.co.nz/GD5800/doxygen/class_j_q6500___serial.html
For Linux Upload and Windows Upload Repair Tool (GD5800-16) see:
https://github.com/NikolaiRadke/GD5800-rescue-tool
Download, Install and Example
-----------------------------
* Download: http://sparks.gogo.co.nz/GD5800_Serial.zip
* Open the Arduino IDE (1.0.5)
* Select the menu item Sketch > Import Library > Add Library
* Choose to install the GD5800_Serial.zip file you downloaded
* Now you can choose File > Examples > GD5800_Serial > HelloWorld
Connecting To Your Arduino
--------------------------
<img src="http://sparks.gogo.co.nz/assets/_site_/images/GD5800/kq6500-16p.jpeg" align="right" title="GD5800-16p" alt="Pinout image of GD5800-16p MP3 Player Module For Arduino"/>
<img src="http://sparks.gogo.co.nz/assets/_site_/images/GD5800/GD5800-28.jpeg" align="right" title="GD5800-28p" alt="Pinout image of GD5800-28p MP3 Player Module For Arduino"/>
There are two varients of the GD5800 module as shown.
To use this library with a *5v Arduino*, connect as follows.
| GD5800 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...
| GD5800 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.
Power Demands
--------------------------
If using the on-board speaker driver, then naturally the power
demands are significant, and your USB power may not be sufficient
at more 1/3rd level of volume or so, the symptom is the audo
breaking up and potentially resetting when volume increases.
You should use either an external power source, an external amp, or a lower
volume if you experience this problem.
Usage
--------------------------
Open the HelloWorld example.

View File

@@ -0,0 +1,65 @@
/** GD5800 serial MP3 Player Arduino Library
Auther:hznupeter
website:
GD5800 串口MP3播放模块arduino 库
*/
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <GD5800_Serial.h>
GD5800_Serial mp3(8, 9); //rx,tx
void setup() {
mp3.begin(9600);
mp3.setVolume(20);//设置音量,0-30
mp3.setLoopMode(MP3_LOOP_ALL);//设置循环模式
//MP3_LOOP_ALL 全部循环
//MP3_LOOP_FOLDER 文件夹内循环
//MP3_LOOP_ONE 单曲循环
//MP3_LOOP_RAM 随机播放
mp3.play(); //播放
mp3.setEqualizer(MP3_EQ_NORMAL);//设置EQ
// MP3_EQ_NORMAL
//MP3_EQ_POP
// MP3_EQ_ROCK
// MP3_EQ_JAZZ
//MP3_EQ_CLASSIC
//MP3_EQ_BASS
}
//控制函数
//mp3.restart(); //重新播放
//mp3.pause(); //暂停
//mp3.playFileByIndexNumber(20);//选择播放曲目0-65535
//查询函数
// Serial.println(mp3.getStatus());//获取播放状态,返回值 MP3_STATUS_PAUSED, MP3_STATUS_PLAYING and MP3_STATUS_STOPPED
// Serial.println(mp3.getVolume());//获取音量值0-30
// Serial.println(mp3.getEqualizer());//获取当前EQ
// Serial.println(mp3.getLoopMode());//获取播放模式
// Serial.println(mp3.countFiles());//获取 U 盘总文件数
// Serial.println(mp3.currentFileIndexNumber());//查询 U 盘的当前曲目
void loop() {
if (!digitalRead(2))
{
mp3.prev(); //上一曲
}
else if (!digitalRead(3))
{
mp3.next(); //下一曲
}
else if (!digitalRead(4))
{
mp3.volumeUp();//音量加
}
else if (!digitalRead(5))
{
mp3.volumeDn();//音量减
}
}

View File

@@ -0,0 +1,9 @@
name=GD5800_MP3_Serial
version=1.0.0
author=hznupeter
maintainer=hznupeter <qiujiongtao@163.com>
sentence=GD5800 serial MP3 Player Arduino Library
paragraph=GD5800 serial MP3 Player Arduino Library.
category=Device Control
url=
architectures=*