Following Jacob’s guide of 5/4/23.
I am using an encoder with three pins.
The printed “Encoder Values” just keep increasing whether I turn the knob left or right.
I had a similar problem using the encoder with Arduino Nano which I solved by enabling the PULL_UP for the signal pins of the RE.
The GitHub for miketeachman/micropython.rotary shows you can enable the Pico PULL_UP in the rotary_irq_rp2.py file. I did this however it had no effect.
Jacob mentions using the three pin RE further in the guide for the momentary switch but there seems to be no variation in the code for Reading Values from a RE section.
I have a few three pin REs to use.
Can you please advise how to alter the code to allow for these REs without breakout boards?
Sorry to hear you’re having issues! How are you wiring the 3 Pin encoder to the Pico (ie which pins of the RE to which of the Pico)? Also, which rotary encoder are you using (if you have a product URL handy that would be awesome)?
I’ve successfully tested the first example from the guide using only 3 pins from this rotary encoder, with the following wiring:
A (left pin) → Pico GPIO 15
B (right pin) → Pico GPIO 16
C (middle pin) → Pico GND
As you mentioned, I also had to add the pull_up=True param to the RotaryIRQ constructor for it to work:
rotary = RotaryIRQ(14, 15, pull_up=True)
Here’s a Fritzing diagram of my exact setup:
Wired up like you said and added the pull_up parameter to the RotaryIRQ constructor, all good,
Initially I had only changed the pull_up parameter in the accompanying rotary_irq_rp2.py file, but this had no effect.
Went onto the servo section and I had to alter the button line to include PULL_UP as the button on your RE must have a pull up resistor included.
btn = Pin(12, Pin.IN, Pin.PULL_UP)
As a result the program with the servo works well.
I can’t send any ID for my encoders as they have been salvaged and there are no markings, however a couple of them look similar to the one you sent the link for.
Most of the youtube pages use REs with breakout boards so not helpfull.
Thanks again for your reply and the great guides CE provides, looking forward to your next one.
Kind regards, Stephen
That’s great to hear that it’s working for you now! And thanks for the positive feedback
I’ve updated the guide to also include how to hook up a regular 3-pin Rotary Encoder for others as well.