hello
I have a water meter with a wire to give pulse every 1L. I would like to use my raspberry pi to count these pulse.
The water meter is a hydrus dn15. The pulse output description is here :
https://manuals.plus/diehl/dn-15-40-hyd ... open_drain
I tried to plug the wires to my rapsberry pi GPIO but did not manage to make it work.
I tried this :
* Pulse 1 to pin 1 (3.3 VDC)
* Pulse 2 to pin 11 (GDPIO 0)
* Ground to pin 6 (ground)
My rpi is
raspberry pi 2 model b v1.1
The GPIO reference I used
https://pi4j.com/1.2/images/j8header-2b.png
Anyone could tell me what I did wrong ??
thanks
-
- Posts: 3
- Joined: Sat Mar 18, 2023 2:23 pm
Re: water meter : pulse count
From the diagram it looks like Pulse1 and Pulse2 are the same, so choose one of them.
Connect Pulse1 or Pulse2 to your GPIO. Connect ground to ground. That's it.
In your software, configure the GPIO as an input with pull-up turned on.
Connect Pulse1 or Pulse2 to your GPIO. Connect ground to ground. That's it.
In your software, configure the GPIO as an input with pull-up turned on.
Hmm. What can I put here?
Re: water meter : pulse count
Do not connect either pulse pin to 3.3V, it will short the supply when the output is low and may damage either the flow meter or the PI. Otherwise connect as ame describes, checking that it really is an open drain output there is no 24V present at either output; that certainly would kill the Pi.
Re: water meter : pulse count
Oh, yes, don't connect the resistor to 24V as shown in the diagram. It is not necessary here.
Hmm. What can I put here?
-
- Posts: 3
- Joined: Sat Mar 18, 2023 2:23 pm
Re: water meter : pulse count
hello
Thanks for your help !! Fortunatly I did not fried my raspberry nor my water meter ...
I think the Gpio schema was not the good one.
This one seems to be better for my raspberry pi 2 model b v1.1
https://www.raspberry-pi-geek.com/howto ... -2-Model-B
But I did not manage to make it work. I tried the following python code, and I tried to short manually GPIO27 (pin13) to ground (pin06). But nothing happens. Any idea ??
thanks !
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
button = 13
GPIO.setup(button, GPIO.IN, GPIO.PUD_UP)
while True:
button_state = GPIO.input(button)
if button_state == GPIO.HIGH:
print ("HIGH")
else:
print ("LOW")
time.sleep(1)
Thanks for your help !! Fortunatly I did not fried my raspberry nor my water meter ...
I think the Gpio schema was not the good one.
This one seems to be better for my raspberry pi 2 model b v1.1
https://www.raspberry-pi-geek.com/howto ... -2-Model-B
But I did not manage to make it work. I tried the following python code, and I tried to short manually GPIO27 (pin13) to ground (pin06). But nothing happens. Any idea ??
thanks !
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
button = 13
GPIO.setup(button, GPIO.IN, GPIO.PUD_UP)
while True:
button_state = GPIO.input(button)
if button_state == GPIO.HIGH:
print ("HIGH")
else:
print ("LOW")
time.sleep(1)
Re: water meter : pulse count
You've got your Pin Numbering set to BCM (Broadcom) mode, but you are using the Board (Physical Pin) numbers.
For GPIO 27 (Pin 13), when using BCM, use 27.
Code: Select all
button = 27
Unreadable squiggle
-
- Posts: 3
- Joined: Sat Mar 18, 2023 2:23 pm
Re: water meter : pulse count
hello
Thanks for all the advices, I managed to make it work : I can see the pulse from the water meter using Python. Which is nice, thanks !
There is one thing left I don't understand.
I made this python script with what I found on the net. It works : it creates a file, then put the timestamp for every pulse detected. This works when I connect in SSh to the PI.
But what I would like is also to start my script everytime the PI boots. I saw that I can do that using crontab, which I did. So now the script starts at boot (I know because it creates a dummy file I see in my PI after each boot). But it does not do the rest of the script at all. This is strange because this script runs well when ran using ssh.
Any idea ???
thanks ...
This is the script.
#!/usr/bin/python /home/pi/water/scripts/water-pulse.py
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import urllib2
import datetime
# raspberry pi 2 model b v1.1
# GPIO number as seen in https://www.raspberry-pi-geek.com/howto ... -2-Model-B
button = 17
# build the filename which will contain the timing for the pulses
mtime=datetime.datetime.now().strftime("%Y%m%d %H%M%S")
mfilename='/home/pi/water/datafiles/mdata-raw_'+mtime[0:15]+'.txt'
mfilename=mfilename.replace(' ', '-')
# build a dummy file to be sure the crontab successfully starts the water-pulse.py script after a reboot
mfilename_boot='/home/pi/water/datafiles/mdata-raw_'+mtime[0:15]+'boot.txt'
mfilename_boot=mfilename_boot.replace(' ', '-')
print(mfilename_boot)
with open(mfilename_boot, "a") as file_object:
file_object.write('booted\n'+mfilename)
# function to be called when a pulse is detected
def button_callback(channel):
mnow=datetime.datetime.now().strftime("%Y%m%d %H%M%S %f")
print(mnow)
with open(mfilename, "a") as file_object:
file_object.write(mnow+'\n')
# gpio setup
GPIO.setwarnings(False) # Ignore warning for now
#GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setmode(GPIO.BCM) # gpio numbering
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set gpio to be an input pin and set initial value to be pulled high
GPIO.add_event_detect(button,GPIO.RISING,callback=button_callback) # Setup event on gpio rising edge
message = input("Watermeter script is started. Press enter to quit\n\n") # Run until someone press enter
# GPIO.cleanup() # Clean up
Thanks for all the advices, I managed to make it work : I can see the pulse from the water meter using Python. Which is nice, thanks !
There is one thing left I don't understand.
I made this python script with what I found on the net. It works : it creates a file, then put the timestamp for every pulse detected. This works when I connect in SSh to the PI.
But what I would like is also to start my script everytime the PI boots. I saw that I can do that using crontab, which I did. So now the script starts at boot (I know because it creates a dummy file I see in my PI after each boot). But it does not do the rest of the script at all. This is strange because this script runs well when ran using ssh.
Any idea ???
thanks ...
This is the script.
#!/usr/bin/python /home/pi/water/scripts/water-pulse.py
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
import urllib2
import datetime
# raspberry pi 2 model b v1.1
# GPIO number as seen in https://www.raspberry-pi-geek.com/howto ... -2-Model-B
button = 17
# build the filename which will contain the timing for the pulses
mtime=datetime.datetime.now().strftime("%Y%m%d %H%M%S")
mfilename='/home/pi/water/datafiles/mdata-raw_'+mtime[0:15]+'.txt'
mfilename=mfilename.replace(' ', '-')
# build a dummy file to be sure the crontab successfully starts the water-pulse.py script after a reboot
mfilename_boot='/home/pi/water/datafiles/mdata-raw_'+mtime[0:15]+'boot.txt'
mfilename_boot=mfilename_boot.replace(' ', '-')
print(mfilename_boot)
with open(mfilename_boot, "a") as file_object:
file_object.write('booted\n'+mfilename)
# function to be called when a pulse is detected
def button_callback(channel):
mnow=datetime.datetime.now().strftime("%Y%m%d %H%M%S %f")
print(mnow)
with open(mfilename, "a") as file_object:
file_object.write(mnow+'\n')
# gpio setup
GPIO.setwarnings(False) # Ignore warning for now
#GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setmode(GPIO.BCM) # gpio numbering
GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set gpio to be an input pin and set initial value to be pulled high
GPIO.add_event_detect(button,GPIO.RISING,callback=button_callback) # Setup event on gpio rising edge
message = input("Watermeter script is started. Press enter to quit\n\n") # Run until someone press enter
# GPIO.cleanup() # Clean up