As i am new to raspberry pi and learning python with pi. i am trying to get the encoder reading over interrupt. Below is my code, my Encoder is of 1000 PPR. I am getting around 1000 PPR at slow speed but at high speed pi is missing pulses. So my question is "is the below code is correct ?" if not "How to get 1000PPR at high speed ?" and "What is the default bouncetime in GPIO.add_event_detect ?"
Thanks in advance
Code: Select all
import RPi.GPIO as GPIO import time GPIO.setmode (GPIO.BOARD) GPIO.setwarnings(False) pin_A = 3 pin_B = 5 Encoder_Count = 0 # Encoder Count variable GPIO.setup (pin_A, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pin input pullup GPIO.setup (pin_B, GPIO.IN, pull_up_down=GPIO.PUD_UP) # pin input pullup def do_Encoder(channel): global Encoder_Count if GPIO.input(pin_B) == 1: Encoder_Count += 1 else: Encoder_Count -= 1 GPIO.add_event_detect (pin_A, GPIO.FALLING, callback=do_Encoder) # Enable interrupt while(1): global Encoder_Count print Encoder_Count