pls, how to use one arduino as master in order to trigger pin on slave arduino which will play mp3 sample.
master arduino has non-editable software which sends to output pins high or low state (via remote control).
i have some example code, error is 'ISR' was not declared in this scope
***************************************************
DFPlayer - A Mini MP3 Player For Arduino
<https://www.dfrobot.com/index.php?route=product/product&product_id=1121>
***************************************************
This example shows the basic function of library for DFPlayer.
Created 2016-12-07
By [Angelo qiao](Angelo.qiao@dfrobot.com)
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
****************************************************/
/***********Notice and Trouble shooting***************
1.Connection and Diagram can be found here
<https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299#Connection_Diagram>
2.This code is tested on Arduino Uno, Leonardo, Mega boards.
****************************************************/
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#define pin 2 // connect to master digital output "pin"
unsigned int state;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
pinMode(pin,INPUT);
state=0;
attachInterrupt(digitalPinToInterrupt(pin), ISR, RISING)); // trigger on rising edge of master voltage signal
mySoftwareSerial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(30); //Set volume value. From 0 to 30
}
void loop(){
if(state==1){
myDFPlayer.play(1); // Play the first mp3
state=0; // reset when done
}
}
void ISR() {
state=1;
}
{
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
void printDetail(uint8_t type, int value) {
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}
Any other solution except External interrupts would be welcome.
This block of code is not contained within any function:
{
if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}
You don't need an ISR for this. Just have your loop() function read the input and check for it going HIGH.
is this code ok, im newbie ?
Is it possible to use any other pin except pin 2, as input , and can i use also multiple different pins as inputs for different states.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#define pin 2 // connect to master digital output "pin"
unsigned int state;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
pinMode(2,INPUT);
state=0; // sets the digital pin 2 as input as example to read output from another arduino
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(30); //Set volume value. From 0 to 30
}
void loop(){
if(state==1){
myDFPlayer.play(1); // Play the first mp3
state=0; // reset when done
}
}
PrinzEugen:
nothing happens
That's because you didn't read the input pin. You should really review the examples included with the IDE regarding digital input and output. Here is code that will play the file when the input goes from LOW to HIGH:
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#define pin 2 // connect to master digital output "pin"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(115200);
pinMode(2, INPUT);
state = 0; // sets the digital pin 2 as input as example to read output from another arduino
Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(30); //Set volume value. From 0 to 30
}
void loop() {
byte prevState = LOW;
byte pinState;
pinState = digitalRead(pin);
if (pinState == HIGH && prevState == LOW) {
myDFPlayer.play(1); // Play the first mp3
}
prevState = pinState;
}
- df mini player stays always on with this code , no sound
- this code will trigger pin 2 only if port is high on master arduino ?
- Is it possible to use any other pin except pin 2, as input , and can i use also multiple different pins as inputs for different states ?
ps. i have deleted state = 0; it displays error , not defined
PrinzEugen:
- df mini player stays always on with this code , no sound
- this code will trigger pin 2 only if port is high on master arduino ?
- Is it possible to use any other pin except pin 2, as input , and can i use also multiple different pins as inputs for different states ?
ps. i have deleted state = 0; it displays error , not defined
PrinzEugen:
- df mini player stays always on with this code , no sound
- this code will trigger pin 2 only if port is high on master arduino ?
- Is it possible to use any other pin except pin 2, as input , and can i use also multiple different pins as inputs for different states ?
ps. i have deleted state = 0; it displays error , not defined
-
If you don't have anything connected to pin 2 then it is floating so it may or may not trigger since you don't have a pullup or pulldown resistor. It sounds like pin 2 is staying HIGH or perhaps toggling between high and low. Hook GND to pin 2 and see if it still happens.
-
Yes if you have it connected properly.
-
What Arduino are you using? That will determine which pins you can use. It is all documented on this site.
You should read this tutorial regarding digital pins DigitalPins
Most of your questions are answered in the references, tutorials, and examples on this site.
Also, if the two Arduinos you are using are different models then you want to make sure they have compatible voltages. For example, you would not want to put 5V into a 3.3V input.
im using two arduino uno's.
output on master arduino is 5v, between output pin and ground
nothing happened when i short connected digital pin 2 to gnd. something is wrong in code, i'm trying to figure it out.
What does the serial console show? Does it say "DFPlayer Mini online." If not, you have an issue with your SD card or configuration of the player. If it does say that then you should put a Serial.println in your loop code to indicate what the digital input state is. I don't have your hardware setup so I can't very well debug it for you.
You should debug one thing at a time. Forget about the master Arduino. Just try to get the file to play. Since you don't have a pulldown resistor you should have GND connected to pin 2 when the board is powered up. Otherwise it will trigger the file to play...assuming it made it out of the setup function in the first place.
with this code, mp3 sample was running just a few seconds, and then stopped, dfplayer stays on
here is connection diagram
and display monitor
Did you put a Serial.println in your loop code to display the state of pin 2?
i have managed to trigger sound with different code, pullup added to pin2
pinMode(2,INPUT_PULLUP);
void loop(){
if (digitalRead(2)==LOW) myDFPlayer.play(1); // play mp3 sample
only issue i have is when master arduino or slave sends low output to pin e.g 2, then sample wouldn't start until output and pin2 are connected for a brief moment (pushbutton example),
since i will not use buttons and switches, then output and input are connected directly, another sample would be played only if low signal is sent again. i hope you understand what i meant. here's picture.
debounce button ?