Controlling a big stepper motor

zeus2kx:
I also tried your Simple Stepper Code but it doesn't rotate the motor.
What is wrong?

You need to post the exact code that you uploaded to your Arduino so I can compare it with your code that works.

My code does not write to the Enable pin - for many drivers it is not necessary. Maybe it is for the one you have.

...R

Thanks Robin,
Just to add, test code I pasted earlier only works when DIP switches are set for microstep 32.
Same code doesn't work if the microstep is different than 32.
I tried microstep 1 with:

for (int i=0; i<200; i++)

Code didn't work.
I can't seem to understand the reason.

Robin2:
You need to post the exact code that you uploaded to your Arduino so I can compare it with your code that works.

My code does not write to the Enable pin - for many drivers it is not necessary. Maybe it is for the one you have.

...R

Alright, after I posted my last reply, I tried to set micro step to 1 and slightly modified your code: (snippet where I made changes)

byte directionPin = 5;
byte stepPin = 6;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 200;  // microseconds
int millisbetweenSteps = 20; // milliseconds - or try 1000 for slower steps

This code moved the motor but certainly had some jitter.

Please suggest how can I smoothly rotate this motor.

Just to add, similar to my previous project, I would like to add 4 buttons (FWD, REV, EN/DIS & REST), POT for speed control and also control through serial.

Thanks a lot.

Z

zeus2kx:
Alright, after I posted my last reply, I tried to set micro step to 1 and slightly modified your code: (snippet where I made changes)

Please suggest how can I smoothly rotate this motor.

You are making it very difficult (and time wasting) when you won't post the complete program like I requested in Reply #9

Try making the motor move at a very slow speed - say 500 millis between steps

There should be no need for a long pulse width - the TB6600 datasheet says the minimum pulse requirement is 2.2µsecs so I would just use 10µsecs.

...R

Robin2:
You are making it very difficult (and time wasting) when you won't post the complete program like I requested in Reply #9

Like I said I didn't make any changes apart from the snippet I posted.
Anyways here is the code:

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 200;  // microseconds
int millisbetweenSteps = 20; // milliseconds - or try 1000 for slower steps


void setup() { 

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
 
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    // delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
}

void loop() { 
}

What DIP switch setting should I apply for your code?

Robin2:
Try making the motor move at a very slow speed - say 500 millis between steps

There should be no need for a long pulse width - the TB6600 datasheet says the minimum pulse requirement is 2.2µsecs so I would just use 10µsecs.

...R

I will test these changes in the evening and update you.

Z

zeus2kx:
Anyways here is the code:

You seemed to have changed my version

int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps

to this

int pulseWidthMicros = 200;  // microseconds
int millisbetweenSteps = 20; // milliseconds - or try 1000 for slower steps

That is completely illogical. What did you hope to achieve with that? If I understand what you were thinking it makes it easier to help.

What DIP switch setting should I apply for your code?

When I wrote the code I assumed single steps, but it should produce movement with any setting.

...R

Robin2:
You seemed to have changed my version

This is exactly what I mentioned in reply #10.

Robin2:
That is completely illogical. What did you hope to achieve with that?

I see what you mean but these numbers came from testing the code.I was changing number to make the motor run smoothly, which I eventually saw.
Using both parameters you have in your code:

int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps

I wasn't able to move the motor.

How is the driver wired to the Arduino?

zeus2kx:
Using both parameters you have in your code:

int pulseWidthMicros = 20;  // microseconds

int millisbetweenSteps = 250; // milliseconds - or try 1000 for slower steps



I wasn't able to move the motor.

I can't understand why the changes you made improved matters.

You made two changes. Which of them was the important one?

When you are trying to debug a problem NEVER change more than 1 thing at a time.

I have just noticed (prompted by @outsider's question) that the code in Reply #8 uses pins 5 and 6 whereas the code in Reply #12 uses pins 9 and 8. Both can't be right unless you have been messing with the wiring.

...R

outsider:
How is the driver wired to the Arduino?

Exactly like this.
Only the pins are different.
Code on this page works but ONLY when DIP switches are set to 1/32th.
If I change the DIP settings, I hear tones.

Robin2:
You made two changes. Which of them was the important one?

Actually both.
This evening I retest and post some parametric results.

You're using HIGH true code with a LOW true connection.

outsider:
You're using HIGH true code with a LOW true connection.

Kindly elaborate.

If PUL+, ENA+ and DIR+ are connected to +5V and PUL-, ENA- and DIR- are wired to the output pins, that's LOW true, the input to the drive is active when the pin is pulled LOW, try changing your program logic to match. I'm not sure how ENA works, just leave it disconnected for now, set microsteps to 1 (200) and try.

Do you mean this:

int PUL=7; //define Pulse pin
int DIR=6; //define Direction pin
void setup() {
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);

}

void loop() {
  for (int i=0; i<6400; i++)    //Forward 5000 steps
  {
    digitalWrite(DIR,LOW);
    digitalWrite(PUL,LOW);
    delayMicroseconds(50);
    digitalWrite(PUL,HIGH);
    delayMicroseconds(50);
  }
  for (int i=0; i<6400; i++)   //Backward 5000 steps
  {
    digitalWrite(DIR,HIGH);
    digitalWrite(PUL,LOW);
    delayMicroseconds(50);
    digitalWrite(PUL,HIGH);
    delayMicroseconds(50);
  }
}

Does that make the motor step?

I can't check now, only in the evening when I get back home.

If that works, leave ENA disconnected and try this (make sure pin connections are correct):

byte pulWidth = 20;
uint32_t intervalFwd = 15000,
         intervalRev = 300; 

int PUL=7; //define Pulse pin
int DIR=6; //define Direction pin
//int ENA=5; //define Enable Pin
void setup() {
  pinMode (PUL, OUTPUT);
  pinMode (DIR, OUTPUT);
  //pinMode (ENA, OUTPUT);

}

void loop() {
  for (int i=0; i<200; i++)    //Forward 200 steps
  {
    digitalWrite(DIR,LOW);
    //digitalWrite(ENA,HIGH);
    digitalWrite(PUL,HIGH);
    delayMicroseconds(pulWidth);
    digitalWrite(PUL,LOW);
    delayMicroseconds(intervalFwd);
  }
  for (int i=0; i<200; i++)   //Backward 200 steps
  {
    digitalWrite(DIR,HIGH);
    //digitalWrite(ENA,HIGH);
    digitalWrite(PUL,HIGH);
    delayMicroseconds(pulWidth);
    digitalWrite(PUL,LOW);
    delayMicroseconds(intervalRev);
  }
}

Then work on microsteps, etc.
EDIT: Just remembered max delayMicroseconds is 16383, changed intervalFwd from 300000 to 15000. :stuck_out_tongue:

Great, thanks.
I will do that and get back to this thread in the evening.

If this doesn't work, I am going to dump this driver and use ST-M5045.

It'll work. :slight_smile:

I hope so :confused:
Once this works, i will figure out how to enable/disable.
Motor wire gets hotter when powered.

Then add some buttons and pot.

Long way to go.