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();
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);
}
void StepForwardDefault()
{
stepper.runToNewPosition(pos);
Serial.println("Enter new option");
Serial.println();
}
//Reverse default microstep mode function
void ReverseStepDefault()
{
digitalWrite(dir, HIGH); //Pull direction pin low to move "forward"
stepper.runToNewPosition(-pos);
Serial.println("Enter new option");
Serial.println();
}
void SmallStepMode()
{
digitalWrite(dir, HIGH); //Pull direction pin low to move "forward"
digitalWrite(MS1, HIGH);
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();
}