I'm working with a bipolar stepper motor (zjchao668), and a L298N Motor Drive Controller Board with an Uno. I think I'm missing something obvious? The problem is that the motor stops working if I call delay() in the sketch. For example, the first chunk of code below works completely fine. The motor makes one full clockwise revolution, then immediately does a full counterclockwise rotation back to where it started. Note that the delay between revolutions is commented out:
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution,8,9,10,11);
void setup() {
myStepper.setSpeed(100);
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
//delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
while(1);
}
HOWEVER the exact same code, with the delay between revolutions, does not work. When I run this, the motor makes one revolution clockwise, and then just stops. It never does the counterclockwise revolution, although the sketch does print "counterclockwise" to serial. Am I missing something? In all the tutorials I can find, there doesn't seem to be any problem using delay, but for some reason that seems to break for me.
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution,8,9,10,11);
void setup() {
myStepper.setSpeed(100);
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
while(1);
}