Stepper Motor Trouble w/ AccelStepper Library

692 views
Skip to first unread message

Marshall Worrall

unread,
Feb 24, 2017, 6:10:04 PM2/24/17
to accelstepper
Hi All,

I am having trouble getting my stepper to run smoothly at "low speeds" (details below) using AccelStepper library. When running the stepper simply through my BigEasyDriver (at similar speeds) it runs very smooth. Appreciate any input.

My setup:
-Nema 17 stepper
-Arduino Uno Rev3
-30V Power Supply
-Big EasyDriver

Please see my video HERE. It shows how the motor is running with INPUT=3 (see code below), this is using a half-step loop through EasyDriver. The 2nd half of the video shows INPUT=1, using AccelStepper. The motor becomes very noisy and vibrates heavily (see the screw fly off the motor in the video).

I am supplying the EasyDriver 30V, and my power supply reads ~0.3A when the motor runs. When I try to go much higher with the current pot on the EasyDriver (at 30V) the motor spins out of control. I can get closer to the 2A spec of the motor when turning down the input Voltage. (but I get the same response as in the video)

Any ideas? 

Code:
#include <AccelStepper.h>
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define MS3 6
#define EN  7
AccelStepper stepper(AccelStepper::DRIVER, 2, 3);

//Declare variables for functions
char user_input;
int x;
int y;
int state;
int Input;
int pos = 100;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(MS3, OUTPUT);
  pinMode(EN, OUTPUT);
  resetEDPins(); //Set step, direction, microstep and enable pins to default states
  Serial.begin(9600); //Open Serial connection for debugging
  Serial.println("Begin motor control");
  Serial.println();
  stepper.setMaxSpeed(200);
  stepper.setAcceleration(2000);
  digitalWrite(MS1, LOW);
  digitalWrite(MS2, LOW);
  digitalWrite(MS3, LOW);
  
}

//Main loop
void loop() {
  while(Serial.available()){
      stepper.setCurrentPosition(0);
      
      user_input = Serial.read(); //Read user input and trigger appropriate function
      digitalWrite(EN, LOW); //Pull enable pin low to allow motor control
      if (user_input =='1')
      {
         StepForwardDefault();
      }
      else if(user_input =='2')
      {
        ReverseStepDefault();
      }
      else if(user_input =='3')
      {
        SmallStepMode();
      }
      else if(user_input =='4')
      {
        ForwardBackwardStep();
      }
      else if(user_input =='5')
      {
        CallInputMode();
      }
      else
      {
        Serial.println("Invalid option entered.");
      }
      resetEDPins();
  }
}

//Reset Easy Driver pins to default states
void resetEDPins()
{
  digitalWrite(stp, LOW);
  digitalWrite(dir, LOW);
  digitalWrite(MS1, LOW);
  digitalWrite(MS2, LOW);
  digitalWrite(MS3, LOW);
  digitalWrite(EN, HIGH);
}

//Default microstep mode function
void StepForwardDefault()
{
  Serial.println("Moving forward at default step mode.");
//  digitalWrite(dir, LOW); //Pull direction pin low to move "forward"

stepper.runToNewPosition(pos);

  Serial.println("Enter new option");
  Serial.println();
}

//Reverse default microstep mode function
void ReverseStepDefault()
{
    Serial.println("Moving back at default step mode.");
  digitalWrite(dir, HIGH); //Pull direction pin low to move "forward"

stepper.runToNewPosition(-pos);

  Serial.println("Enter new option");
  Serial.println();
}

// 1/8th microstep foward mode function
void SmallStepMode()
{
  Serial.println("Stepping at 1/8th microstep mode.");
  digitalWrite(dir, HIGH); //Pull direction pin low to move "forward"
  digitalWrite(MS1, HIGH); //Pull MS1, and MS2 high to set logic to 1/8th microstep resolution
  digitalWrite(MS2, LOW);
  digitalWrite(MS3, LOW);
  for(x= 1; x<300; x++)  //Loop the forward stepping enough times for motion to be visible
  {
    digitalWrite(stp,HIGH); //Trigger one step forward
    delay(1);
    digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
    delay(1);
  }
  Serial.println("Enter new option");
  Serial.println();
}

Marshall Worrall

unread,
Feb 25, 2017, 2:46:42 PM2/25/17
to accelstepper
So for an update to my above problem. I found when running without AccelStepper (just looping stp pins from HIGH to LOW), I will get similar behavior when I put a significant delay after setting the LOW stp pin. Setting this to delay(4) or greater starts to make the motor run very loud and with heavy vibrations.

So my current thinking is AccelStepper is currently set to run with a longer delay here as well? Although it seems odd other people would have similar problems if this was the case...

 The below runs smooth
 digitalWrite(dir, HIGH);
  digitalWrite
(MS1, HIGH);
  digitalWrite
(MS2, LOW);

  digitalWrite
(MS3, LOW);
 
for(x= 1; x<300; x++)

 
{
    digitalWrite
(stp,HIGH);
    delayMicroseconds
(10);
    digitalWrite
(stp,LOW);
    delay
(2);
 
}

This code runs very choppy, similar to how the motor runs using AccelStepper. (only changing the delay after LOW)
  digitalWrite(dir, HIGH);
  digitalWrite
(MS1, HIGH);
  digitalWrite
(MS2, LOW);

  digitalWrite
(MS3, LOW);
 
for(x= 1; x<300; x++)

 
{
    digitalWrite
(stp,HIGH);
    delayMicroseconds
(10);
    digitalWrite
(stp,LOW);
    delay
(4);
 
}

Jesse Bear

unread,
Feb 27, 2017, 7:35:15 PM2/27/17
to accelstepper
It looks like you have a resonance problem right around 250 steps/second. Have you tried increasing the delay? You're likely to find a frequency range that misbehaves, and everything will be fine above and below that frequency. I don't know how to handle that in AccelStepper - there is no direct provision to avoid particular frequencies or ranges of frequencies. What you CAN do is add or remove mass from the moving parts to change the resonant frequency. But first, just experiment with changing frequencies to identify the culprits.
Reply all
Reply to author
Forward
0 new messages