Hey all, I've run into a problem which I'm guessing has a simple solution, but it really has me baffled. In the initial stages of my project I developed using an Arduino Uno, and later on when I needed a fast PWM frequency I switched to a Teensy 3.1 I had on hand. When I did so, the rotary encoder inputs I was using all started behaving strangely. I reduced the problem to it simplest form, and tested with the example provided with the library I was using, this library specifically: https://github.com/PaulStoffregen/Encoder
This is the code I'm testing with:
On an Arduino Uno, the output is as expected. Turning the encoder in one direction prints an increasing integer value, and turning it in the other direction a decreasing integer value. One the Teensy 3.1, I get this:
Depending on which pins I use, I get either -1,0 and 1,0. I've tried different pins, manually disabling and enabling interrupts, testing at 3.3V on the Arduino, and tried several different encoders including one that's on a custom board I designed with hardware debouncing. I'm stumped, so any help would be greatly appreciated.
This is the code I'm testing with:
Code:
Encoder myEnc(2, 3);
void setup() {
Serial.begin(9600);
Serial.println("Basic Encoder Test:");
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
}
On an Arduino Uno, the output is as expected. Turning the encoder in one direction prints an increasing integer value, and turning it in the other direction a decreasing integer value. One the Teensy 3.1, I get this:
Code:
Basic Encoder Test:
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
Depending on which pins I use, I get either -1,0 and 1,0. I've tried different pins, manually disabling and enabling interrupts, testing at 3.3V on the Arduino, and tried several different encoders including one that's on a custom board I designed with hardware debouncing. I'm stumped, so any help would be greatly appreciated.