I’m in the process of migrating from Arduino microcontrollers to ESP32’s. I have an app written for the Mega 2560 that I want to port over to the ESP32. The app utilizes a rotary encoder for menu navigation and value selection. I found an example routine using the “ESP32RotaryEncoder.h” library. The routine displays a value that’s incremented/decremented when the encoder is turned. What I need is a simple “left / idle / right” value. I found in the “ESP32RotaryEncoder.h” the following:
typedef enum {
LEFT = -1,
STILL = 0,
RIGHT = 1
} Rotation;
These values would work perfectly, but I’m not versed well enough in digging through the libraries to know how to get these values.
Is there a good reference on how to work with libraries and get what’s needed?
Take a close look, if you use the edge of one of the pins and look at the other it will be high for one direction low for the other. If you want it the other way just swap pins.
I spent several hours trying to get the rotary encoder function I wrote for the Mega 2560 (which works excellently!) to work on the ESP32, but I’m guessing the much higher clock speed of the ESP32 contributes heavily to the problems I encountered. I totally understand how the encoder works. These encoders are anything but high quality, so the contacts are behaving glitchy.
The example sketch I found that uses the “ESP32RotaryEncoder.h” library is pretty much rock solid. I rarely see any glitch at all. It’s just that the value returned in the example sketch returns a numeric value that’s incremented/decremented when the knob is turned. What I need is a value that shows that it was turned “left” or “right”. I found what appears to be what I need in the library, but I need help in learning how to get it to return the “-1, 0, 1” values.
Well poop! I did see the “LeftOrRight” example yesterday, but when I tried it, everything was flaking out when I attempted to turn the encoder. I discovered today that because I’m using a bare encoder (with no circuit board, pull up resisters, etc.), I needed to change:
Anyone have an explanation for this line in the library:
* @param encoderPinVcc Optional; the voltage reference input, could be marked "+" or "V+" or "VCC"; defaults to -1, which is ignored
Why does a rotary encoder need a voltage reference if it’s only generating “high” and “low” values?
Just curious… Thanks…
Edit: Found the answer in a different rotary encoder library. Apparently modules are sometimes powered using unused GPIO’s rather than from the 3.3 or 5 volt pins.