ENA, DIR and PUL are all driven active LOW
The TB6600 only cares about the direction pin at the time of the rising edge of the pulse signal, so it can stand twiddling the DIR signal at other times. If you send an A+B quadrature signal into the PULSE+DIR lines, it will step CW in one direction and CCW in the other direction.
For example:
It is 1/4 the speed because stepper.h needs a 4 step(1) commands to make a full cycle on STEP/PULSE
It looks like you are toggling the dir pin in between the toggling of the pulse pin. The driver is going to check the state of the dir pin only at the time that the Pulse pin goes high, so it won't care that DIR rises and falls while the PULSE pin is high.
And perhaps the nominal 1000Hz is too fast for your motor to start up, or the LOW portion of the PULSE pin is too short for the driver to detect.
It will be perhaps be fixed by setting the DIR pin before you raise the PULSE pin and by adding a delay between pulses.
int drive(int pul,int dir){ //function to drive motor one step
digitalWrite(dir,HIGH);
digitalWrite(pul,HIGH);
delayMicroseconds(500);
digitalWrite(pul,LOW);
digitalWrite(dir,LOW);
delayMicroseconds(500);
return ;
}
That's what I suppose. And as already stated, creating a pulse at the DIR line is definitely wrong.
if the direction pin is HIGH on one pulse rising edge and LOW on the next, won't the motor just be driven back-and-forth.
might be best to toggle the pulse pin very slowly (e.g. 100 msec).
set the direction once, and make sure the enable pins enable the motor
Of course....But how do you get to that without changing directions cycling through the table? (e.g. step(-1) vs step(1))
Consider the 2nd column of that table as STEP and the 3rd as DIR. Cycling forward through the table STEP rises at the 1->2 transition, when DIR is HIGH. You only get STEP rising when DIR is LOW on the 4->3 transition when you are cycling backwards through the table.
This is the correct answer. OP is caught in a side track discussion but the main issue is that this library is not good and should not be used for projects that need to do anything besides driving a single stepper motor.
drawline(angle, length)
bresenham-algorithm is the best solution
any angle can be transformed into a X-Y-ratio
m = tan ( dy / dx)
You need to drive two steppermotors which represent X-Axis and Y-Axis anyway.
Are you sure that you want to have input-data angle and length?
Wouldn't it be easier to use X-Y-Coordinates?
To drive two stepper-motors in a synchronised way you use
one single for-loop where inside this one single for-loop the pulses for both stepper-motors are created.
There will be always one axis that is faster (or equal) to the second axis
The faster axis becomes the "leader" which increments one step with each iteration
the slower axis increments only if counting a number smaller than 1.0000 changes in the digit left of the decimal-point
example
x shall do 10 steps
y shall do 4 steps
ration 4/10 = 0.4
x = 0
dx = dx + 1 (result)
y = 0
dy = dy + 0.4 ( 0.4) => no change of the left digit => no Y-step-pulse
x = 1
dx = dx + 1 (result 2)
y = 0.4
dy = dy + 0.4 ( result 0.8) => no change of the left digit => no Y-step-pulse
x = 2
dx = dx + 1 (result 3)
y = 0.4
dy = dy + 0.4 ( result 1.2) => CHANGE of the left digit => create step-pulse on Y-axis
x = 3
dx = dx + 1 (result 4)
y = 0.4
dy = dy + 0.4 ( result 1.6) => no change of the left digit => no Y-step-pulse
x = 4
dx = dx + 1 (result 5)
y = 0.4
dy = dy + 0.4 ( result 2.0) => CHANGE of the left digit => create step-pulse on Y-axis
This is what the code in the WOKWI-Simulation in post # 16 is doing for 6 axis
You only need two axis
