ruhrohrotaryio

Pretend to be rotaryio for boards that need non-sequential pins.

On RP2040-based boards like the Raspberry Pi Pico and QTPy RP2040, if you try to use “rotaryio” on pins whose GPIO numbers are not sequential, you will get a RuntimeError: Pins must be sequential GPIO pins.

This package acts just like rotaryio but uses keypad and some logic to read a rotary encoder. It is not as fast or efficient as rotaryio but it will work on RP2040 boards.

  • Author(s): Tod Kurt / @todbot

Implementation Notes

Hardware:

Any CircuitPython device with keypad support

Software and Dependencies:

class ruhrohrotaryio.IncrementalEncoder(pin_a, pin_b, divisor=4)

A simple drop-in replacement for rotaryio.IncrementalEncoder that works on non-sequential pins on RP2040. Requires keypad support.

Create an IncrementalEncoder object associated with the given pins. It tracks the positional state of an incremental rotary encoder (also known as a quadrature encoder.) Position is relative to the position when the object is constructed.

Parameters:
  • pin_a (Pin) – First pin to read pulses from.

  • pin_b (Pin) – Second pin to read pulses from.

  • divisor (int) – The divisor of the quadrature signal. (currently unused)

deinit()

Deinitializes the IncrementalEncoder and releases any hardware resources for reuse.

property position

The current position in terms of pulses. The number of pulses per rotation is defined by the specific hardware and by the divisor.