A great & very cheap MP3 sound module without need for a library!

It’s my pleasure @peekay123 !
Glad that I can start contributing to this great community…

I have just adapted another sketch or this module to “Particle world”:
It allows to play all songs on the CF card with a PLAY, PREVIOUS and NEXT button.

For my first test, I used 3 pinwires to connect D2 (Next), D3 (Pause) or D4 (Prev) to GND:

Here is the working sketch for Particles:

/* MP3 PLAYER PROJECT
From project: http://educ8s.tv/arduino-mp3-player/
Modified for "Particle world" by @FiDel
*/

# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]

# define ACTIVATED LOW

int buttonNext = D2;
int buttonPause = D3;
int buttonPrevious = D4;
boolean isPlaying = false;



void setup ()
{
  pinMode(buttonPause, INPUT_PULLUP);
  digitalWrite(buttonPause,HIGH);
  pinMode(buttonNext, INPUT_PULLUP);
  digitalWrite(buttonNext,HIGH);
  pinMode(buttonPrevious, INPUT_PULLUP);
  digitalWrite(buttonPrevious,HIGH);

  Serial1.begin(9600);
  delay(1000);
  playFirst();
  isPlaying = true;
}



void loop ()
{ 
 if (digitalRead(buttonPause) == ACTIVATED)
  {
    if(isPlaying)
    {
      pause();
      isPlaying = false;
    }else
    {
      isPlaying = true;
      play();
    }
  }


 if (digitalRead(buttonNext) == ACTIVATED)
  {
    if(isPlaying)
    {
      playNext();
    }
  }

   if (digitalRead(buttonPrevious) == ACTIVATED)
  {
    if(isPlaying)
    {
      playPrevious();
    }
  }
}


void playFirst()
{
  execute_CMD(0x3F, 0, 0);
  delay(500);
  setVolume(20);
  delay(500);
  execute_CMD(0x11,0,1); 
  delay(500);
}


void pause()
{
  execute_CMD(0x0E,0,0);
  delay(500);
}


void play()
{
  execute_CMD(0x0D,0,1); 
  delay(500);
}


void playNext()
{
  execute_CMD(0x01,0,1);
  delay(500);
}


void playPrevious()
{
  execute_CMD(0x02,0,1);
  delay(500);
}


void setVolume(int volume)
{
  execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
  delay(2000);
}


void execute_CMD(byte CMD, byte Par1, byte Par2) // Excecute the command and parameters
{
 // Calculate the checksum (2 bytes)
 int16_t checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);

 // Build the command line
 byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge, Par1, Par2, checksum >> 8, checksum & 0xFF, End_Byte};

 //Send the command line to the module
 for (byte k=0; k<10; k++)
 {
  Serial1.write( Command_line[k]);
 }
}

It sounds great with good speakers!
Enjoy… :stuck_out_tongue:

ATTENTION!

I found out that the speaker terminals are not “decoupled”: DC current is flowing through the speaker! This sounds poor and is dangerous…
Put an electrolytic capacitor in line with your speaker(s): Bigger = better… (220 - 2.200 uF/10V)
Attention to the correct polarity! (SPK1 = +)

7 Likes