Cheers for the guidance, have been trying today to implement your suggestions and this is what I have changed it to.
#include <AccelStepper.h>
AccelStepper stepper1(AccelStepper::FULL4WIRE, 5, 6, 7, 8); //Sets up the pins for stepper one
AccelStepper stepper2(AccelStepper::FULL4WIRE, 9, 10, 11, 12); //Sets up the pins for stepper two
int start_var = 0;
int movement = 360;
long newStepper1Pos = 0; // varialbe for the new stepper position for variable 1
long newStepper2Pos = 0; // variable for the new stepper position for variable 2
void setup()
{
Serial.begin(9600);
stepper1.setMaxSpeed(200.0); //Sets the max speed for stepper 1
stepper1.setAcceleration(100.0); //Sets the acceleration for stepper 1
stepper1.moveTo(movement);
stepper2.setMaxSpeed(200.0); //Sets the max speed for stepper 2
stepper2.setAcceleration(100.0); //Sets the acceleration for stepper 2
stepper2.moveTo(movement);
}
char inBuffer = "";
void loop()
{
if(Serial.available()>0) // If any information is avaiable coming from the serial monitor
{
inBuffer = Serial.read(); // Puts the information coming from the serial monitor in the input buffer
}
if (inBuffer == 'a') // If the command sent is an 'a'
{
Serial.println("test point 1"); //Serial print for test point 1
if (stepper1.distanceToGo() == 0)
newStepper1Pos = -stepper1.currentPosition;
stepper1.moveTo(newStepperPos);
if (stepper2.distanceToGo() == 0)
newStepper2Pos = -stepper2.currentPosition;
stepper2.moveTo(newStepperPos);
}
stepper1.run();
stepper2.run();
inBuffer = ""; //Sets the input buffer back to nothing as to not create a loop
}
I am getting an interesting error message in the form of "wrong type argument to unary minus" which I don't really know what it means.
I tried setting the moveTo() equal to zero so that maybe when the program moved, it wouldn't move until a command was sent, however this just resulted in no movement what so ever.
stepper1.setMaxSpeed(200.0); //Sets the max speed for stepper 1
stepper1.setAcceleration(100.0); //Sets the acceleration for stepper 1
stepper1.moveTo(0);
stepper2.setMaxSpeed(200.0); //Sets the max speed for stepper 2
stepper2.setAcceleration(100.0); //Sets the acceleration for stepper 2
stepper2.moveTo(0);
I am looking through the functions that come with this library to see if there is a way of just setting an initial start point for the servo motors so that they can always start from the same position. Thanks again for the help!