Hello Members,
I have been searching the Adafruit forum (Motor Shield V2), for methods
to use the AccelStepper lib with the Motor Shield V2 - I have seen on post
where the alternate constructor is used more or less in the code below. Another post in the Adafruit forum, said "We do not use the AccelStepper Library much here,
go to the AccelStepper forum" so here I am.
Using the code below I am unable to control the direction I want to motor to move, and it steps in a direction (according to the constructor func), one step at a time.
I wanted to add some acceleration to a program that uses the motor shield exclusively.
That program moves the motor (either left or right according to which button is pushed), hits a limit switch, backups
a little and stops. The a left or right button can be pushed, the motor moves in the opposite direction until it hits limit switch
at the other "end". I use a pot to vary the speed of the motor. I was thinking I would like to add some
acceleration to the start of the motor movement, and maybe deceleration which the limit switch is hit.
Can I use the combination of the AccelStepper library and the Adafruit Motor shield this way?
I am open to suggestions and code hints.
thanks,
eholz1/ewholz
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
// AccelStepper Code
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep1() {
myMotor->onestep(BACKWARD, DOUBLE);
}
void backwardstep1() {
myMotor->onestep(FORWARD, DOUBLE);
}
AccelStepper Astepper1(forwardstep1,backwardstep1); // Alternate constructor
void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
Astepper1.setMaxSpeed(200.0);
Astepper1.setAcceleration(100.0);
Astepper1.moveTo(324);
//Astepper1.setSpeed(80);
}
void loop()
{
Astepper1.runSpeed();
}