Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Alright guys, I need to monitor hall sensors for position encoding with up to 350 changes per second. My current Python program watches GPIO pins but uses too much CPU. Here’s my polling loop:
REFRESH_RATE = .0005
while True:
new_p1_state = GPIO.input(hall_p1)
new_p2_state = GPIO.input(hall_p2)
if new_p1_state != p1_state or new_p2_state != p2_state:
if p1_state == GPIO.HIGH:
if new_p2_state == GPIO.HIGH:
position -= 1
else:
position += 1
else:
if new_p2_state == GPIO.LOW:
position -= 1
else:
position += 1
p1_state = new_p1_state
p2_state = new_p2_state
time.sleep(REFRESH_RATE)
How can I make this more efficient? Should I use a different language or tool? If so, which one?
@Middleware & OS
CONTRIBUTE TO THIS THREAD