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!).
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.
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'?
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
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.)
#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.