Trying to use Serial USB port with Arduino Uno to control 2 stepper motors.

I've been searching endlessly for ways to precisely control stepper motors with user input. Currently trying with AccelStepper.h library and Serial.available() function. Attaching a tentative code below but ANY other suggestions are very very welcome! (Objective: rotate to specific degree points, CW and CCW, depending on input values. Within a range of 180º (not full revolutions)). Using Easy Driver and 2phase bipolar stepper motors. This code seems simple enough but motors just don't seem to be moving. Any fixes/suggestions??

#include <AccelStepper.h>
const int stepsRev = 200;

// Define steppers and pins
AccelStepper stepper1(stepsRev,2,3); // Defaults to AccelStepper::FULL4WIRE
AccelStepper stepper2(stepsRev,9,10);

int x = 0;
int y = 0;

void setup() {
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(x);

stepper2.setMaxSpeed(200.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(y);

Serial.begin(9600);

// Serial.setTimeout(10);
}

void loop() {

while (Serial.available() != 0) {

x = Serial.parseInt();
y = Serial.parseInt();
Serial.println(x);
Serial.println(y);
}
stepper1.moveTo(x); //if input is negative, motor should move backwards?
stepper2.moveTo(y);
stepper1.run();
stepper2.run();

}

Robin's updated serial input basics might give you ideas.

The problem with parseInt() is that it's a blocking function; it will read characters till it finds a non-digit or till it times out (serial communication is slow compared to the performance of the Arduino)

Please read How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum, specificaly point #7 about posting code; next edit your post and add the code tags.

Hi msmech,

first of all use the "reply-button" for futere replies. This will guide you to featured texteditor where you can insert code well formatted by simply clicking on the "Code" button.

For the accelStepper-library there are some examples. I recommend starting with this examples.
Especially the example "bounce" which moves a stepper-motor forward and backward a certain amount of steps endlessly.

There are so many factors involved that could cause non-functioning that you should reduce these factors as much as possible. So using a code-example that is known for functioning well is one way to do that. Maybe the reason is just a not connected "enable"-input on your hardware. Then ANY code would NOT run your steppermotor.

If you write something about what you want to do in the end

much better suggestions can be made.

best regards

Stefan