Description
The rotaryio lib is quite good as it is but I have a suggestion for an addition to it: The ability to have a reset pin that sets the counter to 0. When using the rotaryio library to track relitive positions it can be usefull to be able to reset the counter when another pin is triggered.
In my case I have a large geared circle (the rotating dome of a full size R2D2) connected to a rotary encoder that tracks the relitive position of the head, to "home" it I use a hall effect sensor that can give the rotary encoder a fixed position to know where zero is.
the code looks something like (not an optimal solution, very much a WIP):
encoder = rotaryio.IncrementalEncoder(board.GP0, board.GP1)
hall_effect = digitalio.DigitalInOut(board.GP2)
hall_effect.digitalio.Direction.INPUT
hall_effect.digitalio.Pull.DOWN
while True:
if not hall_effect.value:
encoder.position = 0
print(encoder.position)
What I envision is the ability to have this implemented into the rotaryio library itself instead of outside of it by defining a reset_pin and the ability to toggle wether or not that ability is active
encoder = rotaryio.IncrementalEncoder(board.GP0, board.GP1, divisor=2,reset_pin=board.GP2)
encoder.reset_pin_enabled = True
encoder.reset_pin_enabled = False