Silnik krokowy NEMA17 zamienia impulsy krokowe na precyzyjny ruch kątowy dzięki dwóm cewkom elektromagnetycznym. Zwykle steruje się nim za pomocą sterownika silnika krokowego, wykorzystując cztery zaciski cewek silnika (najczęściej oznaczone jako A+/A− i B+/B−), a pozostałe oznaczone zaciski na złączu odpowiadają tym samym połączeniom cewek w innej grupie pinów. Użyj odpowiedniego okablowania sterownika stepper, aby wzbudzać cewki A i B po kolei.
| Pin | Sygnał | Opis |
|---|---|---|
1A |
power | Stepper coil 1 terminal A — connect to one output of motor driver phase A |
1B |
power | Stepper coil 1 terminal B — connect to the other output of motor driver phase A |
2A |
power | Stepper coil 2 terminal A — connect to one output of motor driver phase B |
2B |
power | Stepper coil 2 terminal B — connect to the other output of motor driver phase B |
| Z | Do | Przewód |
|---|---|---|
board:5V |
x2:VDD |
red |
board:GND |
x2:GND |
black |
board:D2 |
x2:STEP |
green |
board:D3 |
x2:DIR |
blue |
board:D4 |
x2:EN |
yellow |
board:5V |
x3:CW |
red |
board:GND |
x3:CCW |
black |
board:A0 |
x3:WIPER |
purple |
x2:1A |
x1:1A |
cyan |
x2:1B |
x1:1B |
magenta |
x2:2A |
x1:2A |
brown |
x2:2B |
x1:2B |
pink |
Ten przykład został napisany i sprawdzony kompilacją dla arduino-uno. Codey Online dostosuje go do każdej innej obsługiwanej płytki.
// Canonical NEMA17 stepper motor example using an A4988-style driver.
// Wiring:
// Arduino D2 -> STEP
// Arduino D3 -> DIR
// Arduino D4 -> EN (active LOW)
// Arduino 5V -> VDD
// Arduino GND -> GND
// Potentiometer CW -> 5V, CCW -> GND, WIPER -> A0
// Motor coils -> driver outputs 1A/1B and 2A/2B
const int STEP_PIN = 2;
const int DIR_PIN = 3;
const int EN_PIN = 4;
const int POT_PIN = A0;
void stepMotor(long steps, bool direction, unsigned int stepDelayMicros) {
digitalWrite(DIR_PIN, direction ? HIGH : LOW);
for (long i = 0; i < steps; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(stepDelayMicros);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(stepDelayMicros);
}
}
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(STEP_PIN, LOW);
digitalWrite(DIR_PIN, LOW);
digitalWrite(EN_PIN, HIGH); // disable driver at start
Serial.begin(9600);
while (!Serial) { }
Serial.println("NEMA17 stepper motor demo with A4988 driver");
Serial.println("Turn the potentiometer to change speed.");
Serial.println("The motor alternates direction after each full rotation.");
}
void loop() {
int pot = analogRead(POT_PIN);
unsigned int stepDelayMicros = map(pot, 0, 1023, 2000, 300);
const int stepsPerRevolution = 200; // typical 1.8 degree NEMA17 motor
digitalWrite(EN_PIN, LOW); // enable driver
Serial.print("Speed control pot=");
Serial.print(pot);
Serial.print(" step delay(us)=");
Serial.println(stepDelayMicros);
Serial.println("Rotating clockwise...");
stepMotor(stepsPerRevolution, true, stepDelayMicros);
delay(500);
Serial.println("Rotating counterclockwise...");
stepMotor(stepsPerRevolution, false, stepDelayMicros);
delay(500);
}
Opisz, co chcesz zbudować. Codey Online napisze kod, narysuje schemat połączeń, skompiluje projekt i wgra go na płytkę bezpośrednio z przeglądarki.
Zacznij za darmo