I am working a project requiring two stepper motors running at the same time. One runs in fixed direction and speed and the other will run at a slower speed and will reverse at the end of travel.
The AccelStepper library works for these requirements, but there is an issue when reversing the slower motor. The below code is one of the examples for AccelStepper and it drives the motors as needed. I have set up stepper 1 to run 5 rotations(1/4 stepping, 800 steps=stepper1. moveTo(4000). When the motor makes 5 revolutions it reverses as expected the first time, but after the first reversal all future reversals make 10 revolutions before reversing. I expected the code to reverse and make the same number of revolutions in the opposite direction. I can't really see any problem with the code. Thanks for any insight anyone can provide. I am using an UNO and 8825 drivers.
// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
// Define some steppers and the pins the will use
AccelStepper stepper1=AccelStepper(1, 7, 8); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2=AccelStepper(1, 9, 10);
AccelStepper stepper3(AccelStepper::FULL2WIRE, 12, 11);
void setup()
{
stepper1.setMaxSpeed(200.0);
stepper1.setAcceleration(1000.0);
stepper1.moveTo(4000);
stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(1000000);
stepper3.setMaxSpeed(300.0);
stepper3.setAcceleration(100.0);
stepper3.moveTo(1000000);
delay(2000);
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
stepper2.run();
stepper3.run();
}