Hallo alle zusammen.
Ich habe hier ein Problem. Ich habe einen DC Motor wo hinten dran ein Magnetic Encoder drauf ist.
Jetzt hatte ich versucht ihn mit dem Code auszulesen.
Der Motor hat 6 Adern, wovon eine gelb (1) ist und der rest ist weiss.
Die gelbe und die daneben (2) ist plus und minus vom motor.
Denke also das die andren 4 adern vom Encoder sind.
/*
Pay attention to the interrupt pin,please check which microcontroller you use.
http://arduino.cc/en/Reference/AttachInterrupt
*/
//The sample code for driving one way motor encoder
const byte encoder0pinA = 2;//A pin -> the interrupt pin 2
const byte encoder0pinB = 4;//B pin -> the digital pin 4
byte encoder0PinALast;
int duration;//the number of the pulses
boolean Direction;//the rotation direction
void setup()
{
Serial.begin(57600);//Initialize the serial port
EncoderInit();//Initialize the module
}
void loop()
{
Serial.print("Pulse:");
Serial.println(duration);
duration = 0;
delay(100);
}
void EncoderInit()
{
Direction = true;//default -> Forward
pinMode(encoder0pinB,INPUT);
attachInterrupt(0, wheelSpeed, CHANGE);//int.0
}
void wheelSpeed()
{
int Lstate = digitalRead(encoder0pinA);
if((encoder0PinALast == LOW) && Lstate==HIGH)
{
int val = digitalRead(encoder0pinB);
if(val == LOW && Direction)
{
Direction = false; //Reverse
}
else if(val == HIGH && !Direction)
{
Direction = true; //Forward
}
}
encoder0PinALast = Lstate;
if(!Direction) duration++;
else duration--;
}
Da wird mir aber immernur 0 angezeigt.
Kann ich den dafür eigentlich verwenden?
Braucht ihr bilder von dem Encoder?
beste grüße Matze
