Forum >DFPlayer simultaneous usage
DFPlayer simultaneous usage

If I use the dfplayer can I play sound effects with the arduino uno or mega, while simultaneously moving servo and stepper motors without interference?
Thanks
Thanks
2017-03-15 09:36:10 Hi there, I just registered while searching for answers to the DFplayer.
I actually have the same task, getting a gate crossing working for the model railroad
My approach is a bit different from the sketch, but basically similar, trying to play a loop (bell ring) while a servo is shutting the gates and a relay powering an external blinking module for the many LED's in action.
I can get the dfplayer to work w/o problems alone, using the wiki sample code.
I can get the servo and relay working all controlled by a single button.
But the moment I try to integrate the DFplayer into the sketch, I run into problems.
Example:
in the void setup() section I have a series of setup syntax. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the end of the setup section, the NANO I use hangs! The built in LED on Pin 30 starts blinking and no reaction on the rest button on the board. I need to upload another sketch to bring the NANO back to life. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the beginning of the setup, I don't run into this problem. However, the sketch gets stuck later hanging somewhere. I tried so many possibilities. I will upload the sketch I use later, currently not at home.
@ mnrk:
At the current version of my sketch, the servo is not yet included! And it doesn't work with DFplayer! So it has nothing to do with incompatibility of the servo and DFplayer library.
liquidfantasy
I actually have the same task, getting a gate crossing working for the model railroad

My approach is a bit different from the sketch, but basically similar, trying to play a loop (bell ring) while a servo is shutting the gates and a relay powering an external blinking module for the many LED's in action.
I can get the dfplayer to work w/o problems alone, using the wiki sample code.
I can get the servo and relay working all controlled by a single button.
But the moment I try to integrate the DFplayer into the sketch, I run into problems.
Example:
in the void setup() section I have a series of setup syntax. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the end of the setup section, the NANO I use hangs! The built in LED on Pin 30 starts blinking and no reaction on the rest button on the board. I need to upload another sketch to bring the NANO back to life. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the beginning of the setup, I don't run into this problem. However, the sketch gets stuck later hanging somewhere. I tried so many possibilities. I will upload the sketch I use later, currently not at home.
@ mnrk:
At the current version of my sketch, the servo is not yet included! And it doesn't work with DFplayer! So it has nothing to do with incompatibility of the servo and DFplayer library.

2017-03-15 09:36:10 Hi there, I just registered while searching for answers to the DFplayer.
I actually have the same task, getting a gate crossing working for the model railroad
My approach is a bit different from the sketch, but basically similar, trying to play a loop (bell ring) while a servo is shutting the gates and a relay powering an external blinking module for the many LED's in action.
I can get the dfplayer to work w/o problems alone, using the wiki sample code.
I can get the servo and relay working all controlled by a single button.
But the moment I try to integrate the DFplayer into the sketch, I run into problems.
Example:
in the void setup() section I have a series of setup syntax. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the end of the setup section, the NANO I use hangs! The built in LED on Pin 30 starts blinking and no reaction on the rest button on the board. I need to upload another sketch to bring the NANO back to life. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the beginning of the setup, I don't run into this problem. However, the sketch gets stuck later hanging somewhere. I tried so many possibilities. I will upload the sketch I use later, currently not at home.
@ mnrk:
At the current version of my sketch, the servo is not yet included! And it doesn't work with DFplayer! So it has nothing to do with incompatibility of the servo and DFplayer library.
liquidfantasy
I actually have the same task, getting a gate crossing working for the model railroad

My approach is a bit different from the sketch, but basically similar, trying to play a loop (bell ring) while a servo is shutting the gates and a relay powering an external blinking module for the many LED's in action.
I can get the dfplayer to work w/o problems alone, using the wiki sample code.
I can get the servo and relay working all controlled by a single button.
But the moment I try to integrate the DFplayer into the sketch, I run into problems.
Example:
in the void setup() section I have a series of setup syntax. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the end of the setup section, the NANO I use hangs! The built in LED on Pin 30 starts blinking and no reaction on the rest button on the board. I need to upload another sketch to bring the NANO back to life. If I add myDFPlayer.volume(10); and myDFPlayer.play(1); at the beginning of the setup, I don't run into this problem. However, the sketch gets stuck later hanging somewhere. I tried so many possibilities. I will upload the sketch I use later, currently not at home.
@ mnrk:
At the current version of my sketch, the servo is not yet included! And it doesn't work with DFplayer! So it has nothing to do with incompatibility of the servo and DFplayer library.

2017-03-15 05:35:27 I did the dfplayer initializationot and that was working. So that isn't it. Any other thoughts?
mnrk

2017-03-15 05:35:27 I did the dfplayer initializationot and that was working. So that isn't it. Any other thoughts?
mnrk

2017-03-15 02:25:55 Hi
Please refer to the wiki sample code to do the dfplayer initialization, if the initialization is not successful, which is possible to result the problem I think.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
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(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
Wendy.Hu
Please refer to the wiki sample code to do the dfplayer initialization, if the initialization is not successful, which is possible to result the problem I think.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
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(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}

2017-03-15 02:25:55 Hi
Please refer to the wiki sample code to do the dfplayer initialization, if the initialization is not successful, which is possible to result the problem I think.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
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(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}
Wendy.Hu
Please refer to the wiki sample code to do the dfplayer initialization, if the initialization is not successful, which is possible to result the problem I think.
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
void setup()
{
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(10); //Set volume value. From 0 to 30
myDFPlayer.play(1); //Play the first mp3
}

2017-03-14 15:39:26 Correction: I figured out why nothing was playing...I didn't have the following lines in the setup() section:
mySoftwareSerial.begin(9600);
if (!myPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while (true);
}
BUT...when I have the myservoX.attach(N); lines and myservoX.write(pos); lines un-commented, the servos still go crazy and spastic.
It seems to me that there is something not compatible with the Servo library and either the SoftwareSerial library or the DFRobotDFPlayerMin library.
Can anyone a bit more knowledgeable in that department help me figure this out?
Thanks.
mnrk
mySoftwareSerial.begin(9600);
if (!myPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while (true);
}
BUT...when I have the myservoX.attach(N); lines and myservoX.write(pos); lines un-commented, the servos still go crazy and spastic.
It seems to me that there is something not compatible with the Servo library and either the SoftwareSerial library or the DFRobotDFPlayerMin library.
Can anyone a bit more knowledgeable in that department help me figure this out?
Thanks.

2017-03-14 15:39:26 Correction: I figured out why nothing was playing...I didn't have the following lines in the setup() section:
mySoftwareSerial.begin(9600);
if (!myPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while (true);
}
BUT...when I have the myservoX.attach(N); lines and myservoX.write(pos); lines un-commented, the servos still go crazy and spastic.
It seems to me that there is something not compatible with the Servo library and either the SoftwareSerial library or the DFRobotDFPlayerMin library.
Can anyone a bit more knowledgeable in that department help me figure this out?
Thanks.
mnrk
mySoftwareSerial.begin(9600);
if (!myPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while (true);
}
BUT...when I have the myservoX.attach(N); lines and myservoX.write(pos); lines un-commented, the servos still go crazy and spastic.
It seems to me that there is something not compatible with the Servo library and either the SoftwareSerial library or the DFRobotDFPlayerMin library.
Can anyone a bit more knowledgeable in that department help me figure this out?
Thanks.

2017-03-14 13:50:48 That didn't work. I even tried to remove the 'if' statements and only included one of the 'myPlayer.play(1);' commands and that is where things now just don't do anything (no sound and servos don't move). If I comment out the 'myPlayer.play(1);' line then the servos sweep. Is there something that is interfering between the Servo, DFRobotDFPlayerMini, and/or SoftwareSerial libraries? Am I using the correct pins on the Arduino mini pro (10 as RX to Pin3 on DFPlayer, 11 as TX to Pin2 on DFPlayer, 5 as signal to servo1, 6 as signal to servo2)?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
mnrk
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

2017-03-14 13:50:48 That didn't work. I even tried to remove the 'if' statements and only included one of the 'myPlayer.play(1);' commands and that is where things now just don't do anything (no sound and servos don't move). If I comment out the 'myPlayer.play(1);' line then the servos sweep. Is there something that is interfering between the Servo, DFRobotDFPlayerMini, and/or SoftwareSerial libraries? Am I using the correct pins on the Arduino mini pro (10 as RX to Pin3 on DFPlayer, 11 as TX to Pin2 on DFPlayer, 5 as signal to servo1, 6 as signal to servo2)?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
mnrk
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

2017-03-14 00:17:19 Hi
Did you try to change the code as below to try again?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Wendy.Hu
Did you try to change the code as below to try again?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

2017-03-14 00:17:19 Hi
Did you try to change the code as below to try again?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Wendy.Hu
Did you try to change the code as below to try again?
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

2017-03-12 16:46:20 I tried to just drop some code in and the servos went crazy/spastic.
I'm trying to have some model railroad crossing gates close using servos while having a bell sound as the gates go down and up. What have I missed... This is the code that I'm testing with [modification of the servo sweep example]:
[code]
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
[/code]
I'm using Arduino IDE 1.8.1 and the DFRobotDFPlayerMini 1.0.1 library
mnrk
I'm trying to have some model railroad crossing gates close using servos while having a bell sound as the gates go down and up. What have I missed... This is the code that I'm testing with [modification of the servo sweep example]:
[code]
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
[/code]
I'm using Arduino IDE 1.8.1 and the DFRobotDFPlayerMini 1.0.1 library

2017-03-12 16:46:20 I tried to just drop some code in and the servos went crazy/spastic.
I'm trying to have some model railroad crossing gates close using servos while having a bell sound as the gates go down and up. What have I missed... This is the code that I'm testing with [modification of the servo sweep example]:
[code]
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
[/code]
I'm using Arduino IDE 1.8.1 and the DFRobotDFPlayerMini 1.0.1 library
mnrk
I'm trying to have some model railroad crossing gates close using servos while having a bell sound as the gates go down and up. What have I missed... This is the code that I'm testing with [modification of the servo sweep example]:
[code]
#include <Servo.h>
#include <DFRobotDFPlayerMini.h>
#include <SoftwareSerial.h>
DFRobotDFPlayerMini myPlayer;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
SoftwareSerial mySoftwareSerial(10, 11);
int buusyPin = 3; //busy pin from dfplayer
int pos = 0; // variable to store the servo position
void setup() {
myservo1.attach(5);
myservo2.attach(6);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 8) { // goes from 180 degrees to 0 degrees
if (digitalRead(buusyPin) == HIGH) { // if DFPlayer is done playing the sound, play it again
myPlayer.play(1);
}
myservo1.write(pos); // tell servo to go to position in variable 'pos'
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
[/code]
I'm using Arduino IDE 1.8.1 and the DFRobotDFPlayerMini 1.0.1 library

2016-03-04 00:52:26 Hi sekramer10,
Should be no problem, to play some music just need to drop a line of relative command, after that, the DFplayer will play music, the code will proceed on the servo. stepper things... then.
Leff
Should be no problem, to play some music just need to drop a line of relative command, after that, the DFplayer will play music, the code will proceed on the servo. stepper things... then.

2016-03-04 00:52:26 Hi sekramer10,
Should be no problem, to play some music just need to drop a line of relative command, after that, the DFplayer will play music, the code will proceed on the servo. stepper things... then.
Leff
Should be no problem, to play some music just need to drop a line of relative command, after that, the DFplayer will play music, the code will proceed on the servo. stepper things... then.

2016-03-03 06:17:23 If I use the dfplayer can I play sound effects with the arduino uno or mega, while simultaneously moving servo and stepper motors without interference?
Thanks
anonymous
Thanks
