DRV8825 + Nema17

Hi all,

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

    }

and this...

int dirPin = 2;
int stepperPin = 3;
void setup() {
 pinMode(dirPin, OUTPUT);
 pinMode(stepperPin, OUTPUT);
}
 void step(boolean dir,int steps){
 digitalWrite(dirPin,dir);
 delay(50);
 for(int i=0;i<steps;i++){
   digitalWrite(stepperPin, HIGH);
   delayMicroseconds(1600);
   digitalWrite(stepperPin, LOW);
   delayMicroseconds(1600);
 }
}
void loop(){
 step(true,400);
 delay(500);
step(false,400*5);
 delay(500);
}

but the motor only vibrate. There should be a problem in the code.

Has anybody an idea where the problem could be?

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.

These links may also help
Stepper Motor Basics
Simple Stepper Code

...R

@Robin2 thanks for the links. I've found them in an older post, but don't find a mistake in my code.

@groundfungus I've also tried the Accelstepper library with this example, but it doesn't work , too:

#include <AccelStepper.h>

// Run a A4998 Stepstick from an Arduino UNOusing AccelStepper
// Paul Hurley Aug 2015

AccelStepper stepper(1,3,2);//initialise accelstepper for a two wire board, pin 5 step, pin 4 dir

void setup() {
Serial.begin(9600);
pinMode(6,OUTPUT); // Enable
digitalWrite(6,LOW); // Set Enable low
}

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
}

but it doesn't work

Can you elaborate in that?

AccelStepper stepper(1,3,2);//initialise accelstepper for a two wire board, pin 5 step, pin 4 dir

The comment does not match the code.

Have you set the current control on the driver? Can you show how the driver is wired?

Please use code tags and format your code when posting code as described in the "how to use the forum" stickies.

The motor is rotating irregulary. (two steps forward and one backwards or something like this) and the motor has no moment of force.

The comment doesnt match to the code, because i have changed it to my wiring.

I have connected the DRV8825 to the Arduino as following:

Direction - Pin 2
Step - Pin 3
VDD of the DRV8825 to MS2 to generate 1/4 Microsteps
RESET to Sleep

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.

RESET to Sleep

On my setup reset to sleep and +5V.

daniel3d:
The motor is rotating irregulary.

Have you tried making the motor move very slowly - say two steps per second?

If that works gradually try faster speeds.

If it will not work very slowly then you may have a power supply problem.

The Pololu website has a good wiring diagram for the DRV8825 and IIRC the connections are not quite the same as for an A4988.

Have you the current limit set correctly on the DRV8825?

If you still have a problem then make a pencil drawing showing how YOU have everything connected and post a photo of the drawing.

Also post a link to the datasheet for your stepper motor - there are dozens of different Nema 17 motors.

...R