Un motore passo-passo NEMA17 converte gli impulsi di passo in un movimento angolare preciso tramite due bobine elettromagnetiche. Di solito è pilotato da un driver per motori passo-passo usando i quattro terminali delle bobine del motore (di solito indicati come A+/A− e B+/B−), mentre gli altri terminali indicati sul connettore corrispondono alle stesse connessioni delle bobine con una diversa disposizione dei pin. Usa un cablaggio adeguato del driver stepper per alimentare in sequenza le bobine A e B.
| Pin | Segnale | Descrizione |
|---|---|---|
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 |
| Da | A | Filo |
|---|---|---|
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 |
Questo esempio è stato scritto e verificato in compilazione per arduino-uno. Codey Online lo adatta a qualsiasi altra scheda supportata.
// 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);
}
Descrivi cosa vuoi realizzare. Codey Online scrive il codice, disegna lo schema di collegamento, lo compila e programma la tua scheda direttamente dal browser.
Inizia gratis