AFMotor MotorShield library 1.0.1
Spécifications moteur pas à pas 28BYJ-48 5V et 12V
Le cavalier 5V doit être positionné pour permettre l'alimentation de la carte Arduino. (12V max)
#include <AFMotor.h>
#define nbSteps 1024
// Connect a stepper motor with 64 steps per revolution (5.625 degree) eg. 28BYJ-48
// Reductor 1:64 ==> 64 x 64 = 4096
// to motor port #1 (M1 and M2)
AF_Stepper motor_X(4096, 1);
// to motor port #2 (M3 and M4)
AF_Stepper motor_Y(4096, 2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor_X.setSpeed(5); // 5 rpm
motor_Y.setSpeed(5); // 5 rpm
testStepper(1);
motor_X.release();
testStepper(2);
motor_Y.release();
}
void loop() {
}
void testStepper(int motor) {
switch(motor) {
case 1:
Serial.println("1 - Single coil steps");
motor_X.step(nbSteps, FORWARD, SINGLE);
motor_X.step(nbSteps, BACKWARD, SINGLE);
Serial.println("1 - Double coil steps");
motor_X.step(nbSteps, FORWARD, DOUBLE);
motor_X.step(nbSteps, BACKWARD, DOUBLE);
Serial.println("1 - Interleave coil steps");
motor_X.step(nbSteps, FORWARD, INTERLEAVE);
motor_X.step(nbSteps, BACKWARD, INTERLEAVE);
Serial.println("1 - Micrsostep steps");
motor_X.step(nbSteps, FORWARD, MICROSTEP);
motor_X.step(nbSteps, BACKWARD, MICROSTEP);
break;
case 2:
Serial.println("2 - Single coil steps");
motor_Y.step(nbSteps, FORWARD, SINGLE);
motor_Y.step(nbSteps, BACKWARD, SINGLE);
Serial.println("2 - Double coil steps");
motor_Y.step(nbSteps, FORWARD, DOUBLE);
motor_Y.step(nbSteps, BACKWARD, DOUBLE);
Serial.println("2 - Interleave coil steps");
motor_Y.step(nbSteps, FORWARD, INTERLEAVE);
motor_Y.step(nbSteps, BACKWARD, INTERLEAVE);
Serial.println("2 - Micrsostep steps");
motor_Y.step(nbSteps, FORWARD, MICROSTEP);
motor_Y.step(nbSteps, BACKWARD, MICROSTEP);
break;
default:
Serial.println("Unknown motor");
}
}