Hi I could really do with some advice on the following.
I have built a simple two link X,Y plotter powered by two stepper motors, one at the shoulder, a nema 17 (200 step per rev) and one at the elbow 28BYJ-48 (2038 steps per rev). I am controlling them using an Adafruit Motorshield V2, attached to a Arduino Mega 2560. I am trying to get both motors to turn a different number of steps, but to start and finish together so,that the arm they are controlling can draw a straight line on an X,Y coordinate. I have been trying to use the Accel library, but cant achieve this, either the steps are shared alternately producing a zigzag out put, or as with my latest attempt (see code below) result in only one step each with the higher stepping motor working alone at the end. How can I overcome this?
#include <Wire.h>
#include <AccelStepper.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS; // Default address, no jumpers
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(2038, 1);// 28BYJ-48
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(200, 2);// Nema 17
void forwardstep1() {
myStepper1->step(FORWARD, SINGLE);
}
void backwardstep1() {
myStepper1->step(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {
myStepper2->step(FORWARD, SINGLE);
}
void backwardstep2() {
myStepper2->step(BACKWARD, SINGLE);
}
// wrap the steppers in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);
// Used to establish starting position
long Travel1; // for stepper1
long Travel2; //for stepper2
void setup()
{
AFMS.begin(); // Start the shield
Serial.begin(9600);
stepper1.setMaxSpeed(500.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(200); // number of steps for stepper1
stepper2.setMaxSpeed(500.0);
stepper2.setAcceleration(500.0);
stepper2.moveTo(10); // number of steps for stepper2
}
void loop()
{
stepper1.run();
stepper2.run();
Serial.print("stepper1.distanceToGo ");
Serial.println(stepper1.distanceToGo());// Used to monitor stepper1 progress
Serial.print("stepper2.distanceToGo ");
Serial.println(stepper2.distanceToGo()); // Used to monitor stepper2 progress
//delay(1000); // delay for monitoring purposes
// return to starting position
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(Travel1);
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(Travel2);
}