Using Accelstepper

Somehow having a ton of difficulty with the accelstepper library...

In the example called bounce, it uses
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

But I am using a DRV8825 to drive to stepper, and thus only have a wire on 2 & 3, one for direction the other for steps. I understand the rest of the code but not sure how to declare the 2 pins I'm using in conjuction with the library.

Thank you!

Try:

const byte STEP_PIN = 9, DIR_PIN = 8;
 
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

Where stepper = name of your stepper, STEP_PIN is the pin where your step wire is connected and DIR_PIN is the pin where your direction wire is connected. Look at the DualMotorShield example.

I imagine the advice in Reply #1 should have been

const byte STEP_PIN = 2, DIR_PIN = 3;

if you are using those pins with your stepper driver.

...R
Stepper Motor Basics
Simple Stepper Code

Ok great, that's what I was looking for thank you!

Now I'm coming to the issue of the stepper not rotating correctly.. its a bipolar stepper using a DRV8825.
Previously worked using:

//

//------------------Defining------------------
#define directionPin 2                        //sets stepper motor direction pin
#define stepPin 3                             //sets stepper motor movement or step pin
#define stepsPerRevolution 200                //sets stepper motor steps per revolution

void setup() {
  pinMode(directionPin, OUTPUT);              //sets direction pin as an output
  pinMode(stepPin, OUTPUT);                   //sets stepping pin as an output

}

void loop() 
{
stepperrotate();
}
void stepperrotate() 
{
//------------------Stepper Motor Rotation------------------
digitalWrite(directionPin, HIGH);             //sets direction as clockwise, HIGH=CW - LOW=CCW

// for(initialization; condition; incerement) { statements }
//1 rev = 1.625 in, rails approx 39 in long
for (int i = 0; i < 22 * stepsPerRevolution; i++)
{
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500);
  //all together, producing one step. Delay varies frequency and therefore speed, low number = high speed
}

delay(1000);

digitalWrite(directionPin, LOW);              //sets direction as ccw

for (int i = 0; i < 22 * stepsPerRevolution; i++) 
{
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(500);
}

delay(1000);
}

but wanted to use accelstepper so I can have it come up to speed slower, with acceleration. This is the code I use now:

//Libraries


#include <AccelStepper.h>

//------------------Defining------------------
#define directionPin 2                        //sets stepper motor direction pin
#define stepPin 3                             //sets stepper motor movement or step pin


AccelStepper conveyor(AccelStepper::DRIVER, stepPin, directionPin);

void setup() {
conveyor.setMaxSpeed(900.0);
conveyor.setAcceleration(900.0);
conveyor.moveTo(1000);
conveyor.run();
}

void loop() 
{
stepperrotate();
}
void stepperrotate() 
{



if (conveyor.distanceToGo() == 0)
  conveyor.moveTo(-conveyor.currentPosition());
  conveyor.run();

}

When running this, wired the same, it causes a whining noise with no rotation... when I set the accelstepper option from driver ot full2wire, it will step once and then step again in opposite direction, repeating. Have tried finding this through googling but am completely lost as to why this is.. when I upload the old code still works, but not with the new

Your call to stepper.run() should be outside the IF clause. Ideally just put it as the last line in loop()

...R