Closed bgewehr closed 9 years ago
Hi Bernd,
Glad to see you are getting some good use out of that script.
Unfortunately I am extremely time poor at the moment so won't be able to help you out right now. Plus I am not really sure what you want me to look at?
Python is very easy to learn and play around with however so dive in and see how you go :).
All the best, Ben
On 7/07/2015 5:05 p.m., Bernd Gewehr wrote:
Hi Sumnerboy,
I use your script in my sprinkler automation, works like a charm!
For water flow meters which give a linear frequency of up to 100Hz when the water flows I want to add a frequency counter mode like in this code snippet:
http://stackoverflow.com/a/23188184
Could you please help me out with my poor Python skills?
To support
- io write
- monitor status
- monitor frequency
Sounds good, right?
— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/6.
Bernd,
What water flow meters are you talking about? (could you point me to the datasheet?)
Thanks On Jul 7, 2015 2:05 AM, "Bernd Gewehr" notifications@github.com wrote:
Hi Sumnerboy,
I use your script in my sprinkler automation, works like a charm!
For water flow meters which give a linear frequency of up to 100Hz when the water flows I want to add a frequency counter mode like in this code snippet:
http://stackoverflow.com/a/23188184
Could you please help me out with my poor Python skills?
To support
- io write
- monitor status
- monitor frequency
Sounds good, right?
— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/6.
it's these ones: http://www.adafruit.com/products/828
Thanks
Josenivaldo Benito Jr. PU2LBD
On Tue, Jul 7, 2015 at 10:25 AM, Bernd Gewehr notifications@github.com wrote:
it's these ones: http://www.adafruit.com/products/828
— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/6#issuecomment-119201772 .
@jrbenito Are you also working on that? Can you help to code it in Python?
Hi @bgewehr,
Actually not. I was just curious because I have an idea that I never implemented (and probably will not). I am not expert in Python but as Ben said it is easy to learn and read other's code.
I read quickly the Adafruit page, Arduino sketch example and stackoverflow snippet and make the assumptions:
.You want to read the frequency from sensor (the snippet will do it for you) (I think you meant "read from sensor" when you wrote "io write" and this is done by RPi.GPIO library) The code on stackoverflow seems to do exactly this, you can just copy it .Calculate liters (Liters = Pulses / (7.5 * 60)) (from Arduino sketch, in python it is similar to write this math) .Post on MQTT for status reading (you can copy from Ben script, it does the mqtt connection and reads, to write is the same but you will use publish method)
I don't have a setup to test or try it here but you can do there and post send your doubts so we can figure it out together.
I have a frequency counting routine working now. It uses pigpiod (http://abyz.co.uk/rpi/pigpio/index.html) which must be running at startup of the script Could you help me to put it into the mqtt script or would you prefer to run ist as a seperate script daemon?
#!/usr/bin/env python
import time
import pigpio
# 2014-10-25
# l298n-pwm-run1.py
# Public Domain
HALL1=17
HALL2=18
HALL3=22
HALL4=27
class hall:
"""
A class to read a Hall effect sensor.
"""
def __init__(self, pi, gpio):
"""
"""
self.pi = pi
self.gpio = gpio
self.old_mode = self.pi.get_mode(self.gpio)
self.pi.set_mode(self.gpio, pigpio.INPUT)
self.pi.set_pull_up_down(self.gpio, pigpio.PUD_UP)
self.cb = self.pi.callback(self.gpio)
self.tally = 0
self.inited = True
def pulses(self):
if self.inited:
self.tally = self.cb.tally()
return self.tally
def cancel(self):
if self.inited:
self.inited = False
self.cb.cancel()
self.pi.set_mode(self.gpio, self.old_mode)
DELAY=3
pi=pigpio.pi()
h1 = hall(pi, HALL1)
h2 = hall(pi, HALL2)
h3 = hall(pi, HALL3)
h4 = hall(pi, HALL4)
while 1:
h1sp = h1.pulses()
h2sp = h2.pulses()
h3sp = h3.pulses()
h4sp = h4.pulses()
time.sleep(DELAY)
h1ep = h1.pulses()
h2ep = h2.pulses()
h3ep = h3.pulses()
h4ep = h4.pulses()
print("E {} {} {} {} {}".format(DELAY, h1ep-h1sp, h2ep-h2sp, h3ep-h3sp, h4ep-h4sp))
h1.cancel()
h2.cancel()
h3.cancel()
h4.cancel()
pi.stop()
Hi Bernd,
I think this would be better run in a separate script, or you can modify a local version of my script, but I don't feel this is suitable for merging into the master version of mqtt-gpio-monitor.
Cheers, Ben
On 12/07/2015 11:24 p.m., Bernd Gewehr wrote:
I have a frequency counting routine working now. It uses pigpiod (http://abyz.co.uk/rpi/pigpio/index.html) which must be running at startup of the script Could you help me to put it into the mqtt script or would you prefer to run ist as a seperate script daemon?
|#!/usr/bin/env python import time import pigpio
2014-10-25
l298n-pwm-run1.py
Public Domain
HALL1=17 HALL2=18 HALL3=22 HALL4=27
class hall: """ A class to read a Hall effect sensor. """
def __init__(self, pi, gpio): """ """ self.pi = pi self.gpio = gpio self.old_mode = self.pi.get_mode(self.gpio) self.pi.set_mode(self.gpio, pigpio.INPUT) self.pi.set_pull_up_down(self.gpio, pigpio.PUD_UP) self.cb = self.pi.callback(self.gpio) self.tally = 0 self.inited = True def pulses(self): if self.inited: self.tally = self.cb.tally() return self.tally def cancel(self): if self.inited: self.inited = False self.cb.cancel() self.pi.set_mode(self.gpio, self.old_mode)
DELAY=3
pi=pigpio.pi()
h1 = hall(pi, HALL1) h2 = hall(pi, HALL2) h3 = hall(pi, HALL3) h4 = hall(pi, HALL4)
while 1:
h1sp = h1.pulses() h2sp = h2.pulses() h3sp = h3.pulses() h4sp = h4.pulses() time.sleep(DELAY) h1ep = h1.pulses() h2ep = h2.pulses() h3ep = h3.pulses() h4ep = h4.pulses() print("E {} {} {} {} {}".format(DELAY, h1ep-h1sp, h2ep-h2sp, h3ep-h3sp, h4ep-h4sp))
h1.cancel() h2.cancel() h3.cancel() h4.cancel()
pi.stop() |
— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/6#issuecomment-120709240.
Ok, Ben thank you for your time! I'll give it a try at my own fork...
Hi Sumnerboy,
I use your script in my sprinkler automation, works like a charm!
For water flow meters which give a linear frequency of up to 100Hz when the water flows I want to add a frequency counter mode like in this code snippet:
http://stackoverflow.com/a/23188184
Could you please help me out with my poor Python skills?
To support
Sounds good, right?