SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By albnar
I am new in this Forum and in development with Arduino too.
I was able to read one of both using code I found in and Arduino UNO.
Now I need to read two quad rotary encoders at the same time. Arduino UNO has only two external interrupts pins.
I decided to use Arduino DUE.
I modified the code to use two encoders.
It seems that DUE does not counts the pulses coming from encoders. It detects them only. Reading have always the same two values, it does not count them.
Could someone help me?

Here is the code (sorry I do not know a better way to paste it)

/* Encoder Library - TwoKnobs Example
* This example code is in the public domain.
#include <Encoder.h>

// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability

Encoder ribbon1(3,2);
Encoder ribbon2(4,5);

void setup() {
Serial.println("Linear Encoder Test:");


long positionRibbon1 = -999;
long positionRibbon2 = -999;

void loop() {
double newLeft1, newLeft2;
float dist1, dist2;
newLeft1 =;
newLeft2 =;
if (newLeft1 != positionRibbon1 or newLeft2 != positionRibbon2) {
dist1 = newLeft1/2000.;
dist2 = newLeft2/2000.; //2000 counts = 1mm.
positionRibbon1 = newLeft1;
positionRibbon2 = newLeft2;

// if a character is sent from the serial monitor,
// reset both back to zero.

if (Serial.available()) {;
Serial.println("Reset Ribbon to zero");
By paulvha
I suspect it could be related to interrupts. Only the last call for encoder will be set with interrupts : Encoder ribbon2(4,5);
Look at the example Nointerrupts and #define ENCODER_DO_NOT_USE_INTERRUPTS before "include "encoder.h". It has a trade off so read the header of the example.

One aspect that I find interesting all the driver code in the the encoder.h file instead of encoder.cpp (where I would expect it)