Pages: [1]   Go Down
Author Topic: Can't Change direction of Stepper Motor with pololu a4988 driver  (Read 647 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys

i am having an issue switching direction of a motor with a buttonpress. im generally new to arduino, but i have some basic concepts, like pulsing the motor to get it to run. i have a pololu a4988 driver and a nema 17 motor. i have been able to get the motor to run continuously in one direction, but i cant get it to change directions. i tried googling around, but i couldnt find anything helpful / anything i could wrap my head around. here is my sketch.

Code:
int spd = 100;
int dir = 7;
int stp = 8;
int buttonPin = 2;
int buttonState;

void setup() { 
     
  pinMode(dir, OUTPUT);   
  pinMode(stp, OUTPUT);
  pinMode(buttonPin, INPUT);   
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == true ){

    digitalWrite(dir, LOW);
    digitalWrite(stp, HIGH);
    delayMicroseconds(spd); 
    digitalWrite(stp, LOW);
    delayMicroseconds(spd);
  }
  if (buttonState == false ){

    digitalWrite(dir, HIGH); 
    digitalWrite(stp, HIGH);
    delayMicroseconds(spd); 
    digitalWrite(stp, LOW);
    delayMicroseconds(spd);
  }
}

Thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, well i guess it was the fact that it wasnt outputting to the right pin...... it was 11 not 10....  smiley-eek-blue

i had a sketch before where i verified things like 20 times.... but i guess in those cases it was probably something else.

like i said. newbie.
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, well i guess it was the fact that it wasnt outputting to the right pin...... it was 11 not 10....  smiley-eek-blue

Your posted sketch only uses pins 2, 7 and 8, not 10
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: