Skip to content

rp2040: implement rotaryio #4226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dhalbert opened this issue Feb 19, 2021 · 8 comments · Fixed by #4329
Closed

rp2040: implement rotaryio #4226

dhalbert opened this issue Feb 19, 2021 · 8 comments · Fixed by #4329
Assignees
Labels
rp2040 Raspberry Pi RP2040
Milestone

Comments

@dhalbert
Copy link
Collaborator

I may look at this in conjunction with #3895. If I can get a good reference implementation going, then it will be easy to port.

@dhalbert dhalbert added the rp2040 Raspberry Pi RP2040 label Feb 19, 2021
@dhalbert dhalbert added this to the Long term milestone Feb 19, 2021
@tannewt tannewt modified the milestones: Long term, 6.2.0 Feb 20, 2021
@tannewt
Copy link
Member

tannewt commented Feb 20, 2021

This is similar to the approach I was thinking: https://github.com/micropython/micropython/pull/6894/files

Use PIO to debounce and deduplicate pin values. Push the value out and trigger an interrupt on it.

I want to do this soon so moving to 6.2.0 milestone. Its a natural fit with usb_hid projects.

@jepler
Copy link

jepler commented Feb 20, 2021

The micropython state decoder looks like a solid design for "x4" quadrature decoding that avoids some problems that more naive implementations have. Crucially,

  • the data checked by the decoder is exactly the seen edges, not a sample of the inputs at a later time
  • every state transition is handled, rather than just handling certain transitions

Tracking the previous direction (positive or negative) in an attempt to decode changes in both bits simultaneously I think is of dubious value but it doesn't seem to hurt (doesn't affect the behavior when only one bit transition at a time is ever seen) and could make some designs that run just at the margin of the maximum work better, as long as there's enough "physicality" to the quadrature inputs that they don't instantly reverse from "+ludicrous_speed" to "-ludicrous_speed" instantly.

@tannewt tannewt self-assigned this Feb 24, 2021
@wildestpixel
Copy link

Found this quite quickly having wired up to test
IMG_1013

@tannewt
Copy link
Member

tannewt commented Feb 26, 2021

Sorry! I'm hoping to get to this very soon! Hopefully today or Monday.

@tannewt tannewt assigned jepler and unassigned tannewt Mar 2, 2021
@jepler
Copy link

jepler commented Mar 4, 2021

@tannewt shared with me some initial code related to rotaryio, but it's incomplete: https://github.com/tannewt/circuitpython/tree/rp2040_rotaryio

@dhalbert
Copy link
Collaborator Author

Fixed by #4329.

@wildestpixel
Copy link

Can confirm this now working in latest nightly builds (cannot build myself due to M1 silicon config error). Might be that assignation of encoder pins A & B is flipped. I have :

encoder = rotaryio.IncrementalEncoder(board.GP3, board.GP4)

working in correct orientation (clockwise increment, counter-clockwise decrement), however,

GP3 is connected to B and GP is connected to A.

Switch the wires, the encoder goes the wrong way, or code as

encoder = rotaryio.IncrementalEncoder(board.GP4, board.GP3)

to receive error :

Traceback (most recent call last): File "code.py", line 12, in <module> RuntimeError: Pins must be sequential

@tannewt
Copy link
Member

tannewt commented Mar 16, 2021

@jepler want to support descending pins too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rp2040 Raspberry Pi RP2040
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants