Hello,
my first post here, but have been lurking for couple of weeks and your posts have been most helpful in aiding me to complete the design for my project. I've been building a controller box for DCS and Teensy 4 is the brains, couple of 16 channel multiplexers for the buttons, couple of potentiometers for radio control and 2 encoders.
Now, I've been able to make standalone sketches that work just for reading buttons from multiplexers and another to read pots. Just as a proof-of-concept on a breadboard. When it comes to encoders, I've had 0 success for last 2 weeks, I'm out of ideas what have I been doing wrong and it's starting to really frustrate me. Encoders should be simple devices and with the plethora of libraries available I didn't expect I'll have issues, but here I am.
I've been using the example sketch that comes with Teensyduino IDE and here is the code and result. I have connected the encoder and just spun it in single direction for a full turn or two. Only thing I get as a result is alternation between 0 and 1. Because of that, I can't figure out did I turn encoder left or right and as a result I can't bind that to button output.
The result:
I have tried numerous libraries (Encoder_Polling, EncoderStepCounter, NewEncoder, QuadEncoder) with all their examples and the result was the same. If I got some result, I got this alternation result and that's it. It even doesn't matter in which direction I turn the encoder, the alternation just continues. I would expect the encoder to start counting if I just turn it in one direction, but this doesn't happen.
The end result that I'd like is just to be able to recognize did I turn encoder left or right and assign those to button outputs as I'll be using the Teensy in Joystick mode.
Connection scheme:
Encoder pin A -> Teensy pin 1
Encoder pin B -> Ground
Encoder pin C -> Teensy pin 3
There is also a 10kOhm resistor between Teensy pins 1 and 3 and 3.3V
I've attached a picture of that too.
Also, as I have bought 5 of those, I did try to put all of them in the breadboard and the result was identical between the encoders. So, either I got the failed batch or there is something I just fail to understand with this kind of encoder.
Oh, one more thing that I've noticed and could help in resolving this. I have noticed that sometime I get 5-6 lines in the output for just one detent in a turn. Don't really understand what that means.
So if anyone can help me in achieving this, I would be really grateful as this is last thing that's barring me from continuing on the project.
my first post here, but have been lurking for couple of weeks and your posts have been most helpful in aiding me to complete the design for my project. I've been building a controller box for DCS and Teensy 4 is the brains, couple of 16 channel multiplexers for the buttons, couple of potentiometers for radio control and 2 encoders.
Now, I've been able to make standalone sketches that work just for reading buttons from multiplexers and another to read pots. Just as a proof-of-concept on a breadboard. When it comes to encoders, I've had 0 success for last 2 weeks, I'm out of ideas what have I been doing wrong and it's starting to really frustrate me. Encoders should be simple devices and with the plethora of libraries available I didn't expect I'll have issues, but here I am.
I've been using the example sketch that comes with Teensyduino IDE and here is the code and result. I have connected the encoder and just spun it in single direction for a full turn or two. Only thing I get as a result is alternation between 0 and 1. Because of that, I can't figure out did I turn encoder left or right and as a result I can't bind that to button output.
Code:
/* Encoder Library - Basic Example
* http://www.pjrc.com/teensy/td_libs_Encoder.html
*
* This example code is in the public domain.
*/
#include <Encoder.h>
// Change these two 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 myEnc(1, 3);
// avoid using pins with LEDs attached
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);
}
}
The result:
Code:
Basic Encoder Test:
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
0
-1
... you get the idea
I have tried numerous libraries (Encoder_Polling, EncoderStepCounter, NewEncoder, QuadEncoder) with all their examples and the result was the same. If I got some result, I got this alternation result and that's it. It even doesn't matter in which direction I turn the encoder, the alternation just continues. I would expect the encoder to start counting if I just turn it in one direction, but this doesn't happen.
The end result that I'd like is just to be able to recognize did I turn encoder left or right and assign those to button outputs as I'll be using the Teensy in Joystick mode.
Connection scheme:
Encoder pin A -> Teensy pin 1
Encoder pin B -> Ground
Encoder pin C -> Teensy pin 3
There is also a 10kOhm resistor between Teensy pins 1 and 3 and 3.3V
I've attached a picture of that too.
Also, as I have bought 5 of those, I did try to put all of them in the breadboard and the result was identical between the encoders. So, either I got the failed batch or there is something I just fail to understand with this kind of encoder.
Oh, one more thing that I've noticed and could help in resolving this. I have noticed that sometime I get 5-6 lines in the output for just one detent in a turn. Don't really understand what that means.
So if anyone can help me in achieving this, I would be really grateful as this is last thing that's barring me from continuing on the project.