I have a problem with using the a4988 and this library.
I am trying to set adjustable speed based on a variable that i change with encoder, i initialized it, enabled it and set rpm with a variable that i change and then stepper.Move command that moves the stepper a certain number of steps, but the problem is when move command is executed everything else gets blocked until the stepper moves, and if i set it to a low value like 10 it still blocks the code and produces more vibrations, so i'm not really sure how to solve this, i also searched for closed issues with the library where someone already asked how to make this but didn't get a definite answer. Would really appreciate if someone would give me some tips or some example working code.
Look at the Non-Blocking example that comes with the library. You call the "nextAction()" function as often as you can and it tells you how much time you have until the next step. In that time you can do whatever you want. In the example, they check that there are at least 100 microseconds available before they do other operations. You can tell when the move is complete because it returns 0 microseconds to the next step.
// motor control loop - send pulse and return how long to wait until next pulse
unsigned wait_time_micros = stepper.nextAction();
// 0 wait time indicates the motor has stopped
if (wait_time_micros <= 0) {
stepper.disable(); // comment out to keep motor powered
delay(3600000);
}
// (optional) execute other code if we have enough time
if (wait_time_micros > 100){
// other code here
}
Yeah i tried it but it messes up with motor rotations and i'm not sure how to use it correctly
my code:
// motor control loop - send pulse and return how long to wait until next pulse
unsigned wait_time_micros = stepper.nextAction();
// 0 wait time indicates the motor has stopped
if (wait_time_micros <= 0)
{
stepper.startMove(100 * MOTOR_STEPS * MICROSTEPS);
}
// (optional) execute other code if we have enough time
if (wait_time_micros > 5000)
{
function1();
function2();
function3();
}
would really appreciate some extra hep because i tried everything but it still doesn't work, so if i get this non blocking example correctly i set how many steps it will make and then during that time other function can be executed?
I don't use any delays in my code btw.
How many microseconds does each of these three functions take?