wicked4geology
Posts: 1
Joined: Thu Jun 23, 2016 8:11 pm

Flow Meter time intervals

Thu Jun 23, 2016 8:19 pm

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()

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Flow Meter time intervals

Fri Jun 24, 2016 1:41 am

wicked4geology wrote: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!

Code: Select all

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()
Account Inactive

Return to “Python”