สินค้าที่เกี่ยวข้อง
UNO and IO modules, the interface between the introduction ports.
The basic requirements of stepper motor control, other pins are in the engraving machine or 3D printer when using the printer, here we do not detail the IO , it corresponds to the above figure.
Uno expansion board
8 interesting (stepper motor drive enable, low use)
7 Oni z.dir (Z axis direction control)
6Y Dir (Y-axis direction control)
5-inch x.dir (x-axis direction control)
4-inch Z steps (Z-axis stepper control)
3 more y. steps (Y-axis stepper control)
2. x. steps (x-axis stepper control)
// This is a simple stepper motor control procedure.
#define EN 8 //Enable terminal of stepper motor, active low
#define X_DIR 5 //X-axis stepper motor direction control
#define Y_DIR 6 //y-axis stepping motor direction control
#define Z_DIR 7 //z-axis stepping 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 and number of steps of the stepper motor.
//Parameters: dir direction control, dirPin corresponds to the DIR pin of the stepper motor, stepperPin corresponds to the step pin of the stepper motor, steps is the number of steps
//no return value
*/
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(50);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepperPin, LOW);
delayMicroseconds(800);
}
}
void setup(){//Set the IO pin used by the stepper motor as an 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); //X-axis motor reverses 1 circle, 200 steps are one circle
step(false, Y_DIR, Y_STP, 200); //Y-axis motor reverses 1 circle, 200 steps are one circle
step(false, Z_DIR, Z_STP, 200); //z-axis motor reverses 1 circle, 200 steps are one circle
delay(1000);
step(true, X_DIR, X_STP, 200); //X-axis motor rotates forward for 1 circle, 200 steps are one circle
step(true, Y_DIR, Y_STP, 200); //Y-axis motor rotates forward for 1 circle, 200 steps as a circle
step(true, Z_DIR, Z_STP, 200); //z-axis motor rotates forward for 1 circle, 200 steps as a circle
delay(1000);
}