I successfully run the AccelStepper examples on an Arduino Mega with a RAMPS 1.4 shield, two A4988 stepper motor drivers and two 17HS16-0284S stepper motors.
I used 3 jumpers on the RAMPS to set the microstep resolution to 1/16.
I used this code inspired by the Polargraph Server for Polargraph:
#include <AccelStepper.h>
/*
// for the Arduino Uno + CNC shield V3
#define MOTOR_A_ENABLE_PIN 8
#define MOTOR_A_STEP_PIN 2
#define MOTOR_A_DIR_PIN 5
#define MOTOR_B_ENABLE_PIN 8
#define MOTOR_B_STEP_PIN 3
#define MOTOR_B_DIR_PIN 6
*/
// for the Arduino Mega + RAMPS 1.4
#define MOTOR_A_ENABLE_PIN 30
#define MOTOR_A_STEP_PIN 36
#define MOTOR_A_DIR_PIN 34
#define MOTOR_B_ENABLE_PIN 56
#define MOTOR_B_STEP_PIN 60
#define MOTOR_B_DIR_PIN 61
AccelStepper motorA(1, MOTOR_A_STEP_PIN, MOTOR_A_DIR_PIN);
AccelStepper motorB(1, MOTOR_B_STEP_PIN, MOTOR_B_DIR_PIN);
void setup()
{
motorA.setEnablePin(MOTOR_A_ENABLE_PIN);
motorA.setPinsInverted(false, false, true);
motorB.setEnablePin(MOTOR_B_ENABLE_PIN);
motorB.setPinsInverted(false, false, true);
motorA.setAcceleration(100);
motorA.move(1000);
//motorA.setMaxSpeed(100);
//motorA.setSpeed(100);
motorB.setAcceleration(100);
motorB.move(1000);
//motorB.setMaxSpeed(100);
//motorB.setSpeed(100);
motorA.enableOutputs();
motorB.enableOutputs();
}
void loop()
{
motorA.run();
motorB.run();
}
I tried to use the same code with the same stepper motor drivers and motors on a Arduino Uno and a CNC shield v3 without success (I also used the 3 jumpers to set the microstep resolution to 1/16). The motors do not work and jitter.
What is wrong with my code?
Bonus questions:
I have taken this setup and code from the Polargraph server but I didn't get how I'm suppose to know how to use setEnablePin()
and setPinsInverted()
methods. In fact, I have troubles finding documentation about the CNC shield V3 and the A4988 drivers (I only found this page) to work with AccelStepper.