miketeachman / micropython-rotary

MicroPython module to read a rotary encoder.
MIT License
267 stars 56 forks source link

Using GPIO Extender #28

Open Snowgoose74 opened 11 months ago

Snowgoose74 commented 11 months ago

Hi Mike, Firstly, thanks for an excellent MicroPython library for the rotary encoder. So many resources use Circuit Python or Arduino only, so it's great to come across this!

My issue is that I'm using an MCP 23017 to extend the number of GPIO pins. This is because I'm using a Pico to drive an LED matrix and almost all the GPIOs are used for this purpose. I have an adafruit 23017 GPIO extender board working on I2C (using QWIIC connection).

I address the pins like this (where x is the pin number I'm addressing):

mcp = mcp23017.MCP23017(i2c, 0x20) mcp.pin(x, mode=1, pullup=True)

My tiny brain can't work out a way to use these extended GPIO pins with your Rotary Encoder module. Is this possible? Interrupts on the extender are through 2 pins (INTA works with the first 8 pins and INTB for the second 8). I assume I need to connect these interrupt pins to a spare GPIO on the Pico itself in order to get interrupts to work?

Many thanks Dave

miketeachman commented 11 months ago

Hi Dave, Unfortunately, I can't see a way to use a GPIO extender with this library. Internally, this Rotary library uses the MicroPython Pin class which requires direct access to the microprocessor pins. As far as I know there is no way to map a Pin class object to the GPIO extender library. It's a similar problem that is discussed in this issue https://github.com/miketeachman/micropython-rotary/issues/24. I suggest trying to find an encoder library that uses polling techniques, rather than the interrupt techniques that are used in this library. A library that uses polling can be adapted to poll pin values from the GPIO extender. The downside to polling approach is a much slower response when the encoder is turned. Clicks will be missed if the encoder is turned too quickly.
Hope this helps! Mike

Snowgoose74 commented 11 months ago

Hi Mike, I thought as much. Speed isn't too much of an issue for me so I'll see if I can find a polling library.

Thanks again for your work here...it allowed me to have fun using rotary encoders for the first time!!

Best wishes Dave