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.
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.
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
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.
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.
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.