Help with Using accelStepper to run multiple steppers with user input

Hello, I need some help with this code. I am trying to use accelStepper to run multiple steppers at the same time and uses the serial monitor to determine the steps for each stepper. I also have a problem with imputing a large value of steps like the number 1000000. The code is below and I have added another block of code that works, but does not have the user input that I’m trying to do for the steps.Thank you.
-WilliamN

accelStepper URL accelStepper

#include <MultiStepper.h>
#include <AccelStepper.h>

//Stepper pins
AccelStepper stepperX(AccelStepper::DRIVER, 3, 5);
AccelStepper stepperZ(AccelStepper::DRIVER, 6, 9);

String in;
int myNumber = 0;
int val;
int motor1_steps = 0;
int motor2_steps = 0;
char c;
String Command;




void setup()
{  
   Serial.begin(115200);
   stepperX.setMaxSpeed(1417.0);
   stepperX.setAcceleration(500.0);
   
   stepperZ.setMaxSpeed(1417.0);
   stepperZ.setAcceleration(500.0);
   
}
void loop(){

 //if (stepperX.isRunning()== false && stepperZ.isRunning()== false){
Serial.println(stepperX.isRunning());
Serial.println(stepperZ.isRunning());
 Serial.println("Imput# xSteps");
 while(!Serial.available());
 in=Serial.readStringUntil('\n');
 if(in!="")
   motor1_steps=in.toInt();
   Serial.println(motor1_steps); 
   stepperX.moveTo(motor1_steps);
   
 Serial.println("Imput# zSteps");
 while(!Serial.available());
 in=Serial.readStringUntil('\n');
 if(in!="")
  motor2_steps=in.toInt();
  Serial.println(motor2_steps);
  stepperZ.moveTo(motor2_steps);
 RunStepper();
 Serial.println("DONE");
 
//if (stepperX.isRunning()== true && stepperZ.isRunning()== true){
//if(Serial.available()>0){
//  Command = Serial.readString();
//  if(Command = "stop" || "STOP" || "Stop");
//    stepperX.stop();
//    stepperZ.stop();
//}
//}
}
void RunStepper(){
 stepperX.run();
 stepperZ.run();
}

CODE THAT WORKS

#include <MultiStepper.h>
#include <AccelStepper.h>
//Stepper pins
AccelStepper stepper1(AccelStepper::DRIVER, 3, 5);
AccelStepper stepper2(AccelStepper::DRIVER, 6, 9);

void setup()
{  
   stepper1.setMaxSpeed(100.0);
   stepper1.setAcceleration(10.0);
   stepper1.moveTo(10000);
   
   stepper2.setMaxSpeed(100.0);
   stepper2.setAcceleration(10.0);
   stepper2.moveTo(10000);
   
}
void loop()
{
   // Change direction at the limits
   if (stepper1.distanceToGo() == 0)
       stepper1.moveTo(-stepper1.currentPosition());
   stepper1.run();
   stepper2.run();
}

Stepper_XZaxis.ino (1.37 KB)

Stepper_Simple_XZaxis.ino (580 Bytes)

I also have a problem with imputing a large value of steps like the number 1000000.

You can't store that big a number in a sixteen bit int.

Please remember to use code tags when posting code

To make it easy for people to help you please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

The MultiStepper library does not use acceleration, but, from what I can see your code does not use that library. The purpose of the MultiStepper library is to enable a number of motors to be controlled in a coordinated way - for example MotorA does 137 steps in the same time that MotorB does 293 steps. If you don’t need that coordinated control then just use the regular AccelStepper library.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with ‘\0’ (NULL).

Don’t use Serial.readString() as it blocks the Arduino and may interfere with the stepping of your motors.

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

Rather than send “Stop” just send ‘S’. Single character commands will make the Arduino program much simpler.

…R
Stepper Motor Basics
Simple Stepper Code