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);
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();
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)
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