A4988 polulu 6 wires stepper motor inverting it's direction

Hello Guys,

Need help for a weird behaviour of the stepper motor.

I’m connecting a 6 wires stepper motor (0.9 degree MODEL 103-594-05xd03 ) by using a A4988 driver but when I used the code presented below a weird situation occures that for each movement the motor inverts it’s direction.

The tests I made and additional information:

1 - Made all the recommentations to use only 4 wires, 4 wires which are not the common wires (using the wires which have the higher resistance between them and not connecting the common wires).

2 - tested the same program for other stepper motor model and it works normally.

Same motor of the link (didn’t find a data sheet of it):

code :

// defines pins numbers
const int stepPin = 9; 
const int dirPin = 8; 


const int MS1Pin = 6; 
const int MS2Pin = 5; 
const int MS3Pin = 4; 

bool mode;
String input;
float pulses;
int MeioPeriodo  = 1000;
float PPR=400;
bool turnOnOff;


void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,INPUT_PULLUP);
  digitalWrite(MS1Pin, LOW);
  digitalWrite(MS2Pin, LOW);
  digitalWrite(MS3Pin, LOW);
  
  mode = HIGH;
  PPR = 400;
  turnOnOff=LOW;
  Serial.begin(9600);
}
void loop() {
        
          if(Serial.available()){
                input = Serial.readStringUntil('\n');
                
                if(input.equals("Z")){
                    turnOnOff = HIGH;
                }
                if(input.equals("X")){
                    turnOnOff = LOW;
                }
                         
              }
        
         if (turnOnOff == HIGH){
          
        
            digitalWrite(dirPin, HIGH);
        
            
            for(int x = 0; x < PPR; x++) {
              digitalWrite(stepPin, HIGH);            // Pulso nível baixo
              delayMicroseconds (MeioPeriodo);   // MeioPeriodo de X microsegundos
              digitalWrite(stepPin, LOW);           // Pulso nível alto
              delayMicroseconds (MeioPeriodo);   // MeioPeriodo de X microsegundos
              }
          Serial.print(dirPin);

          }
    delay(1000); 
}

Regards,

Bruno Oliveira

Try this Simple Stepper Code

...R
Stepper Motor Basics

it uses a simple loop with for function.

for(int x = 0; x < PPR; x++) {
              digitalWrite(stepPin, HIGH);            // Pulso nível baixo
              delayMicroseconds (1000);   // MeioPeriodo de X microsegundos
              digitalWrite(stepPin, LOW);           // Pulso nível alto
              delayMicroseconds (1000);   // MeioPeriodo de X microsegundos
              }
          Serial.print(dirPin);

The motor you linked is high impedance, with 85 Ohm coils, and not well suited for the A4988. Use your multimeter to measure the coil resistance of the motor you have, and tell us what that is.

Please post a hand drawn wiring diagram, and the details of your motor power supply (or a link to the product page).

To what value did you set the all-important current limit on the A4988?

jremington:
The motor you linked is high impedance, with 85 Ohm coils,

I must be missing something. The link says that it has a 2amp coil current and that suggests a coil resistance of the order of 5 ohms or less. The OP should measure the coil resistance with his multimeter.

Of course an A4988 will not be able to provide 2 amps. The OP would probably need a driver capable of providing 3 amps to have some headroom - perhaps a driver using a TB66xx chip.

...R

Solved, so how one pin was'nt receiving a signal.