I'm trying to read interrupts and detect direction of interrupts from an encoder using a raspberry pi , it is USdigital Brand "H6BM-1000-500-IE-S-H" , it has 1000 signals per revolution , the thing is that when I run my python program , I loose some steps (probably because of python speed) , I switched from RPi.GPIO to pigpio , because pigpio is written in C , and got all the interrupts right , the thing is that when I add python code on the callback function it looses steps , leaving me on the same spot as before , my next idea is to write the encoder interrupt value into a Register on the raspberry pi , so on my python program I only need to read the value , like a link between python and C , but I dont know how to detect interrupts on C and write them into a register , any help?
new ideas are also welcome
heres my code till now
#!/usr/bin/env python
import time
import math as m
import pigpio # http://abyz.me.uk/rpi/pigpio/python.html
class Signal(object):
"""docstring for Interrupt"""
def __init__(self, pinA , pinB):
self.pinA = pinA
self.pinB = pinB
self.gpio = pigpio.pi()
self.perimetro = 40*m.pi
self.cuenta = 0
self.estado = 0
self.tiempo_actual = 0
self.tiempo_anterior = time.time()
self.velocidad = 0
#Definicion de funciones que correran al interrumpirse en los pines
self.interrupcionA = self.gpio.callback(self.pinA, edge = pigpio.FALLING_EDGE ,func = self.guia)
#self.interrupcionB = self.gpio.callback(self.pinB, edge = pigpio.EITHER_EDGE , func = self.referencia)
def guia(self,a,b,c):
self.tiempo_actual = time.time()
if int(self.gpio.read(self.pinB)):
self.cuenta += 1
if not int(self.gpio.read(self.pinB)):
self.cuenta -= 1
tiempo = self.tiempo_actual-self.tiempo_anterior
self.tiempo_anterior = self.tiempo_actual
self.velocidad = (self.perimetro/1000)/tiempo
print "cuenta en %s" % self.cuenta
def main():
encoder = Signal(21,20)
try:
while 1:
time.sleep(1)
except KeyboardInterrupt:
pigpio.pi().clear_bank_1(bin(2**20+2**21))
if __name__ == '__main__':
main()