×

SparkFun Electronics will be closed on July 3rd, 2015 in observance of Independence Day. Any orders placed after 2:00pm MT on July 2nd will be shipped out after the weekend. Thanks!

avatar

gabrielgiacomini

Member Since: March 11, 2013

Country: Brazil

  • I had similar problem as the other users and didn’t manage to use this encoder by using libraries or example code. After a few nights failing to implement existent code I decided to go reverse engineering and figure out what kind of output this thing was giving, and I came out with this code that is working nice with all the units I have (a bought a bunch of them with ringcoder breakouts and everything). This code adds or subtracts from encoderPosition every time the encoder reachs a detent. It will still fail to detect 1% of the times you reach a detent. I used port 52 and 53 since I’m testing this on Arduino DUE (all pins can be used as interrupts), but if you are using other arduinos you should use external interrupt pins.

    int aPin = 52; //connected to the A port
    int bPin = 53; //connected to the B port
    
    void setup()
    {
      Serial.begin(115200);
    
      pinMode(aPin, INPUT); 
      digitalWrite(aPin, HIGH); //pulled-up
      pinMode(bPin, INPUT);
      digitalWrite(bPin, HIGH); //pulled-up
    
      noInterrupts();
      attachInterrupt(aPin, readEncoder, CHANGE);
      attachInterrupt(bPin, readEncoder, CHANGE);
      interrupts();
    
    }
    
    signed int encoderPosition; 
    
    volatile char rotaryData = 0x0;
    
    void readEncoder()
    {
      noInterrupts();
    
      char newData=digitalRead(aPin)
    

No public wish lists :(