All the A4988 drivers connect the same. The diagram on the Pololu page will apply to your driver.
You can connect with a quality solderless breadboard for temporary testing, though that is not the best, at all. Better would be to solder the parts to a protoboard or use a CNC shield to mount the drivers and connect the steppers. I like the CNC shields for convenience.
Sure, like this. Tested on real hardware. The button wiring and the state change detection is shown in my tutorial. >> State change detection for active LOW inputs
// simple step/dir stepper toggle direction with button test by groundfungus
// aka charlie goulding
const byte stepPin = 2; // set to pin of your choice
const byte directionPin = 5; // set to pin of your choice
const byte buttonPin = 9;
int stepsToTake = 100;
unsigned long stepDelay = 20; // milliseconds to set stepper speed
void setup()
{
Serial.begin(115200);
Serial.println("Starting Stepper button toggle direction");
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
static bool lastButtonState = HIGH;
static unsigned long timer = 0;
unsigned long interval = 20;
if (millis() - timer >= interval)
{
timer = millis();
bool buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState)
{
Serial.println("time");
if (buttonState == LOW)
{
digitalWrite(directionPin, !digitalRead(directionPin)); // toggle direction
}
lastButtonState = buttonState;
}
}
singleStep(); // 10 milliseconds per step
delay(stepDelay);
}
void singleStep()
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(10);
digitalWrite(stepPin, LOW);
}