// ****************************** // Sketch by R. Jordan Kreindler, written October 2016 // to work with EasyDriver stepper driver module // Rotates stepper in full, 1/2, 1/4, and 1/8 step modes // with the parameter "rotations" specifying how many times to // rotate for each stepping mode // ****************************** int oneLED = 6; // Full step LEDMS1 int onehalfLED = 7; // 1/2 step LED int onequarterLED = 8; // 1/4 step LED int oneeighthLED = 9; // 1/8 step LED int ms1Pin = 10; // EasyDriver MS1 to Arduino digital pin 10 int ms2Pin = 11; // EasyDriver MS2 to Arduino digital pin 11 int stepPin = 12; // EasyDriver STEP pin to Arduino digital pin 12 int dirPin = 13; // EasyDriver DIR pin to Arduino digital pin 13 int numSteps = 48; // Number of steps in 360 degree rotation int rotations = 4; // Number of rotations of the rotor in each mode int delay1 = 3; // Delay between coil activations (ms) int delay2 = 500; // Delay between subsequent rotations int i; // For loop index //------------------------------ void setup() { pinMode(ms1Pin, OUTPUT); // MS1 set to receive Arduino signals pinMode(ms2Pin, OUTPUT); // MS2 set to receive Arduino signals pinMode(stepPin, OUTPUT); // stepPin set to receive Arduino signals pinMode(dirPin, OUTPUT); // DIR set to receive Arduino signals pinMode(oneLED, OUTPUT); // Full step LED pinMode(onehalfLED, OUTPUT); // 1/2 step LED pinMode(onequarterLED, OUTPUT); // 1/4 step LED pinMode(oneeighthLED, OUTPUT); // 1/8 step LED digitalWrite(dirPin, HIGH); } //------------------------------ void loop(){ digitalWrite(dirPin, HIGH); digitalWrite(oneLED, HIGH); // Rotate stepper a full revolution, using full step method digitalWrite(ms1Pin, LOW); digitalWrite(ms2Pin, LOW); for (i = 1; i <= numSteps * rotations; ++i) { digitalWrite(stepPin, LOW); // Prepare to take a step digitalWrite(stepPin, HIGH) ; // Take a step delay(delay1); // Allow some delay between energizing // the coils to allow stepper rotor time to respond. } delay(delay2); digitalWrite(oneLED, LOW); digitalWrite(dirPin, LOW); digitalWrite(onehalfLED, HIGH); // Rotate stepper a full revolution, using half step method digitalWrite(ms1Pin, HIGH); digitalWrite(ms2Pin, LOW); for (i = 1; i <= numSteps * 2 * rotations; ++i) { digitalWrite(stepPin, LOW); // Prepare to take a step digitalWrite(stepPin, HIGH) ; // Take a step delay(delay1); // Allow some delay between energizing // the coils to allow stepper rotor time to respond. } digitalWrite(onehalfLED, LOW); digitalWrite(dirPin, HIGH); digitalWrite(onequarterLED, HIGH); // Rotate stepper a full revolution, using quarter stepping digitalWrite(ms1Pin, LOW); digitalWrite(ms2Pin, HIGH); for (i = 1; i <= numSteps * 4 * rotations; ++i) { digitalWrite(stepPin, LOW); // Prepare to take a step digitalWrite(stepPin, HIGH) ; // Take a step delay(delay1); // Allow some delay between energizing // the coils to allow stepper rotor time to respond. } digitalWrite(onequarterLED, LOW); // Rotate stepper a full revolution, using microstepping // 8 steps/step digitalWrite(oneeighthLED, HIGH); digitalWrite(ms1Pin, HIGH); digitalWrite(ms2Pin, HIGH); digitalWrite(dirPin, LOW); for (i = 1; i <= numSteps * 8 * rotations; ++i) { digitalWrite(stepPin, LOW); // Prepare to take a step digitalWrite(stepPin, HIGH) ; // Take a step delay(delay1); // Allow some delay between energizing // the coils to allow stepper rotor time to respond. } digitalWrite(oneeighthLED, LOW); }