Stepper motor rotates the wrong way after soldering components together


I have spent the last couple of months designing and building a star tracker. The purpose of this is to take photos of the night sky, without the stars turning into streaks, as the sky rotates. Without getting too technical, in it's current state it consists of a high-gear stepper motor, which I have mounted a camera to. To test this setup some time ago, I ran it while connecting everything together using a breadboard (component list further down). I used the AccelStepper library to configure 16x microstepping and the correct direction for the motor to spin in. This worked wonderfully. After this test, I soldered everything to a perfboard. I remounted everything, and tested it again. This time however, the motor acted erratically. Sometimes it acted as if the motor wasn't even on, sometimes it would work for one picture, but not for the next.

The conclusion I arrived at was that for some reason, the rotational direction seems to have been reversed! Now when I reverse the direction in my code, and raise the speed, it works as intended!

I am completely stumped as to why this is. Have I reversed the polarity somewhere? Would that even give these results? What could possibly have caused this behavior?

The components I am using are:
Arduino Nanon (old bootloader)
A4988 stepper driver
Nema 17 stepper motor
Accelstepper stepper library

Any suggestions or tips would be greatly appreciated.

This is the specific motor I use:

It seems I most likely just reversed the polarity of one stepper coil. It's fine as it is now, but if there could be other explanations to the problem I'd love to hear those too. Thank you to those who answered already!

Did You try Your breadboard version fully moving the camera? Check and compare Your breadboard circuit and the PCB. Reversing the polarity of one stepper coil can do this.

I am completely stumped as to why this is. Have I reversed the polarity somewhere? Would that even give these results?

Clearly you have. :astonished:

Recurrent problem: "Nema 17 stepper motor" tells us absolutely nothing about the motor.

If you provide a link to it, we can determine its actual specification, but in general, swapping any two of the end terminals of a single winding will reverse the direction, but swapping the end terminals of both windings ("double reverse") will not change the direction.

If - presumably - it is a bipolar motor then it is easy to swap the terminals. If you mixed the terminals of one winding with another, or the end with the common terminals of a unipolar stepper, it likely would not work at all.

Why not just change the direction in your program?