AccelStepper library with DRV8825 driver and MKS GEN(RAMPS Shield+Mega)

I have a stepper wired up to a MKS GEN board with a DRV8825 driver in place. I have verified the wiring and have no problem running the stepper using the Laurb StepperDriver library. I can’t seem to get the Accel Stepper library to do anything for me. The stepper doesn’t respond at all (no motion, no whining, etc). I’m not sure what code to post as I’ve tried a variety of settings, but below is my best attempt at what I think is the bare minimum to make this work. I’m not exactly certain how the enable stepper functions work with accelstepper since I have not been able to find sample code that utilizes it. Any thoughts/comments would be appreciated.

AccelStepper code

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 54, 55);


void setup()
{  
  stepper.setMaxSpeed(150);
   stepper.setSpeed(50);	
  stepper.setAcceleration(100);
  stepper.setEnablePin(38);
  stepper.enableOutputs();
}
void loop()
{    
  
   stepper.runSpeed();
 
}

===============================
Laurb StepperDriver Code (works!)

#include <Arduino.h>
#include "BasicStepperDriver.h"

// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 200

// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 1

// All the wires needed for full functionality
#define DIR 55
#define STEP 54
//Uncomment line to use enable/disable functionality
#define ENABLE 38

// 2-wire basic config, microstepping is hardwired on the driver
//BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);

//Uncomment line to use enable/disable functionality
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, ENABLE);

void setup() {
    stepper.begin(RPM, MICROSTEPS);
}

void loop() {
  
    // energize coils - the motor will hold position
     stepper.enable();
  
    /*
     * Moving motor one full revolution using the degree notation
     */
    stepper.rotate(1200);
delay(1000);
    /*
     * Moving motor to original position using steps
     */
    stepper.move(-1200);

    // pause and allow the motor to be moved by hand
     stepper.disable();

    delay(1000);
}

You are not asserting the enable pin of the driver board in the AccelStepper program. It probably needs to be set to LOW for things to work. (But if that is wrong try setting it to HIGH).

...R

Thanks for the reply.

I understood the "stepper.enableOutputs();" call would HIGH or LOW the enable pin based off my configuration. Since it's never disabled I assume its ok to call it in the setup routine. I've tried inverting the enable signal with the "setPinsInverted" function but to no avail. I've seen only 1 or so examples with a setup of AccelStepper and a DRV8825 or a A4988 driver, which none called the enable pin at all. I've tested the enable/disable functionality of the Laurb library and that works as it should.

To be honest, I would just set the enable pin LOW (or HIGH) with a digitalWrite() in setup()

Then, at least, you are in control of it.

...R

Yea, I guess I needed to invert the enable pin which I tried but must’ve had some poor code to actually call the stepper to move. Below is a set of working code, thanks!

#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 54, 55); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);	
   stepper.setEnablePin(38);
   stepper.setPinsInverted(false, false, true);

}

void loop()
{  
   stepper.enableOutputs();
   stepper.runSpeed();
}