Stepper library suddenly not working

Hello!

I was recently using my Arduino Uno with the Arduino Motor Shield to drive a NEMA 14 12V Stepper Motor ClockWise, CounterClockWise, then Clockwise again. Everything seemed to be working fine, but I decided to slow down the step speed from 60 to 30. After changing this, however, the motor would not move anymore. I changed the step speed back to 60 and re-uploaded the entire original program, but still the motor would not move. I’m fairly certain it is not an issue with the motor because I can no longer drive any other motors I was able before either. However, I AM able to drive the motor with this code:

int delaylegnth = 5;

void setup() {
  
  //establish motor direction toggle pins
  pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
  pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
  
  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) CH A
  pinMode(8, OUTPUT); //brake (disable) CH B


  
  
}

void loop(){
 
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, HIGH);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
  
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, LOW);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
  
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, LOW);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
    
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, HIGH);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);

}

But my original code using the Stepper Library has stopped driving my motors:

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 200

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(200, 12, 13);


void setup()
{
  // set the speed of the motor
  stepper.setSpeed(60);
  stepper.step(256);
  delay(500);
  stepper.step(-232);
  delay(500);
  stepper.step(8);
}

void loop()
{




}

I’ve used another Arduino Uno board, and the same issue occurs, and i’m still very much unsure of what the problem could be. I’d very much like to use the Stepper Library in my project rather than powering pins manually. Can anyone help? Thank you very much!

Hi,

Have you tried loading one of the stepper library examples?

Tom... :)

Stepper stepper(200, 12, 13);

Don’t you need to specify 4 pins if you are using a h-bridge to drive the motor?

…R
Stepper Motor Basics
Simple Stepper Code

Hi,

None of the stepper library examples seem to be able to drive the motor either. I'm starting to believe that I'm not exactly sure which 4 pins are the ones I should specify when constructing my Stepper object. I would assume they would be 8, 9, 12, 13, as they are labeled "Brake B" "Brake A" "DIR A" and "DIR B." However, this code still doesn't work:

Stepper stepper(200, 8, 9, 12, 13);

I have also tried the default 8, 9, 10, 11 as given in the examples and that doesn't seem to drive the motor either.

Post a link to the datasheet for your Motor Shield so we can know exactly what you are talking about.

...R