A td6600 controller is not a good choice for a pi as you will need to level convert the control signals, much better to use (for a basic stepper controller like this) one of the A4988 family which use the same logic levels as the pi, so can be driven directly from gpio pins. Also these controllers allow logic level control of the number of microsteps, rather than dip switches. generally you will need to reduce the number of microsteps as the overall motor speed increases. They also have much finer control of current limiting.
While python code cannot provide super accurate / reliable timing directly driving gpio pins, a package like pigpio can easily do this by using DMA to drive the pins, although this makes the software more complex.
If you want to use a microcontroller to offload the detailed work from the pi, then why not use a dedicated microcontroller based stepper driver like one of the tmc
familly of chips?
A premounted chip on a development board (like this one
) can interface directly to a raspberry pi and provides superb control of the stepper with ramp up / down, current limiting and even stall detection.
btw you might get on better posting these questions in the automation forum
Also you can remove some of the variability of timing by checking the time in the loop like this:
Code: Select all
ticktime=.01 #for 100 per second
ticksleft=5000 # how many ticks to issue
while ticksleft > 0:
pio.gpio_trigger(pin, pulse, level) # pigpio can issue a pulse in a single call
ticksleft -= 1
if sleeptime > 0: