Go Down

Topic: Problem of using stepper motor 17HS4401 (Read 9755 times) previous topic - next topic

Scat

Hello, I've got a little problem regarding my stepper motor. I'm using Stepper Motor 17HS4401 with pololu A4988 driver and for the controller I'm using arduino Mega.

So, here is my problem. I want to test whether my motors are working correctly, so I'm using a simple code which is used to turn the motor left and right simultaneously. However, the motors only rotating on clockwise direction and sometimes randomly rotating counter clockwise. I've try several motors and several drivers and the result is still the same. The code itself is supposedly contained no error.

Here is the code I'm using:

Code: [Select]

const int stepPin = 3;
const int dirPin = 4;
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
}
void loop() {
  digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making two full cycle rotation
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
  }
  delay(1500); // One second delay
 
  digitalWrite(dirPin,LOW); //Changes the rotations direction
   //Makes 400 pulses for making two full cycle rotation
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
  }
 delay(1500);
}


Can anybody help me with this matter, please? Thank you very much

Robin2

Try this Simple Stepper Code

Post a link to the datasheet for your motor.

What power supply are you using for the motor (volts and amps).

Make a pencil drawing showing clearly how everything is connected and post a photo of the drawing. Don't worry if you are not an artist - crude but clear is fine.

...R
Stepper Motor Basics
Two or three hours spent thinking and reading documentation solves most programming problems.

Scat

Here's the link for my motors datasheet
http://www.datasheet4u.com/pdf/17HS4401-pdf/928661


For the power supply, I'm using a 12V 30A power supply.


While for the connection, I'm using the connection from the pololu website for A4988
https://www.pololu.com/product/1182


I tried your code, but my motors only vibrating, not rotating. I've tried to turn the potentiometer, but it still gives the same result. Why?

ouatsup

I tried your program everything is fine,
this is my program to test stepper motors

if you still have problems try to remove your dir wire

Code: [Select]

int cwccw = HIGH; //set to HIGH or LOW for clockwise, counter clockwise
int stp = 3;  //connect pin 3 to step
int dir = 4;  // connect pin 4 to dir
int Speed = 5000; //lower this number to find your best starting speed
int MaxSpeed = 500; //Lower this number to find your max speed
int accel = 1; //change this number to experiment different acceleration
//with 17HS4401 500=Speed and 100=MaxSpeed was my best result

void setup()
{
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
}

void loop()
{

  if (Speed == MaxSpeed)
  {
    digitalWrite(dir, cwccw);
    digitalWrite(stp, HIGH);
    delayMicroseconds(Speed);
    digitalWrite(stp, LOW);
    delayMicroseconds(Speed);
  }

  if (Speed > MaxSpeed)
  {
    digitalWrite(dir, cwccw);
    Speed = Speed - accel;
    digitalWrite(stp, HIGH);
    delayMicroseconds(Speed);
    digitalWrite(stp, LOW);
    delayMicroseconds(Speed);
  }

  else {
  }
}

Scat

#4
Mar 12, 2016, 04:53 am Last Edit: Mar 12, 2016, 05:06 am by Scat
@Ouatsup

Hello, thanks for your help. I've tried your code and here's is the problem which I encountered:

1. I'm using your default speed and max speed which is 5000 and 500, when I'm changing the direction from low  to high, I need to recalibrate the current by turning the potentiometer on the A4899 driver, is it common for a stepper motors to have different current different direction?

2. When changing the high to low for the direction, I need to upload it twice in order for the motor to change the rotation. Do you think my driver is broken?


Thanks

ouatsup

hi,
my a 4899 is set to 1A with 12v in and I never had any problem changing the direction.  Sorry I can't help you more than that.  For the second point it happens sometimes I tought it was my computer lol

Good luck with your project



MarkT

#6
Mar 12, 2016, 05:54 pm Last Edit: Mar 12, 2016, 05:55 pm by MarkT
@Ouatsup

Hello, thanks for your help. I've tried your code and here's is the problem which I encountered:

1. I'm using your default speed and max speed which is 5000 and 500, when I'm changing the direction from low  to high, I need to recalibrate the current by turning the potentiometer on the A4899 driver, is it common for a stepper motors to have different current different direction?
No, they are completely symmetrical.
Quote
2. When changing the high to low for the direction, I need to upload it twice in order for the motor to change the rotation. Do you think my driver is broken?

Something sounds very wrong.  Make sure to change the direction pin, delay for a few microseconds
before the next step pulse (digitalWrite() is actually slow enough to guarantee such a delay).  Note
that the step happens on the LOW to HIGH transition of the step pin, the other transition is irrelevant.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up