HI,
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 https://www.pjrc.com/teensy/td_libs_Encoder.html 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.begin(9600);
Serial.println(“Linear Encoder Test:”);
}
long positionRibbon1 = -999;
long positionRibbon2 = -999;
void loop() {
double newLeft1, newLeft2;
float dist1, dist2;
newLeft1 = ribbon1.read();
newLeft2 = ribbon2.read();
if (newLeft1 != positionRibbon1 or newLeft2 != positionRibbon2) {
Serial.print(“E”);
dist1 = newLeft1/2000.;
dist2 = newLeft2/2000.; //2000 counts = 1mm.
Serial.print(dist1,3);
Serial.print(“,”);
Serial.print(dist2,3);
Serial.println();
positionRibbon1 = newLeft1;
positionRibbon2 = newLeft2;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println(“Reset Ribbon to zero”);
ribbon1.write(0);
ribbon2.write(0);
}
}