===== Dual MC33926 ===== Hier findet ihr einen übersichtlichen Schaltplan zum Anschluss des Motor Treibers: [[http://letsmakerobots.com/node/39173|http://letsmakerobots.com/node/39173]] Und hier die Polou-Seite mit weiteren Infos: [[https://www.pololu.com/product/1213|https://www.pololu.com/product/1213]] ===== Motorgeschwindigkeit mit Encoder messen ===== (Code für einen Motor) const int ENABLE = 4; const int IN1 = 9; const int IN2 = 11; const int CS = A7; // pin to measure the motor current (connected to the driver FB feedback pin) const int ENCODERA = 2; // encoder sensor pin A const int ENCODERB = 3; // encoder sensor pin B byte encoder0PinALast; int duration;//the number of the pulses boolean dir;//the rotation direction void setup() { pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENABLE, OUTPUT); Serial.begin(9600); pinMode(ENCODERA, INPUT); pinMode(ENCODERB, INPUT); encoderInit(); } void loop() { digitalWrite(ENABLE, HIGH); int pwm = 250; analogWrite(IN1, pwm); digitalWrite(IN2, LOW); Serial.print("speed: "); Serial.print(duration); Serial.print(" "); Serial.print("PWM: "); Serial.print(pwm); Serial.print(" "); Serial.print("CS: "); Serial.println(CS); // ich muss die Variable auf Null setzen, damit ich die nächste Messung durchführen kann: duration = 0; delay(100); } // Wird am Anfang im Setup aufgerufen void encoderInit() { dir = true;//default -> Forward pinMode(ENCODERB, INPUT); attachInterrupt(0, wheelSpeed, CHANGE); } // Speichert die Motorgeschwindigkeit in der globalen Variable duration void wheelSpeed() { int Lstate = digitalRead(ENCODERA); if ((encoder0PinALast == LOW) && Lstate == HIGH) { int val = digitalRead(ENCODERB); if (val == LOW && dir) { dir = false; //Reverse } else if (val == HIGH && !dir) { dir = true; //Forward } } encoder0PinALast = Lstate; if (!dir) duration++; else duration--; }