Using a Raspberry Pi 3, I am trying to measure the number of counts from an analog flow meter per unit time. I want to repeat a time interval of pulses per second and print the total number of pulses for each interval. I would also like to export it as a text file if possible.
Below is the working code I am currently using to count pulses. (Python 2.7.9) THANK YOU!
import RPi.GPIO as GPIO
import time, sys
FLOW_SENSOR = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_UP)
global count
count = 0
def countPulse(channel):
global count
count = count+1
print count
GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING, callback=countPulse)
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print '\ncaught keyboard interrupt!, bye'
GPIO.cleanup()
sys.exit()