I am recently working on a NEMA 17 bipolar stepper motor and I am using the TB6560 driver. The problem is that the motor does not rotate only one complete revolution for 200 steps. Instead, it is rotating clockwise as long as it is powered by the 12V supply.
digitalWrite(MOTORDIR1, LOW); // HIGH Enables the motor to move in a particular direction CW
for (int x = 0; x < 1000 ; x++) {
digitalWrite(MOTORSTEP1, HIGH);
delayMicroseconds(T);
digitalWrite(MOTORSTEP1, LOW);
delayMicroseconds(T);
}
}
You have posted a new question in an old Thread and your question is about a different type of stepper motor so I have suggested to the Moderator to move you to your own Thread.
nurkhan:
The problem is that the motor does not rotate only one complete revolution for 200 steps. Instead, it is rotating clockwise as long as it is powered by the 12V supply.
I see two problems.
First, your code is asking the motor to do 1000 steps rather than 200.
Second, because the code is within loop() as soon as the 1000 steps are complete it starts another 1000.
If you want it to stop moving after N steps then you need a variable to keep track of whether it has completed the move or not. For example suppose you create a global variable
bool motorMoveDone;
then in setup() you can set it to false to start things off
motorMoveDone = false;
and your code to do the steps can then check that value
if (motorMoveDone == false) {
for (int x = 0; x < 200 ; x++) {
digitalWrite(MOTORSTEP1, HIGH);
delayMicroseconds(T);
digitalWrite(MOTORSTEP1, LOW);
delayMicros
}
motorMoveDone = true;
}
It is customary on this forum (and very helpful to others) to use code tags.
[code]your code here[/code]
Reason for edit: There was an error when the topic was split and I did not know Robin2 replied already. His reply is more in depth (and more accurate). I wouldn't have replied at all if I had known about it.