Joystick and speedystepper

hello I am trying to control two stepper motors using an Arduino Uno, a joystick and DRV8822 drivers I absolutely have to use the speedystepper library for the high speed options and the acceleration and deceleration
I have tried a lot of methods but I can't get anywhere do you have any leads because I don't know what to do anymore

it should be simple I have already done it with other libraries but with this one I can't do anything if someone has already done something like this I come to your aid

Please post the working solution that used other libraries.

Please post your attempt to use the library you must and elaborate on the difficulties - post error message if it fails to verify, describe the misbehaviour(s) if it runs.

a7

here is my attempt with this library sorry for the other libraries I did it a long time ago I have no more projects

#include <SpeedyStepper.h>

#define MOTOR1_STEP_PIN 2
#define MOTOR1_DIR_PIN 5
#define MOTOR2_STEP_PIN 3
#define MOTOR2_DIR_PIN 6

#define JOYSTICK_X_PIN A1
#define JOYSTICK_Y_PIN A0

#define JOYSTICK_THRESHOLD 250
const int MAX_MOTOR_SPEED = 12500;

SpeedyStepper motor1;
SpeedyStepper motor2;
 int targetDirection1= 0;
void setup() {
    motor1.connectToPins(MOTOR1_STEP_PIN, MOTOR1_DIR_PIN);
    motor2.connectToPins(MOTOR2_STEP_PIN, MOTOR2_DIR_PIN);
Serial.begin(9600);
    motor1.setAccelerationInStepsPerSecondPerSecond(10000);
    motor2.setAccelerationInStepsPerSecondPerSecond(10000);
}

void loop() {
    int xValue = analogRead(JOYSTICK_X_PIN);
    int yValue = analogRead(JOYSTICK_Y_PIN);

    int centeredX = xValue - 512;
    int centeredY = yValue - 512;

    // Contrôle du moteur 1 avec arrêt forcé si dans la zone morte
    if (abs(centeredX) > 10) {
        
        motor1.setSpeedInStepsPerSecond(abs(1000));
        motor1.setTargetPositionRelativeInSteps(50000);
    } else {
        // Forcer l'arrêt en réinitialisant la position cible
       // motor1.setTargetPositionInSteps(motor1.getCurrentPositionInSteps());
        motor2.setTargetPositionToStop();
    }

    // Contrôle du moteur 2 avec arrêt forcé si dans la zone morte
    if (abs(centeredY) < -10) {
        
        motor2.setSpeedInStepsPerSecond(abs(1000));
        motor2.setTargetPositionRelativeInSteps(50000);
    } else {
        // Forcer l'arrêt en réinitialisant la position cible
        //motor2.setTargetPositionInSteps(motor2.getCurrentPositionInSteps());
        motor2.setTargetPositionToStop();
    }
Serial.println(centeredX);
    // Processus de mouvement pour les deux moteurs
    motor1.processMovement();
    motor2.processMovement();
}

Will this ever be true?

Is that your issue?

Or is it that you are using the blocking commands and are only able to re-read the joystick after it moves 50000 steps.

Maybe look into the non-blocking moves if you want to react to a stop before 50000 steps.

And furthermore....

Those "setTargetPosition*" commands don't with the current SpeedyStepper library.

And that first conditional block states motor1 but stops motor2.

And the SpeedyStepper library at GitHub - Stan-Reifel/SpeedyStepper: Stepper motor control library for Arduino doesn't have an up-to-date proper release tag, so by default it gives an error unless you apply this change:

And the GitHub - Stan-Reifel/SpeedyStepper: Stepper motor control library for Arduino library doesn't have "Issues" enabled to report library errors such as these.

Maybe try one of the more developed other acceleration libraries.

ok maybe i'll try to change library.
do you know another library that can handle high speeds and accelerations?

How high is high? Maybe switching to faster hardware would be enough?

Maybe MobaTools? FastAccelStepper?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.