Skip to content

rpi python - only get state of rotary encoder wheel but not from switch #2

@mcpat-it

Description

@mcpat-it

Hi,

I tried to get the value with python on raspberry pi via smbus, but I don't know how to get the rotary enoder switch state, could you please help?
Here my code for now which is reading the value of the wheel:

from smbus import SMBus
import time

addr = 0x36 # bus address
bus = SMBus(1) # indicates /dev/ic2-1
oldvalue = 0

while True:
	try:
		z = bus.read_byte(addr)
		if z != oldvalue:
			oldvalue = z
			print(z, end = "\r")

		time.sleep(0.25)
	except:
		print('exiting...')
		break

And second question, is there a better way to get the actual value without a while loop?

Thank you in advance,
Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions