I am working on a project that will re-purpose a cheap laser engraver to move an ultrasonic sensor with a joystick when in "manual mode" and run a predefined routine when in "auto mode". The circuit board has a Nano and two A4988 drivers on it. I plan on using the AccelStepper library to control both stepper motors. The motor is a 200 step motor and the A4988 is set to 16th step (which is controlled by the circuit board). I am starting out small and just trying to get the steppers to work the way I want them to. When I try the following code, it takes almost 3 seconds for the stepper to complete one full turn. If I understand steppers and the library correctly, at the MAX_SPEED of 6400, it should complete 2 full turns in 1 second. Is that correct? I have changed both the MAX_SPEED (as low as 100 and as high as 20000) and I can't get quicker than 1 rev in 3 seconds. What am I missing/doing wrong?
#include <AccelStepper.h>
#define STEP_PIN 2
#define DIR_PIN 5
#define ENABLE_PIN 8
#define MAX_SPEED 6400
#define MAX_ACCEL 500
AccelStepper stepper(STEP_PIN, DIR_PIN);
void setup()
{
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW);
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(MAX_SPEED);
stepper.setAcceleration(MAX_ACCEL);
}
void loop()
{
stepper.moveTo (100);
stepper.setSpeed(MAX_SPEED);
stepper.run();
stepper.moveTo (-100);
stepper.setSpeed(MAX_SPEED);
stepper.run();
}
Thanks,
Justin