_Al
Posts: 1
Joined: Sat Jun 15, 2019 8:58 pm

KY040 Rotary Encoder Python Module

Sat Jun 15, 2019 9:09 pm

Hi All,
I am working on Pi Zero based internet radio (MPD) and ended up writing my own implemention to get the (KY040) rotary encoders working the way I wanted, anyway I have made it available if anyone wants it (https://pypi.org/project/RPi-GPIO-Rotary/ / https://github.com/AllanGallop/RPi_GPIO_Rotary) disclaimer: I am not fantastic with Python by any means. Next stop will be playing with getting the display working!

Install via pip:

Code: Select all

pip3 install RPi_GPIO_Rotary
example:

Code: Select all

from RPi_GPIO_Rotary import rotary

## Define Callback functions
def cwTurn():
    print("CW Turn")

def ccwTurn():
    print("CCW Turn")

def buttonPushed():
    print("Button Pushed")

def valueChanged(count):
    print(count) ## Current Counter value

## Initialise (clk, dt, sw, ticks)
obj = rotary.Rotary(23,24,25,2)

 ## Register callbacks
obj.register(increment=cwTurn, decrement=ccwTurn)

## Register more callbacks
obj.register(pressed=buttonPushed, onchange=valueChanged) 

## Start monitoring the encoder
obj.start() 

Return to “Other projects”