-
Notifications
You must be signed in to change notification settings - Fork 43
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
encoder-only setup questions #38
Comments
That setup example looks correct for encoder only mode. The two encoder pins are connected to The final What is the actual problem you're getting? Can you post a link to the encoder device? By all means submit a PR for the driver with setup example. Please also submit a PR for the docs which are part of nano-gui. I can copy the driver to nano-gui (all drivers are common to both GUI's). |
Here is the encoder that I'm using: https://www.amazon.com/dp/B07T3672VK
When I run the
Totally agree that the naming is vague (at best). Maybe I'm misunderstanding -- are you saying that some encoders treat a clockwise vs couner-clockwise turn as signals sent to two different pins (X/Y)? |
It's evidently a standard encoder. Going on one of the comments the 5V pin is connected to 10KΩ pullups and the switches are connected to gnd. With a Pico you should connect the 5V pin on the encoder to the 3V3 output on the Pico. This is because the Pico inputs are not 5V-compatible. Gnd on the encoder should be connected to one of the Pico's gnd pins. The 5V issue doesn't explain your problem and I'm baffled. I think there is an electrical issue. Are you sure you're not confusing GPIO numbers with pin numbers? For example GPIO10 is on Pin14. If the pins are correct I can only suggest double checking the integrity of the wiring. A mechanical encoder such as this one comprises two switches arranged to produce a quadrature signal as described here. The naming of these switches is immaterial: X/Y A/B or CLK/DT. Clockwise/anticlockwise discrimination is done by detecting the relative phase of the two signals, as described in the doc. If the direction is wrong you can swap the wires or swap the pins in |
I'm certain the wiring is correct. I can successfully use
Do you recall which pairs your code treats as equal?
or the reverse? |
Update: I just built and installed it again -- not certain what I changed but now the encoder seems to work! |
Update 2: Looks like the issue is with stopping the simple demo in vscode doesn't exit cleanly. Trying to start it again exits early without an exception (main loop doesn't persist?). Have to reset the Pico, then run the script again and it works fine. I was confused because the screen still showed the simple menu demo but encoder input wasn't registering since the script wasn't running. |
Update 3: The encoder was working, though using it was finicky. Adjusting the input division via the
Ideally, all arguments for the |
In general with I'll give some thought to making the delay configurable but I'm puzzled why you found it necessary. I have experimented with delays from 0 to 1000ms. At 1000ms the delay in response was very evident but behaviour was predictable. I don't know if your encoder has mechanical detents: if it does, it's worth ensuring that the division ratio ( The purpose of the delay is to limit the frequency at which the encoder callback is run. However this callback runs in an |
I have pushed an experimental encoder driver that may help with your problem. Go to the branch If you're in doubt about the right value of the from gui.primitives import Encoder
import asyncio
from machine import Pin
x = Pin(20, Pin.IN, Pin.PULL_UP)
y = Pin(17, Pin.IN, Pin.PULL_UP)
v = 0
n = 0
def cb(a, b):
global v, n
print(b)
v += abs(b)
n += 1
async def main():
enc = Encoder(x, y, callback=cb, delay=500)
await asyncio.sleep(60)
print(f"encoder value is {round(v/n)}")
enc.deinit()
s = """
This script determines the value of the encoder arg for encoders with mechanical
detents. It runs for 60 seconds. After starting, rotate the encoder one click
and wait for a printed result. Repeat with one click each time a result is output.
"""
print(s)
try:
asyncio.run(main())
finally:
_ = asyncio.new_event_loop() Please report your findings. This is quite hard for me to diagnose as the original code works here! |
I have updated |
Hello! Love this project, thank you for all the work you have done so far!
Trying to use a Pico, an SSD1309, and encoder-only mode on my own project, hitting a few obstacles that I could use some help with. The display portion all works, but I can't seem to get the encoder and encoder push button to work as expected.
Encoder
class usesx
andy
input arguments? Most rotary encoders seem to haveCLK
andDT
pins -- it's not clear to me how this translates.For context, here's my
hardware_setup.py
Happy to supply the driver I wrote for the SSD1309 if needed. I can confirm that works as expected. I'll be happy to contribute it for others to use, as well as my own hardware setup example.
Thanks!
The text was updated successfully, but these errors were encountered: