AccelStepper + Buttons = Nothing! - help please

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper = AccelStepper(1, D6, D7); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

int buttonPin1 = D11;
int buttonPin2 = D12;
int buttonState1 = HIGH;
int buttonState2 = HIGH;
int motorPos = 0;

void setup()
{   
    Serial.begin(9600);
    stepper.setMaxSpeed(400.0);
    stepper.setAcceleration(200);
    pinMode(buttonPin1, INPUT_PULLUP);
    pinMode(buttonPin2, INPUT_PULLUP);
}

void loop()
{    
    //digitalWrite(MS2pin, HIGH);
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);

    if (buttonState1 == LOW) {
      Serial.println("buttonState1");
      Serial.println(buttonState1);
      motorPos = 500;
    }

    if (buttonState2 == LOW) {
      Serial.println("buttonState2");
      Serial.println(buttonState2);
      motorPos = 1000;
    }

    stepper.runToNewPosition(motorPos);
  
}

IDE version 1.8.12

I’m using a A4988 driver to power a NEMA 17 with a Wemos D1. I have confirmed that stepper motor will run to various positions with similar “runToNewPosition” code so i’m fairly confident on my wiring. I cannot however, get them to run to a certain position when a button is pressed. I have also confirmed that the button pins are at 3.3V when unpressed and 0V/grounded when pressed, which I thought i was triggering in my code. Only one of the buttons (D12) trigger a very slight movement when I press it, the other does nothing. Any help would be greatly appreciated, let me know if you need any more information.

Are your Serial.print() statements showing the results you expect?

...R

Robin2:
Are your Serial.print() statements showing the results you expect?

...R

Yes, it'll say "Moving to position 500" for example if I put that right after the move command within the IF statement, but it will only jerk slightly. The same code outside an IF with run flawlessly. Very strange

nilejr:
Yes, it'll say "Moving to position 500" for example

The program in your Original Post does not have "Moving to ..." so you must be talking about a different program.

If you want help then please post the correct program so we are all looking at the same thing.

...R

Try to write to the stepper only when the position changes instead of (re)writing to it for each iteration of the main loop.

So I think I found the culprit, I don't think there is enough power to pull 2 pins HIGH and also drive the stepper motor. It worked with only one button, now to figure out a double click or long hold code for another input.

nilejr:
So I think I found the culprit, I don't think there is enough power to pull 2 pins HIGH and also drive the stepper motor.

The stepper will require it's own power supply, it (most likely) cannot be powered by the board.