pyKY040
pyKY040 copied to clipboard
Switch Pin with "device" configuration
I'm trying to use the "device" configuration rather than the GPIO pins and I have it working perfectly for the rotary encoder. How would I go about monitoring the button pushes through the same "device" method?
Thanks Kris
Hi @beaconIOT,
You would use the following code:
my_encoder = pyky040.Encoder(device='/dev/input/event0')
Check https://python-evdev.readthedocs.io/en/latest/usage.html#listing-accessible-event-devices to list your devices if event0 is not working.
Please confirm if it worked so I can close the issue and update the README :)
Hey @raphaelyancey, thanks for the response. So right now I have the following added to my boot/config.txt file:
dtoverlay=rotary-encoder,pin_a=13,pin_b=6,relative_axis=1
dtoverlay=gpio-key,gpio=19,keycode=28,label="ENTER"
and in my code, I have the below.
def my_callback(scale_position):
global cursorPosition
print('Hello world! The scale position is {}'.format(scale_position))
cursorPosition = scale_position
menuLayout()
# Init the encoder pins
#my_encoder = pyky040.Encoder(CLK=17, DT=18, SW=26)
# Or the encoder as a device (must be installed on the system beforehand!)
my_encoder = pyky040.Encoder(device='/dev/input/event1')
# Setup the options and callbacks (see documentation)
my_encoder.setup(scale_min=0, scale_max=100, step=1, chg_callback=my_callback)
# Create the thread
my_thread = threading.Thread(target=my_encoder.watch)
# Launch the thread
my_thread.start()
The rotary encoder works great, but the button pushes/switch isn't recognized by the code and that's what I'm trying to figure out. Sorry if I misunderstood you're answer above. Right now event1 handles the rotary encoder and event0 handles the switch/button pushes (tested with evtest) so I imagine I need a callback to handle event0
For Button Pushes I see:
pi@raspberrypi:~ $ cat /dev/input/event0
?*?^??*?^??*?^?,?*?^?,?*?^???*?^??^
For Rotary Encoder movement I see:
pi@raspberrypi:~ $ cat /dev/input/event1
+?^#+?^#+?^??+?^??^
Oh I'm sorry I've read too fast. Unfortunately you're right, the switch feature is not working in device mode (code).
I'll take a look at it but don't count on it being ready in the next days, if it's urgent for you. I'll bump the issue when it's done anyway.
Hello,
I just set up your library in device mode and it's working like a charm for the rotary encoder. I would also like to use the button in device mode. Has my any change someone already implemented that?
Regards,
Michael
I also bumped into this and i need to have my rotaries in device mode for accuracy. Also need this enhancement to recognize the switch event..
Thanks.