I am using this driver A4988 http://mlb-d1-p.mlstatic.com/driver-motor-de-passo-a4988-stepstick-pololu-reprap-ramps-637001-MLB20252170560_022015-O.webp?square=false to run a NEMA 16 motor (4 wires bipolar).
I did all connections exactly like this diagram http://howtomechatronics.com/wp-content/uploads/2015/08/A4988-Wiring-Diagram.png?e739c9
The problem is this: I see some codes saying that sending a LOW (to the step pin) -> wait a few milliseconds -> sending a HIGH (to the step pin) will make it walk one step. But for some reason in my case it's completely different.
In my case when I do this once (yes, once):
digitalWrite(step_pin,HIGH);
delayMicroseconds(800);
digitalWrite(step_pin,LOW);
delayMicroseconds(800);
my motor spins forever in a single direction. If I execute the above code again, my motor stops spinnins. It is not taking steps it's is rotating forever till I execute code above. I am using this code below:
const byte step_pin = 3;
const byte dir_pin = 4;
void setup() {
pinMode(step_pin,OUTPUT);
pinMode(dir_pin,OUTPUT);
digitalWrite(step_pin,HIGH);
digitalWrite(dir_pin,HIGH);
}
void loop() {
char resultado = "";
if (Serial.available()) {
resultado = (char)Serial.read();
if (resultado == "a") {
digitalWrite(step_pin,HIGH);
delayMicroseconds(800);
digitalWrite(step_pin,LOW);
delayMicroseconds(800);
}
}
}
What is going on? My motor should only spin a single step every time "a" is sent in the Serial, right? But no, it's spinning forever till next time I press "a" and it stops spinning. But if I hit "a" again my motor starts spinning forever again!