Adafruit Motor Shield V2.3
Arduino UNO Rev 3
Adafruit NEMA17 Stepper Motor 12V
After the installation of the libraries for the Adafruit Motor Shield, there are some examples in the Arduino IDE 2.0 in File > Examples > Adafruit Motor Shield V2 Library. While the example Accel_MultiStepper works just fine, the example Accel_ConstantSpeed moves the stepper only one step per second. It is supposed to move the motor at a constant speed. Changing the
Code: Select all
Astepper1.setSpeed(50)
Code: Select all
#include <AccelStepper.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
void forwardstep1() {
myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardstep1() {
myStepper1->onestep(BACKWARD, DOUBLE);
}
AccelStepper Astepper1(forwardstep1, backwardstep1);
void setup()
{
Serial.begin(9600);
Serial.println("Stepper test!");
if (!AFMS.begin()) { // create with the default frequency 1.6KHz
// if (!AFMS.begin(1000)) { // OR with a different frequency, say 1KHz
Serial.println("Could not find Motor Shield. Check wiring.");
while (1);
}
Serial.println("Motor Shield found.");
Astepper1.setSpeed(200);
}
void loop()
{
Astepper1.runSpeed();
}