驱动步进电机常见的有42,56步进电机,但如何驱动呢。
首先要了解步进电机,你要知道他是几相,有几根线。
步进电机驱动器有很多种,比如A4988,一定要外接电源,不然不能驱动,有的情况还需要加电容。用此驱动器可以进行细分,就是MS1到MS3引脚,用A4988驱动步进电机的程序:
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}