Hello all! I have written some Arduino code to turn 2 stepper motors from a serial input.
Right now it works if I enter a comma separated pair of steps into the serial monitor (i.e. 1000,1000).
My issue is that if I enter more than one "pair" of angles (i.e. 1000,1000,2000,2000), it will only execute for the "final pair" (2000,2000 in this example).
My endgame is to use python to send about 2000 pairs of angles stored in a csv through serial, but I'm facing the same problem of only the last pair being used.
My code is below, and there is some more info in my previous two posts (thanks to everyone who commented on those, I truly appreciate the help).
https://forum.arduino.cc/index.php?topic=735638.new#new
https://forum.arduino.cc/index.php?topic=733014.new#new
Thanks for any help and for taking the time to read!
#include "AccelStepper.h"
AccelStepper pitch(1,6,5);
AccelStepper yaw(1,11,10);
long pitchangle;
long yawangle;
int finish = 1;
void setup() {
Serial.begin(9600);
pitch.setMaxSpeed(500.0);
pitch.setAcceleration(500.0);
yaw.setMaxSpeed(500.0);
yaw.setAcceleration(500.0);
}
void loop() {
while (Serial.available()>0) {
finish = 0;
pitchangle = Serial.parseInt();
Serial.print(pitchangle);
Serial.print("Pitch Angle, ");
yawangle = Serial.parseInt();
Serial.print(yawangle);
Serial.print("Yaw Angle, ");
pitch.move(pitchangle);
yaw.move(yawangle);
Serial.print("Moving...");
}
if ((pitch.distanceToGo() != 0) || (yaw.distanceToGo() != 0)){
pitch.run();
yaw.run();
}
if ((finish == 0) && (pitch.distanceToGo() == 0) && (yaw.distanceToGo() == 0)) {
Serial.println("Done");
finish =1;
}
}