Hallo zusammen.
Habe einen 4 Pin Bipolar Schrittmotor schon erfolgreich angesteuert mit folgendem Code unten.
Nun möchte ich einen 2 ten gleichen Motor Synchron ansteuern wie der erste Motor, aber mit weniger Zeiger Ausschlag.
Daztu muss ich die stepsPerRevolution (aktuell 185 für den ersten Motor) ja seperat hinschreiben in dem Befehl der Ansteuerung.
Nur wie ?
Der 2te Motor soll mit 110 Steps hoch und runter fahren.
Jemand einen Tipp ?
Der Code sollte ja sonst selbsterklärend sein.
Also die 2 Motoren sollen gleichzeitig anfangen beide Nadeln Hochfahren, der eine Stoppt halt früher.
Dankeschön
//Erster Motor
#define A 2 // the pin connected to the wire A of the coil A (or to the H-bridge pin controlling the same wire)
#define A_bar 3 // the pin connected to the wire A- of the coil A (or to the H-bridge pin controlling the same wire)
#define B 4 // the pin connected to the wire B of the coil A (or to the H-bridge pin controlling the same wire)
#define B_bar 5 // the pin connected to the wire B- of the coil A (or to the H-bridge pin controlling the same wire)
//Zweiter Motor
#define A2 8 // the pin connected to the wire A of the coil A (or to the H-bridge pin controlling the same wire)
#define A_bar2 9 // the pin connected to the wire A- of the coil A (or to the H-bridge pin controlling the same wire)
#define B2 10 // the pin connected to the wire B of the coil A (or to the H-bridge pin controlling the same wire)
#define B_bar2 11 // the pin connected to the wire B- of the coil A (or to the H-bridge pin controlling the same wire)
#define x 4000 // smaller values may make the motor produce more speed and less torque
void setup() {
pinMode(A, OUTPUT);
pinMode(A_bar, OUTPUT);
pinMode(B, OUTPUT);
pinMode(B_bar, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A_bar2, OUTPUT);
pinMode(B2, OUTPUT);
pinMode(B_bar2, OUTPUT);
}
void loop() {
for (int i = 0; i < (185/8) ; i++) {
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, LOW);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, LOW);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
}
delay(1000); // the motor will complete a full revolution then waits for a second
// Counter Direction
for (int i = 0; i < (185/8); i++) {
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, LOW);
digitalWrite(B_bar, HIGH);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, LOW);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, HIGH);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, LOW);
digitalWrite(A_bar, LOW);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, HIGH);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
digitalWrite(A, HIGH);
digitalWrite(A_bar, LOW);
digitalWrite(B, LOW);
digitalWrite(B_bar, LOW);
delayMicroseconds (x);
}
delay(1000);
}