some months ago i've build a stepper controlled robotic arm with nema 17 motors, a arduino mega and a home made motor shield, based on DRV8825 stepper driver. At this time i had a little code sample on the arduino which shows me that the electronic is working - the motors are rotating without any problems. Because i've written the arduino code on a computer which i didn't have anymore, i started programming a new one, but it doesn't work, now. I dont know what i'm doing wrong.
I've tried this example...
#include <Stepper.h>
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 2;
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
Stepper myStepper(stepsPerRevolution, 2,3);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
myStepper.setSpeed(20);
myStepper.step( (5*200)/360 ); //this should move it around 2.7 steps at a time
}
I don't think that the Stepper.h library is written for the step-dir type of stepper drivers. Stepper.h is written for L293/L298 or ULN 2003 2 or 4 wire drivers which are very different. Stepper.h also has trouble with more than one motor. Try the AccelStepper library. It has the option to use the step-dir type drivers (DRIVER in consstructor) and will handle multiple motors with ease.
void loop() {
digitalWrite(6,LOW); // Set Enable low
if (stepper.distanceToGo() == 0)
{ // Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
stepper.moveTo(rand() % 400);
stepper.setMaxSpeed((rand() % 400) + 200);
stepper.setAcceleration((rand() % 200) + 100);
}
Serial.println(stepper.distanceToGo());
stepper.run(); // Actually makes stepper move
}
I have set up a NEMA 17 stepper (1.6A/phase, 1.8 degrees/step) and DRV8825 connected to an Uno. DRV8825 set to 1/4 step, Vref to .7 (1.4A/phase). The stepper runs smoothly with good torque. If I set the DRV8825 to full steps I see the behavior that you describe (sort of "chattering", but torque is good when running smoothly). Not sure why. Will investigate, time allowing.