Arduino Nano and DFPlayer Sketch Problem

Hi, this is my first post on the forum as a complete novice to all things Arduino. I have a need to use a Nano with a DFPlayer and have been given a circuit and a sketch to accomplish this.

I could not find and install in the library the first line of the sketch #include <DFPlayer_Mini_Mp3.h> so looking online found and installed DFRobotDFPlayerMini in the library.
I commented out the DFPlayer_Mini include and installed #include <DFRobotDFPlayerMini.h>
in its place. I then clicked the 'tick' to verify the sketch, at which point it throws up errors which seem to be related to the Mp3 serial setup.

I have copied the error messages here:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"





















C:\Users\mikec\OneDrive\Documents\MyKontrols 2011\Products\2022-100 Arduino Bell Code Sounder\soundplayer\SoundPlayer\SoundPlayer.ino: In function 'void setup()':

SoundPlayer:48:2: error: 'mp3_set_serial' was not declared in this scope

  mp3_set_serial (Serial);

  ^~~~~~~~~~~~~~

SoundPlayer:49:2: error: 'mp3_reset' was not declared in this scope

  mp3_reset();

  ^~~~~~~~~

SoundPlayer:50:2: error: 'mp3_set_volume' was not declared in this scope

  mp3_set_volume(15);

  ^~~~~~~~~~~~~~

C:\Users\mikec\OneDrive\Documents\MyKontrols 2011\Products\2022-100 Arduino Bell Code Sounder\soundplayer\SoundPlayer\SoundPlayer.ino:50:2: note: suggested alternative: 'adjustVolume'

  mp3_set_volume(15);

  ^~~~~~~~~~~~~~

  adjustVolume

C:\Users\mikec\OneDrive\Documents\MyKontrols 2011\Products\2022-100 Arduino Bell Code Sounder\soundplayer\SoundPlayer\SoundPlayer.ino: In function 'void adjustVolume()':

SoundPlayer:71:5: error: 'mp3_set_volume' was not declared in this scope

   { mp3_set_volume(newVolume); volume = newVolume;}

     ^~~~~~~~~~~~~~

C:\Users\mikec\OneDrive\Documents\MyKontrols 2011\Products\2022-100 Arduino Bell Code Sounder\soundplayer\SoundPlayer\SoundPlayer.ino:71:5: note: suggested alternative: 'adjustVolume'

   { mp3_set_volume(newVolume); volume = newVolume;}

     ^~~~~~~~~~~~~~

     adjustVolume

exit status 1

'mp3_set_serial' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I have uploaded the .ino file here and would be grateful of any help to put me on the right track (excuse the pun!).

SoundPlayer.ino (3.9 KB)

The circuit diagram is here:

Thank you in anticipation

you have code that depends on the old, deprecated Library (with dash in the name)

So if you just replaced it with DFRobotDFPlayerMini (no dash) then it's not compatible

Nano is 5v board why do you feed it 3.3v?

Hi Jackson, I realise that replacing the original library with the new DRRobotDFPlayerMini that the code is no longer compatible but what I am looking for is help to make the sketch run with the new library as I was unable to find and download the old library. As a complete novice I am unable to understand the error messages and was hoping someone might explain a: what they mean and b: what I might need to change in the original sketch.

Hi Edison, the sketch and circuit is as given to me, it is not my design but I was told it worked.

Give it a try with the details old library

Please see my first post. I cannot find and download and install the old deprecated library hence my query 'What do I need to alter in my old sketch to work with the new DRRobotDFPlayerMini library that I have downloaded and installed'?

I gave you the link just above

Managed to download the deprecated library after a lot of searching for the 'Download' button but to no avail as when I try to install/manage libraries/add zip file all I get is error message

`Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P"

Specified folder/zip file does not contain a valid library

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
`

The Volume command is
player.volume(volumeValue);
where volumeValue is 0 - 30.

What was 'mp3_set_serial' for?

This always comes up with new people, but you have to "post your code - in code tags". I don't want to d/l your INO and make a folder for that, etc. (Look up that code tags deal, don't paste your sketch as text.)

That’s how it used to be in the deprecated lib.

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

// Use pins 2 and 3 to communicate with DFPlayer Mini
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX 
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX 

const byte funBtn = 7;  // push a button, get a sound;  simple
byte pb;

SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);

// Create the Player object
DFRobotDFPlayerMini player;

void setup() 
{
  pinMode(funBtn, INPUT_PULLUP);
  Serial.begin(19200);
  softwareSerial.begin(9600);
  if (player.begin(softwareSerial)) 
  {
   Serial.println("OK");

    // Set volume to maximum (0 to 30).
    player.volume(22); //30 is very loud
  } 
  else 
  {
    Serial.println("Connecting to DFPlayer Mini failed!");
  }

  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

Faraday
Thank you for your explanation and your sketch, which now makes more sense to me regarding the serial settings in the original code. This is my first outing with anything Arduino and any sort of programming hence a steep learning curve.

I have posted the original code in code tags below:

[code]
#include <DFPlayer_Mini_Mp3.h>
#include <SoftwareSerial.h>
//
//  18 track sound box with push button or external triggers
//
//                       Connections for Arduino Nano and DFPlayer
//                       =========================================
//
//                     NANO//                                 DFPlayer
//          TX   D1   o     o  +7V to +12V                +5V  o     o  Busy
//          RX   D0   o     o  GND                         RX  o     o
//              Reset o     o  Reset                       Tx  o     o
//                GND o     o  +5V                             o     o
//   Track1 --->   D2 o     o  A7  <--- busy                   o     o
//   Track2 --->   D3 o     o  A6  <--- pot           Speaker  o     o 
//   Track3 --->   D4 o     o  A5  <--- Track18           GND  o     o  GND
//   Track4 --->   D5 o     o  A4  <--- Track17       Speaker  o     o 
//   Track5 --->   D6 o     o  A3  <--- Track16
//   Track6 --->   D7 o     o  A2  <--- Track15
//   Track7 --->   D8 o     o  A1  <--- Track14
//   Track8 --->   D9 o     o  A0  <--- Track13
//   Track9 --->  D10 o     o  Ref V
//   Track10 ---> D11 o     o  <--- 3.3V 
//   Track11 ---> D12 o     o  D13 <--- Track12
//
// Input pins - digital
int T1 = 2;   int T2 = 3;   int T3 = 4;
int T4 = 5;   int T5 = 6;   int T6 = 7;
int T7 = 8;   int T8 = 9;   int T9 = 10; 
int T10 = 11; int T11 = 12; int T12 = 13;

// Input pins - analog
int T13 = A0; int T14 = A1; int T15 = A2; 
int T16 = A3; int T17 = A4; int T18 = A5; 
int pot = A6; int busy = A7;

//variables
int n;         // track being played
int pinState;  // for reading pins
int volume;    // current volume level
int newVolume; // volume reading from pot
int threshold; // switching point for analog inputs

void setup () {
 Serial.begin (9600);
 mp3_set_serial (Serial);
 mp3_reset();
 mp3_set_volume(15);     
 pinMode(T1,INPUT_PULLUP);    pinMode(T2,INPUT_PULLUP);
 pinMode(T3,INPUT_PULLUP);    pinMode(T4,INPUT_PULLUP);
 pinMode(T5,INPUT_PULLUP);    pinMode(T6,INPUT_PULLUP);
 pinMode(T7,INPUT_PULLUP);    pinMode(T8,INPUT_PULLUP);
 pinMode(T9,INPUT_PULLUP);    pinMode(T10,INPUT_PULLUP);  
 pinMode(T11,INPUT_PULLUP);   pinMode(T12,INPUT_PULLUP);   
 pinMode(T13,INPUT_PULLUP);   pinMode(T14,INPUT_PULLUP);
 pinMode(T15,INPUT_PULLUP);   pinMode(T16,INPUT_PULLUP);
 pinMode(T17,INPUT_PULLUP);   pinMode(T18,INPUT_PULLUP);  
 
 pinMode(busy,INPUT);  pinMode(pot,INPUT);
 
threshold=700;
}


void adjustVolume(){
  newVolume = analogRead(pot);
  newVolume = map(newVolume, 0, 1023, 0, 30);
  if(newVolume != volume)
  { mp3_set_volume(newVolume); volume = newVolume;}
}



void play(int n) {
  play(n);
  while (analogRead(busy)< 200)  {delay(100);  adjustVolume();}      
}

void loop (){ 
pinState = digitalRead(T1);  if(pinState == 0)  {play(1);}
pinState = digitalRead(T2);  if(pinState == 0)  {play(2);}
pinState = digitalRead(T3);  if(pinState == 0)  {play(3);}
pinState = digitalRead(T4);  if(pinState == 0)  {play(4);}
pinState = digitalRead(T5);  if(pinState == 0)  {play(5);}
pinState = digitalRead(T6);  if(pinState == 0)  {play(6);}
pinState = digitalRead(T7);  if(pinState == 0)  {play(7);}
pinState = digitalRead(T8);  if(pinState == 0)  {play(8);}
pinState = digitalRead(T9);  if(pinState == 0)  {play(9);}
pinState = digitalRead(T10); if(pinState == 0)  {play(10);}
pinState = digitalRead(T11); if(pinState == 0)  {play(11);}
pinState = digitalRead(T12); if(pinState == 0)  {play(12);}
pinState = analogRead(T13);  if (pinState< threshold)  {play(13);}
pinState = analogRead(T14);  if (pinState< threshold)  {play(14);}
pinState = analogRead(T15);  if (pinState< threshold)  {play(15);}
pinState = analogRead(T16);  if (pinState< threshold)  {play(16);}
pinState = analogRead(T17);  if (pinState< threshold)  {play(17);}
pinState = analogRead(T18);  if (pinState< threshold)  {play(18);}
}
[/code]

This is as given to me. Now I understand a bit more I will try and update it using the DFRobotDFPlayerMini library which I have downloaded and installed.

try to compile using the deprecated library:

  • remove what you added to the Library folder

  • save the code you posted in #12 under the name TEST on your desktop. (that will create a TEST folder and inside you'll have TEST.ino)

  • Quit the IDE

  • download the zip from GitHub - DFRobot/DFPlayer-Mini-mp3 at c0bc05509c8a11f3b68b9b6758cb0508a365e7c9

  • unzip what you got on your desktop

  • In the DFPlayer-Mini-mp3-master/DFPlayer_Mini_Mp3 folder that you got, you'll see 2 files
    DFPlayer_Mini_Mp3.h and DFPlayer_Mini_Mp3.cpp

  • copy those 2 files into the TEST folder, next to TEST.ino so the folder should include 3 files:
    image

  • Double click now on TEST.ino to launch the IDE. The IDE should open a sketch window with 3 tabs

  • Edit the first line of the TEST.ino file to change the <> for the include into double quotes.

#include "DFPlayer_Mini_Mp3.h"

this instructs the compiler to look for the file first in the local folder before going to check for libraries.

  • compile and upload

you should be good to go... with all the possible bugs of the deprecated library and that code. I've no clue what it does :slight_smile:

Thank you for your suggestion. Having tried it, it still throws up errors

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"


C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp: In function 'void mp3_send_cmd(uint8_t)':

DFPlayer_Mini_Mp3.cpp:186:24: error: call of overloaded 'mp3_send_cmd(uint8_t&, int, int)' is ambiguous

  mp3_send_cmd(cmd, 0, 0);

                        ^

C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp:162:6: note: candidate: void mp3_send_cmd(uint8_t, uint16_t, uint16_t)

 void mp3_send_cmd (uint8_t cmd, uint16_t high_arg, uint16_t low_arg) {

      ^~~~~~~~~~~~

C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp:190:6: note: candidate: void mp3_send_cmd(uint8_t, uint8_t, uint32_t)

 void mp3_send_cmd (uint8_t cmd, uint8_t byte1, uint32_t byte234) {

      ^~~~~~~~~~~~

exit status 1

call of overloaded 'mp3_send_cmd(uint8_t&, int, int)' is ambiguous



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Just for info the code is supposed to read 18 pushbuttons and a volume control and play the Mp3 file associated with the button that is pressed.

i think my best chance is to try and get the code to work with the new DFRobotDFPlayerMini library. If that doesn't work then ????

Set the detailed output pref and Copy the full error

Have set the output to verbose when compiling as you suggested. Have pasted resultant error messages below:


C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\mikec\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\mikec\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\mikec\OneDrive\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10819 -build-path C:\Users\mikec\AppData\Local\Temp\arduino_build_184217 -warnings=default -build-cache C:\Users\mikec\AppData\Local\Temp\arduino_cache_411822 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\mikec\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\mikec\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\mikec\OneDrive\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10819 -build-path C:\Users\mikec\AppData\Local\Temp\arduino_build_184217 -warnings=default -build-cache C:\Users\mikec\AppData\Local\Temp\arduino_cache_411822 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp

Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\sketch\\DFPlayer_Mini_Mp3.cpp.cpp" -o nul

Alternatives for SoftwareSerial.h: [SoftwareSerial@1.0]

ResolveLibrary(SoftwareSerial.h)

  -> candidates: [SoftwareSerial@1.0]

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\sketch\\DFPlayer_Mini_Mp3.cpp.cpp" -o nul

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src\\SoftwareSerial.cpp" -o nul

Generating function prototypes...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\sketch\\DFPlayer_Mini_Mp3.cpp.cpp" -o "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\preproc\\ctags_target_for_gcc_minus_e.cpp"

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\sketch\\DFPlayer_Mini_Mp3.cpp.cpp" -o "C:\\Users\\mikec\\AppData\\Local\\Temp\\arduino_build_184217\\sketch\\DFPlayer_Mini_Mp3.cpp.cpp.o"

C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp: In function 'void mp3_send_cmd(uint8_t)':

DFPlayer_Mini_Mp3.cpp:186:24: error: call of overloaded 'mp3_send_cmd(uint8_t&, int, int)' is ambiguous

  mp3_send_cmd(cmd, 0, 0);

                        ^

C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp:162:6: note: candidate: void mp3_send_cmd(uint8_t, uint16_t, uint16_t)

 void mp3_send_cmd (uint8_t cmd, uint16_t high_arg, uint16_t low_arg) {

      ^~~~~~~~~~~~

C:\Users\mikec\OneDrive\Desktop\TEST\DFPlayer_Mini_Mp3.cpp:190:6: note: candidate: void mp3_send_cmd(uint8_t, uint8_t, uint32_t)

 void mp3_send_cmd (uint8_t cmd, uint8_t byte1, uint32_t byte234) {

      ^~~~~~~~~~~~

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial 

exit status 1

call of overloaded 'mp3_send_cmd(uint8_t&, int, int)' is ambiguous

You also might want to try out this alternate DFPlayer library:

Thank you. I will download and install it and give it a try.

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