I2C QT Rotary Encoder documentation

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bheesbeen
 
Posts: 2
Joined: Tue Jan 11, 2022 4:16 am

I2C QT Rotary Encoder documentation

Post by bheesbeen »

Hello,

I recently bought an Adafruit I2C QT Rotary Encoder to ease the use of a rotary encoder in my project.
After connecting it to my Raspberry Pi, I was able to run the sample code without any problems. Cool, much easier than analysing the signals yourself.

But one of the reasons I chose to use this board is it capability to use interrupts, so there is no need to constantly poll for changes.
I can not find any documentation or even sample code on how to use this board with interrupts.

Can anyone help me to find the correct documentation to use this board with interrupts or provide me with sample code?

Thanks

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C QT Rotary Encoder documentation

Post by dastels »

In the basic example (https://learn.adafruit.com/adafruit-i2c ... 3096044-19) you can see:

Code: Select all

ss.setGPIOInterrupts((uint32_t)1 << SS_SWITCH, 1);
ss.enableEncoderInterrupt();
The above will enable the generation of interrupts on the encoder pushswitch and position change.

Connect the INT pin of the encoder breakout to the digital input pin you want to use as an interrupt and then use it as appropriate.

That should give you what's needed to get started.

Dave

User avatar
bheesbeen
 
Posts: 2
Joined: Tue Jan 11, 2022 4:16 am

Re: I2C QT Rotary Encoder documentation

Post by bheesbeen »

Thanks Dave.

You have put me on the right track.
As I am using CircuitPython, I had a look at the Seesaw code in Github and found the equivalents.

In Python I got it working with:

Code: Select all

seesaw.set_GPIO_interrupts(1 << 24, True)
seesaw.enable_encoder_interrupt()

User avatar
mzincali
 
Posts: 48
Joined: Tue Jan 18, 2022 9:09 pm

Re: I2C QT Rotary Encoder documentation

Post by mzincali »

dastels wrote:In the basic example (https://learn.adafruit.com/adafruit-i2c ... 3096044-19) you can see:

Code: Select all

ss.setGPIOInterrupts((uint32_t)1 << SS_SWITCH, 1);
ss.enableEncoderInterrupt();
The above will enable the generation of interrupts on the encoder pushswitch and position change.

Connect the INT pin of the encoder breakout to the digital input pin you want to use as an interrupt and then use it as appropriate.

That should give you what's needed to get started.

Dave
What's the best way to wire up interrupt lines if i have 4 rotary encoders? Each encoder takes up a different input pin on my ESP32?

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C QT Rotary Encoder documentation

Post by dastels »

If the INT output is open-collector then you can connect them together to a single pin that would have the internal pullup enabled.. I'm guessing they are since that's often the cans and it's directly providing a ground for the INT LED. I would remove that LED if I were using the INT output, though. The other option is to have each INT go to a separate pin. The advantage of the latter is that you know which encoder generated the INT since its dedicated interrupt would trigger. If you tied them all together to a single interrupt you would need to read/update the positions of all encoders each time one changed.

Dave

User avatar
mzincali
 
Posts: 48
Joined: Tue Jan 18, 2022 9:09 pm

Re: I2C QT Rotary Encoder documentation

Post by mzincali »

dastels wrote:If the INT output is open-collector then you can connect them together to a single pin that would have the internal pullup enabled.. I'm guessing they are since that's often the cans and it's directly providing a ground for the INT LED. I would remove that LED if I were using the INT output, though.

Dave
It seems you are right. I can connect the INT pins together for two encoders, and into the ESP32 input and it works.

If I add two more encoders' INT pins to the same input pin of the ESP32, then I get poor behavior: I get one interrupt from each encoder and no more, until I twist another encoder. If I take one encoder off, and use three, I still have the bad behavior.

Any more than two encoders, the voltage of the combined INT lines drops to about 2..6 volts once I've triggered one encoder a second time. If I trigger another encoder, the voltage goes back up to 3.3V momentarily. I think as you say, it may have to do with the INT LEDs. I'd rather not go desoldering the surface mount LEDs if i can; is there another way to work around this?

Right now, I'm splitting the 4 into two pairs of encoders on two INT inputs. I'd rather use one input for all, if possible.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C QT Rotary Encoder documentation

Post by dastels »

I'm afraid the LED (and it's resistor) are hardwired in with no easy way to remove it from the circuit. Its resistor will be easier to remove as there's nothing else around it. It's the one just above "INT".

Dave

User avatar
mzincali
 
Posts: 48
Joined: Tue Jan 18, 2022 9:09 pm

Re: I2C QT Rotary Encoder documentation

Post by mzincali »

Thank you for being so helpful.

I think I might just live with two input pins dedicated to serve the interrupts of four encoders - a pair of encoders per INT. I would rather not mess with the hardware, since I'm only temporarily using these encoders as a way to quickly fine tune PID and LQR control system coefficients, without needing to upload code changes a few hundred times. I don't even really need to use the INT at all, and just poll them, but I am learning more about how interrupts work, and it makes the code look nicer.

I'm curious why 2 work and three don't. Where can I learn more about this or how to measure voltage levels in order to be able to detect these sort of things, since they can be time sinks when you don't know if it is an issue with the code you are writing or the hardware.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: I2C QT Rotary Encoder documentation

Post by dastels »

I'm not sure, and I'm not completely sure that's the problem, but I can't see what else it would be.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”