Problem with runSpeed() AccelSteppers

Hi everyone. Im making a code that control two motors at different speeds. But, they’re all running at the same speed (the highest one).

stepperY.moveTo(instrucao.motores[Y].posicao);
        stepperX.moveTo(instrucao.motores[X].posicao);
        if(instrucao.motores[X].posicao - stepperX.currentPosition() < 0)
           stepperX.setSpeed(-instrucao.motores[X].frequencia);
       else stepperX.setSpeed(instrucao.motores[X].frequencia);
       if(instrucao.motores[Y].posicao - stepperY.currentPosition() < 0)
           stepperY.setSpeed(-instrucao.motores[Y].frequencia);
       else stepperY.setSpeed(instrucao.motores[Y].frequencia);
       Serial.println(instrucao.motores[Y].frequencia);
       while((stepperX.distanceToGo() != 0) || (stepperY.distanceToGo() != 0)) 
       {
           Serial.println(stepperX.distanceToGo());   
           Serial.println(stepperY.distanceToGo());
           if (stepperY.distanceToGo() == 0);
           else stepperY.runSpeed();
           if (stepperX.distanceToGo() == 0);
           else stepperX.runSpeed();     
       }
       Serial.println(stepperX.distanceToGo()); 
       Serial.println(stepperY.distanceToGo());
       stepperX.stop();
       stepperY.stop();

Can anyone help? The difference between speeds is really big (one is at 1000pps and the other 88pps). Thank you!

And the distance they have to go is really different too. One motor have to walk about 1134 and the other one 107 at the same time, thats why they have so different speed.

I find it much easier to read code when it is laid out like this - I suspect you will also. Use the AutoFormat tool

stepperY.moveTo(instrucao.motores[Y].posicao);
stepperX.moveTo(instrucao.motores[X].posicao);

if(instrucao.motores[X].posicao - stepperX.currentPosition() < 0) {
    stepperX.setSpeed(-instrucao.motores[X].frequencia);
}
else { 
    stepperX.setSpeed(instrucao.motores[X].frequencia);
}

if(instrucao.motores[Y].posicao - stepperY.currentPosition() < 0) {
    stepperY.setSpeed(-instrucao.motores[Y].frequencia);
}
else { 
    stepperY.setSpeed(instrucao.motores[Y].frequencia);
}

Serial.println(instrucao.motores[Y].frequencia);

while((stepperX.distanceToGo() != 0) || (stepperY.distanceToGo() != 0)) {
    Serial.println(stepperX.distanceToGo());   
    Serial.println(stepperY.distanceToGo());
    if (stepperY.distanceToGo() == 0) {
    }
    else { 
        stepperY.runSpeed();
    }
    if (stepperX.distanceToGo() == 0) {
    }
    else { 
        stepperX.runSpeed();     
    }
}

Serial.println(stepperX.distanceToGo());
Serial.println(stepperY.distanceToGo());
stepperX.stop();
stepperY.stop();

You are using runSpeed() all wrong.

It should be called from loop() as often as possible - hundreds or thousands of times per second. The library will stop the motor when it gets to its destination. There is normally no need to call stop().

One motor have to walk about 1134 and the other one 107 at the same time, thats why they have so different speed.

The AccelStepper library is specifically not suitable for that. Use the MultiStepper version, but note that it cannot use acceleration.

…R
Stepper Motor Basics
Simple Stepper Code

Thank you for the answer!
I took out the stepper.stop(), but the speeds are still the same.
I’ve tried using MultiStepper, but it doesnt work anyway.

       posicao[0] = instrucao.motores[X].posicao;
       posicao[1] = instrucao.motores[Y].posicao;
       steppers.moveTo(posicao);
       Serial.println(stepperX.distanceToGo());   
       Serial.println(stepperY.distanceToGo());
       if(instrucao.motores[X].posicao - stepperX.currentPosition() < 0)
                  stepperX.setSpeed(-instrucao.motores[X].frequencia);
       else stepperX.setSpeed(instrucao.motores[X].frequencia);
       if(instrucao.motores[Y].posicao - stepperY.currentPosition() < 0)
               stepperY.setSpeed(-instrucao.motores[Y].frequencia);
       else stepperY.setSpeed(instrucao.motores[Y].frequencia);
       while (stepperX.distanceToGo() != 0 || stepperY.distanceToGo() != 0)
       {
             Serial.println(stepperX.distanceToGo());   
             Serial.println(stepperY.distanceToGo());  
             steppers.run();
       }

The speeds are still the same :\

diegoalmeida:
I've tried using MultiStepper, but it doesnt work anyway.

That does not provide any useful information from which to help you.

You need to post the complete program. And I am NOT going to read it unless you have used the AutoFormat tool (or equivalent) to lay it out in a readable style.

...R