I'm trying to set up a tachometer. I used a comparator IC to get a real clean signal on pin 21 but I'm getting iterrupts on the rising AND falling edges.
#!/usr/bin/python3 import time import datetime import RPi.GPIO as GPIO def Int21R( channel ): global Count Count += 1 GPIO.output( 20, GPIO.HIGH ) time.sleep( 0.000001 ) GPIO.output( 20, GPIO.LOW ) GPIO.setwarnings(False) GPIO.setmode( GPIO.BCM ) GPIO.setup( 20, GPIO.OUT ) GPIO.setup( 21, GPIO.IN, pull_up_down = GPIO.PUD_OFF ) GPIO.add_event_detect( 21, GPIO.RISING, callback = Int21R ) Count = 0 while True: Time = datetime.datetime.now() print( "%s - Count = %6d RPM = %6d" % ( Time, Count, Count * 60.0 ) ) RPM = Count * 60.0 Count = 0 t = time.time( ) Wait = 1 - ( t - int( t ) ) time.sleep( Wait ) except KeyboardInterrupt: GPIO.cleanup( ) GPIO.cleanup( )
I output a short pulse on pin 20 in the event handler so i can see it on a scope. It's very clear that the event handler is getting called on the rising and falling edges. I get the same results on RPi B+ and RPi Zero W.
What am I missing?
Update: I'm running Jessie with all updates installed.
Update: Same results on an RPi 3Bv1.2.