Dec-23-2018, 07:09 PM
Hello,
thank you, it works. I do a code to print the speed of the encoder bu it does'nt works, the max that he prints is 4, i think it's a probleme like the speed of python to detect rising edge. Can you help me because i need the speed but i dont know how to do now. My first idea is mesuring the time between two riing edge and after calculate the speed but it doesn't works. Do you have other idea of code that could works?
thank you, it works. I do a code to print the speed of the encoder bu it does'nt works, the max that he prints is 4, i think it's a probleme like the speed of python to detect rising edge. Can you help me because i need the speed but i dont know how to do now. My first idea is mesuring the time between two riing edge and after calculate the speed but it doesn't works. Do you have other idea of code that could works?
# coding: utf-_ import RPi.GPIO as GPIO import time lasttime=0 def callback_up(channel): global lasttime if lasttime==0: lasttime=time.time() else: now = time.time() gap=now-lasttime vitesse=(1/(gap*256))*257 print(vitesse) lasttime=now GPIO.setmode(GPIO.BCM) PIR = 23 GPIO.setup(PIR, GPIO.IN) try: GPIO.add_event_detect(PIR, GPIO.RISING, callback=callback_up) while 1: time.sleep(10) exept KeyboardInterrupt: print("fin")