-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlowMeter.py
37 lines (27 loc) · 908 Bytes
/
FlowMeter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import sys
import datetime
from Logger import logger
flow = 0
count = 0
class FlowMeter:
def __init__(self, pin, name):
self.pin = pin
self.name = name
self.init_gpio()
def init_gpio(self):
logger.info('initialize: {} pin: {}'.format(self.name, self.pin))
GPIO.setmode(GPIO.BCM)
GPIO.setup(self.pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(self.pin, GPIO.FALLING, callback=self.count_pulse)
def count_pulse(self, channel):
global count
count = count+1
def get_flow_rate(self):
global count
flow = count / 6 # pulse frequency = 6*Q, Q is the flow rate in L/min
logger.info("Flow {}: {} Liter/min".format(self.name, flow))
print("Flow {}: {} Liter/min".format(self.name, flow))
count = 0