Go Down

Topic: [SOLVED] DFPlayer Mini weird static noises when paired with 28BYJ-48 Step Motor (Read 535 times) previous topic - next topic

PharaohsVizier

I was hoping to get a bit of help with my DFPlayer Mini.  I'm just playing around with some tutorial codes for the DFPlayer Mini and the 28BYJ-48 stepper motor at the moment, with the hope that eventually I can get the motor to move in sync with a song I select later on.

Basically the trouble is that individually they work.  Under the loop section, I can comment off the stepper motor code and the DFPlayer will play perfectly, and on the other side, I can comment off the DFPlayer and the stepper motor runs fine.  However, when placed together, I get the song to play for maybe a half second, and then this really jarring static noise kicks in.  The motor doesn't run, so I think what is happening is that for whatever reason, output for the stepper motor is going to the DFPlayer.

I've chosen the AccelStepper library because of the finer controls available.  But basically I'm not sure where to begin looking at this problem.  Is it the wiring, or is it the code?  Do I look at the library or is it the code I've mashed together.  Any help would be greatly greatly appreciated!  Thanks!

Code: [Select]
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "AccelStepper.h"

#define HALFSTEP 8 
#define motorPin1  8     // IN1 on ULN2003 ==> Blue   on 28BYJ-48 
#define motorPin2  9     // IN2 on ULN2004 ==> Pink   on 28BYJ-48 
#define motorPin3  10    // IN3 on ULN2003 ==> Yellow on 28BYJ-48 
#define motorPin4  11    // IN4 on ULN2003 ==> Orange on 28BYJ-48 

int endPoint = 512;        // Move this many steps - 1024 = approx 1/4 turn 

SoftwareSerial mySoftwareSerial(12, 13); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); 

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){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
  myDFPlayer.volume(20);  //Set volume value. From 0 to 30
  stepper1.setMaxSpeed(20000.0); 
  stepper1.setAcceleration(3000); 
  stepper1.setSpeed(20000); 
  stepper1.moveTo(endPoint);

}

void loop()
{
  static unsigned long timer = millis();
  if (millis()%4000==0)
  { 
    myDFPlayer.play(1);  //Play the first mp3
    delay(8000);
    myDFPlayer.stop();
  }

  //Change direction at the limits 
  if (stepper1.distanceToGo() == 0) 
   { 
     Serial.println(stepper1.currentPosition()); 
     stepper1.setCurrentPosition(0); 
     endPoint = -endPoint; 
     stepper1.moveTo(endPoint); 
     Serial.println(stepper1.currentPosition()); 
   } 
  stepper1.run();
 
}

Grumpy_Mike

Quote
Is it the wiring, or is it the code?
Probably yes.

So far you have shown us the code, and not correctly at that. Use the code icon </> not the quote one.

Show us a schematic including how these things are powered, along with any decoupling you have on the power supplies.

PharaohsVizier

Show us a schematic including how these things are powered, along with any decoupling you have on the power supplies.
Thanks for the reply!  I've not done any decoupling, and in all honesty I had to google what that meant.  The power is straight through an Arduino Nano's MiniUSB port and I figured I'd worry about the power source later.



I've attached a picture of how it's being connected at the moment, the only thing I should have on there is that the MiniUSB port of the nano is plugged in for power.

Thanks again!  Seems like I'm a little out of my league.  :(

Grumpy_Mike

Quote
The motor doesn't run, so I think what is happening is that for whatever reason, output for the stepper motor is going to the DFPlayer.
Well what ever it is it is not that.

Quote
I can comment off the DFPlayer and the stepper motor runs fine.
What lines do you comment out to make the motor run? Can you post a version of the code with the relevant lines of code commented out please.

In general motors generate interference that is very easy to pick up on audio amplifiers. This is made even easier with the way you have wired it up. Connect power and ground of the player direct to the Arduino not to the bread board as that is causing an effect called ground lift due to the power going through the ground to the motors. You need a big capacitor on the input to the stepping motor driver, at least 100uF.

You also should not power the stepping motor from the USB as their is normally not enough current available. What current does your motor take? What is that driver board?

Having said that it is possible that the Accel driver is using the same resources as the software serial libiary.

Also so this line:-
Code: [Select]
static unsigned long timer = millis();
Will not set the timer variable to the value of millis on anything except the first time it is encountered. After that because it is static it will not be reinitialised. So drop the static bit from that line.
 

PharaohsVizier

This is the code with the lines commented out:

Code: [Select]
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "AccelStepper.h"

#define HALFSTEP 8 
#define motorPin1  8     // IN1 on ULN2003 ==> Blue   on 28BYJ-48 
#define motorPin2  9     // IN2 on ULN2004 ==> Pink   on 28BYJ-48 
#define motorPin3  10    // IN3 on ULN2003 ==> Yellow on 28BYJ-48 
#define motorPin4  11    // IN4 on ULN2003 ==> Orange on 28BYJ-48 

int endPoint = 512;        // Move this many steps - 1024 = approx 1/4 turn 

SoftwareSerial mySoftwareSerial(12, 13); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); 

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){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
  myDFPlayer.volume(20);  //Set volume value. From 0 to 30
  stepper1.setMaxSpeed(20000.0); 
  stepper1.setAcceleration(3000); 
  stepper1.setSpeed(20000); 
  stepper1.moveTo(endPoint);

}

void loop()
{
//  static unsigned long timer = millis();
//  if (millis()%4000==0)
//  { 
//    myDFPlayer.play(1);  //Play the first mp3
//    delay(8000);
//    myDFPlayer.stop();
//  }

  //Change direction at the limits 
  if (stepper1.distanceToGo() == 0) 
   { 
     Serial.println(stepper1.currentPosition()); 
     stepper1.setCurrentPosition(0); 
     endPoint = -endPoint; 
     stepper1.moveTo(endPoint); 
     Serial.println(stepper1.currentPosition()); 
   } 
  stepper1.run();
 
}


I will try and get some capacitors to see if that'll help and update when I do.  In the meantime, I think I'm going to try and switch to another stepper library and see if that has caused some clash, maybe the official library might help.

Grumpy_Mike


PharaohsVizier

This issue was solved by powering the DFPlayer with a separate power supply than the Arduino.  I found a link (https://stonez56.blogspot.ca/2015/03/arduino-dfplayer-mini-mp3-module.html) that suggested reducing DC voltage to 4.0-4.3 as an alternative, though it doesn't seem to be a solution to this specific problem. 

Basically I have the USB power through the Arduino for the step motor.  For the 5v and ground pins of the DF Player, they are connected to a separate battery pack.  Not the most elegant solution, but it'll do for now.

Go Up