Go Down

Topic: Can't Change direction of Stepper Motor with pololu a4988 driver (Read 770 times) previous topic - next topic

gyrofan

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: [Select]

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!

gyrofan

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.

MarkT


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
[ I won't respond to messages, use the forum please ]

Go Up