ATtiny412-I2C-Rotary-Encoder icon indicating copy to clipboard operation
ATtiny412-I2C-Rotary-Encoder copied to clipboard

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

Open mcpat-it opened this issue 8 months ago • 3 comments

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

mcpat-it avatar Nov 05 '23 18:11 mcpat-it