feature:
The expansion board acts as a drive expansion board for engraving machines and 3D printers. It has four slots and can drive four A4988 stepper motors. Each road stepper motor requires only two IO ports. In other words, six IO ports can manage three stepper motors very well. It is very convenient to use. UNO introduces the IO port communication of the Arduino module.
Note: This version is not included in the A4988 module and the UNO R3 module!
IO corresponding pin:
UNO stands for Arduino ---------------------- Expansion Committee;
8 ------------------------ EN (stepper motor driver enable, active low);
7 ----------------------- Z.DIR (Z-axis direction control);
6 ----------------------- Y.DIR (Y-axis direction control);
5 ----------------------- X.DIR (X-axis direction control);
4 ---------------------- Z.STEP (Z-axis step control);
3 ---------------------- Y.STEP (Y-axis step control);
2 ---------------------- X.STEP (X-axis step control);
The following is a simple stepper motor control program,
#define EN 8 //Stepper motor enabled, active low;
#define X_DIR 5 / / X-axis stepper motor direction control;
#define Y_DIR 6 / / y-axis stepper motor direction control;
#define Z_DIR 7 / / z-axis stepper motor direction control;
#define X_STP 2 / / x -axis step control;
#define Y_STP 3 / / y -axis Step control;
#define Z_STP 4 / / z -axis step control;
/ *; // function: step. Function: Control the direction of the stepper motor, the number of steps.
//Parameter: dir direction control, dirPin corresponds to stepper motor DIR pin, stepperPin corresponds to stepper motor stepping pin, step progress number has no return value.
* /
Void step(boolean dir,byte dirPin,byte stepperPin,int steps)
{
digitalWrite(dirPin,dir);
Delay (50);
For(int i = 0; i digitalWrite(stepperPin,HIGH);
delayMicroseconds(800);
digitalWrite(stepperPin, LOW);
delayMicroseconds(800);
}
}
Void setup(){/ / The stepper motor used in the IO pin is set to output
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
pinMode(EN,OUTPUT);
digitalWrite(EN, LOW);
}
Void loop(){
Step (false, X_DIR, X_STP, 200); // The X-axis motor reverses 1 ring, and the 200 step is a circle.
Step (false, Y_DIR, Y_STP, 200); // The y-axis motor reverses 1 ring, and 200 steps is a circle.
Step (false, Z_DIR, Z_STP, 200); // z-axis motor reverses 1 ring, 200 steps is a circle.
Delay (1000);
Step (true, X_DIR, X_STP, 200); // The X-axis motor advances one revolution and the 200-step is one revolution.
Step (true, Y_DIR, Y_STP, 200); // The y-axis motor advances one revolution, and the 200 steps are one revolution.
Step (true, Z_DIR, Z_STP, 200); // The z-axis motor advances one revolution, and the 200-step is one revolution.
Delay (1000);
}
Note: When inserting the A4988 module, be careful not to insert the opposite side. The stepper motor wiring is as follows:
In Fig. 2A, 2B is a group (red, green), 1A, 1B is a group (blue, yellow), if you want to change direction, you can change the position of a group, for example 2A, 2B exchange.