To make a long story short I am trying to read frequency on the RPi2's GPIO pins. The goal eventually would be to use this frequency signal to control a PyGame platformer that I have created. However I am having some consistency problems with the RPi.GPIO library. I am running the code below just to test the functionality:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) pin = 4 pull_up_down = GPIO.PUD_OFF GPIO.setup(pin, GPIO.IN, pull_up_down) NUM_CYCLES = 10 run = True while run: try: start = time.time() for impulse_count in range (NUM_CYCLES): GPIO.wait_for_edge(sensor, GPIO.FALLING) duration = time.time() - start frequency = NUM_CYCLES / duration print(frequency) except KeyboardInterrupt: GPIO.cleanup() run = False
I can run this code and get a pretty good reading, although the frequency value I get is not the actual frequency. That doesn't matter because it is the change in frequency that is important to me and I can clearly measure that. However, if I do a KeyboardInterrupt the program stops, as it should, and I get the following message in the terminal:
Message from syslogd@raspberrypi at Feb 17 01:34:53 ...
kernel:[ 373.646034] Disabling IRQ #49
From what I can tell the GPIO.cleanup() function is causing this, and if I run the code again it does not work, unless I reboot the Pi.
I have seen the question kernel Disabling IRQ #49 but to be honest I understand maybe half of it is happening while he is running his script. Is there anyone who has run into this problem or knows why this is happening and could maybe explain it to someone who is new to Raspberry and Linux?