Jeeprock:
Tank you darrob, after reading it seem more clear for me.
One more question:
1-Even if i'have success with that library, can i'use tx/rx pins on the board
using " SoftwareSerial mySoftwareSerial(2, 1); // RX, TX "
instead of
" SoftwareSerial mySoftwareSerial(10, 11); // RX, TX " ?
Save yourself a lot of heartache, and stick with SoftwareSerial on 10 and 11 or any other digital pins.
I have an application running now on 11 and 12, with 10 being connected to the BUSY pin of the DF Player.
And I'm not using any libraries either, the command bytes are easy enough to create in code and squirt out with a for-loop using SoftwareSerial.write()
Here's some ideas....
First the DF commands
////////////////////////////////////////////////////////////////////////////////////
// MP3 Player commands and queries
// DFPlayer - datasheet(https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299)
// The DFPlayer receives commands in a 10-byte string
// The DFPlayer has a checksum (2-bytes) before the last byte
// 7E FF 06 {command} {feedback mode} {data_Hi} {data_Lo} {CS_Hi} {CS_Lo} EF
byte MP3_Recv[10]; // MP3 response array
byte MP3_Send[10]; // MP3 command array
// Commands
#define NEXT 0x01 // Play the next track : No data - set parameter to 0
#define PREV 0x02 // Play the previous track : No data - set parameter to 0
#define PLAY_W_INDEX 0x03 // Play track number from root directory : DATA = track number 0-2999
#define VOL_UP 0x04 // Volume up 1 level : No data - set parameter to 0
#define VOL_DN 0x05 // Volume down 1 level : No data - set parameter to 0
#define VOL_SET 0x06 // Set Volume level : DATA = volume from 0 up to 30 (0x1E)
#define EQ_MODE 0x07 // Set Equalisation Preset
#define EQ_Normal 0x00
#define EQ_Pop 0x01
#define EQ_Rock 0x02
#define EQ_Jazz 0x03
#define EQ_Classical 0x04
#define EQ_Bass 0x05
#define MODE 0x08 // Set Playback Mode
#define MODE_Repeat 0x00
#define MODE_FolderRepeat 0x01
#define MODE_SingleRepeat 0x02
#define MODE_Random 0x03
#define DEV_SEL 0x09 // Storage Device Select
#define DEV_USB 0x00
#define DEV_TF 0x01
#define DEV_AUX 0x02
#define DEV_SLEEP 0x03
#define DEV_FLASH 0x04
#define SLEEP 0x0A // standby low power mode
#define WAKE 0x0B //
#define RESET 0x0C // Reset Chip
#define RESUME 0x0D // Play
#define PAUSE 0x0E // Pause
#define PLAY_F_T 0x0F // Play Folder/Track : DATA = 0x7E 06 0F 00 {folder} {track} {CSH} {CSL} EF
#define VOL_ADJ 0x10 // {DH=1:Open Volume Adjust}{DL:Set Gain 0-31}
#define REPEATPLAY 0x11 // 0=OFF, 1=ON
// Queries
#define SENDPAR 0x3F // Send Initialisation Parameters 0-0x0F
// each bit represent one device of the low-four bits ???
#define RETURNSERR 0x40 // Returns an Error : Request Retransmission ????
#define REPLY 0x41 // ????
#define Q_STATUS 0x42 // Query the current status
#define Q_VOL 0x43 // Query the current volume
#define Q_EQ 0x44 // Query the current equalisation mode
#define Q_MODE 0x45 // Query the current playback mode
#define Q_VERS 0x46 // Query the current software version
#define Q_TFFILES 0x48 // Query the number of TF card files
#define Q_UFILES 0x47 // Query the number of USB disk files
#define Q_FFILES 0x49 // Query the number of FLASH files
#define KEEPON 0x4A // ????
#define Q_TFTRACK 0x4B // Query the current track of TF card
#define Q_UTRACK 0x4C // Query the current track of USB disk
#define Q_FTRACK 0x4D // Query the current track of Flash
Then you can use the commands like....
MP3Cmnd(PLAY_W_INDEX, TrackSelect);
with....
void MP3Cmnd(byte command, unsigned int param) {
// create the command string to send to the player
MP3_Send[0] = 0x7E; // start byte
MP3_Send[1] = 0xFF; // version
MP3_Send[2] = 0x06; // length
MP3_Send[3] = command; // single byte command
MP3_Send[4] = 0x00; // feedback mode
MP3_Send[5] = (unsigned byte)(param >> 8); // data high byte
MP3_Send[6] = (unsigned byte)(param); // data low byte (truncated 16 to 8 bit)
// bytes [7] & [8] are the negated checksum of bytes [1] to [6]
unsigned int CSum = -(MP3_Send[1] + MP3_Send[2] + MP3_Send[3] + MP3_Send[4] + MP3_Send[5] + MP3_Send[6]);
MP3_Send[7] = (unsigned byte)(CSum >> 8); // checksum high byte
MP3_Send[8] = (unsigned byte)(CSum); // checksum low byte (truncated 16 to 8 bit)
MP3_Send[9] = 0xEF; // end byte
// send the command data to the MP3 module
for (int i=0; i<10; i++) {
MP3.write(MP3_Send[i]);
}
delay(100);
} // void MP3Cmnd()
No need for any library code at all, keeps it simple.