I am trying to achieve a sine position movement with the Pololu Tic T825 stepper motor driver.
Which is the best way to achieve this? Now i am talking to the driver with an Arduino Mega 2560 via Serial Communication.
Should I loop over positions (with the Arduino) the stepper motor has to achieve? Therefore I think I should change to Teensy, because I does not get a smooth movement.
Or should I change the acceleration and speed within an while loop to get the desired maximal distance?
Or is the serial communication not the right choice and I should communicate via Step/Dir or else?
In general if you have position as a function of time you can convert this to step pulses by repeatedly calculating the current intended number of steps and comparing to actual step position:
void loop ()
{
static int current_position = 0 ;
int intended_position = int (round (40 * sin (millis() / 1000.0)) ; // or whatever function you want
while (intended_position != current_position) // check if a step is due
{
bool direction = intended_position > current_position ; // determine direction
digitalWrite (direction_pin, direction) ;
digitalWrite (step_pin, HIGH) ; // pulse one step
delayMicroseconds (10) ;
digitalWrite (step_pin, LOW) ;
current_position += direction ? +1 : -1 ; // update current position
}
}