DF Player Mini - not working

The code below came from https://www.dfrobot.com/blog-1422.html

The only changes I made (which I've included in the full code below) were:
int buttonNext = 7; // instead of 2
int buttonPrevious = 6; // instead of 4

It uploads correctly, but I get nothing from the player module. Neither on startup nor when I press either Next, Previous or Pause buttons.

Wiring and power are fine. No problem with other programs using same UNO, breadboard and button. But none do all that I want, so I'm exploring others like this one. I've posted to the author's blog. Anyone here used this code? Or can see anthing wrong with it please?

//////////////////////////////////////////
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# 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 = 7;
int buttonPause = 3;
int buttonPrevious = 6;
boolean isPlaying = false;
void setup ()
{
  pinMode(buttonPause, INPUT);
  digitalWrite(buttonPause, HIGH);
  pinMode(buttonNext, INPUT);
  digitalWrite(buttonNext, HIGH);
  pinMode(buttonPrevious, INPUT);
  digitalWrite(buttonPrevious, HIGH);
  mySerial.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();
    }
  }
  setVolume(10);
  playFirst();

}



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)
  word 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, highByte(checksum), lowByte(checksum), End_Byte
                          };
  //Send the command line to the module
  for (byte k = 0; k < 10; k++)
  {
    mySerial.write( Command_line[k]);
  }
}

Rather than have all the DF commands built into your code, use a library that has been tested and works. There are several to choose from within the IDE. In library manager, search for DF Mini and you will see all the choices. Choose one, try the examples.

Thanks, but I have tried several libraries over the last three months and am still looking for one that meets my relatively simple needs. See my post from about a week ago, so far with no replies.

Ideally I'm seeking code that, as a non-programmer, I can mostly understand. Although the subject example uses hex codes and serial commands etc, which takes it outside my current know-how level, it does at least seem logical. And its modules (functions?) for all the basic actions I want are built-in, yes? So I'm disappointed that it doesn't work as it stands.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.