Stepper Motor with Wire issues

Recently, I purchases a stepper motor from Spark fun, more specifically, “Stepper Motor with Wire”. I’m driving it with am a4988. I’m currently trying to build a 3d scanner with a garmin v3, sparkfun stepper motors, a4988, and an Arduino Uno. However, currently, my sparkfun stepper motors, which are driven by A4988, switch directions every step. I’m not sure why this issue occurs, and sometimes the stepper motors steps properly, but 95% of the time, the stepper switches direction every step. I’m currently micro stepping by 1/16, but when the oscillation occurs, it appears to be taken over 1 step every oscillation cycle. Here is a video of my issue: https://drive.google.com/file/d/1TFIVQr … sp=sharing. Here is my software, just in case it is a software issue.

#include <Wire.h>

#include <LIDARLite.h>

LIDARLite myLidarLite;

const int dirPinV = 2; // Direction

const int stepPinV = 3; // Step

const int dirPinH = 4; // Direction

const int stepPinH = 5; // Step

// Motor steps per rotation

void setup() {

Serial.begin(115200);

myLidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz

myLidarLite.configure(0); // Change this number to try out alternate configurations

// Setup the pins as Outputs

pinMode(stepPinV,OUTPUT);

pinMode(dirPinV,OUTPUT);

pinMode(stepPinH,OUTPUT);

pinMode(dirPinH,OUTPUT);

pinMode(8,OUTPUT);

pinMode(9,OUTPUT);

pinMode(10,OUTPUT);

pinMode(11,OUTPUT);

pinMode(12,OUTPUT);

pinMode(13,OUTPUT);

digitalWrite(8,HIGH);

digitalWrite(9,HIGH);

digitalWrite(10,HIGH);

digitalWrite(11,HIGH);

digitalWrite(12,HIGH);

digitalWrite(13,HIGH);

}

void loop() {

int maxStepV = 45*16;

int stepV = 1;

int maxStepH = 60*16;

int stepH = 1;

for (int x = 0; x < maxStepH; x = x + stepH*2)

{

// Set motor direction clockwise

digitalWrite(dirPinV,HIGH);

// Spin vertical

for(int v = 0; v <= maxStepV; v= v + stepV) {

digitalWrite(stepPinV,HIGH);

delayMicroseconds(500);

digitalWrite(stepPinV,LOW);

delayMicroseconds(500);

Serial.println(myLidarLite.distance(false));

}

// Pause for one second

delay(1000);

// Spin horizontal

digitalWrite(dirPinH,HIGH);

for(int hstep = 0; hstep <= stepH; hstep= hstep + stepH) {

digitalWrite(stepPinH,HIGH);

delayMicroseconds(10000);

digitalWrite(stepPinH,LOW);

delayMicroseconds(10000);

}

myLidarLite.distance(true);

// Pause for one second

delay(1000);

// spin vertical

digitalWrite(dirPinV,LOW);

// Spin motor two rotations quickly

for(int v = 0; v <= maxStepV; v= v + stepV) {

digitalWrite(stepPinV,HIGH);

delayMicroseconds(500);

digitalWrite(stepPinV,LOW);

delayMicroseconds(500);

Serial.println(myLidarLite.distance(false));

}

// Pause for one second

delay(1000);

// Spin horizontal

digitalWrite(dirPinH,HIGH);

for(int hstep = 0; hstep <= stepH; hstep= hstep + stepH) {

digitalWrite(stepPinH,HIGH);

delayMicroseconds(10000);

digitalWrite(stepPinH,LOW);

delayMicroseconds(10000);

}

myLidarLite.distance(true);

// Pause for one second

delay(1000);

}

}

I am powering my stepper with 4s lion battery.

It wouldn’t be your steppers, they can’t just change direction on their own. Gotta be your driver, connections or something in your code.