Flow Meter Addon for reef-pi

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Hi, quite a few people ask about flow meters so I thought I would make up a simple program to manage them as my skills aren't up to messing in reef-pi. I'll have to put this in the intermediate category right now as it's a little messy changing settings but it's basically set and forget so not that bad, I'll see what I can do moving forward to make it easier, maybe someone has some tips, I'll post again with what I'm trying to accomplish.

The program is c++ and running as a service in the background so it starts when the Pi starts. I'm using the wiringPi library for the GPIO's so this will be installed. You can use any pin and the library will set it up as an interrupt so the code is basically the same as Arduino. I think it's producing good numbers but I'm not setup for real world testing. Either way the numbers should only be used as a reference unless you know you've tuned it in and it's accurate. If you use this please post your results so I can make changes if needed.

In reef-pi you can get current flow rate and total flow volume tracked over time, when the Pi is restarted it will continue where it left off. To reset total volume you need to delete a file on the Pi, explained at the end.

To install run the following 3 commands in the Raspberry Pi terminal window. After it installs if you run htop you'll see flowmeters running.

sudo wget -c https://robo-tank.ca/reef-pi/flowmeters.zip

sudo unzip flowmeters.zip

sudo bash install_flowmeters.sh


The files will be installed to /var/lib/reef-pi/flowmeters/

The CPP files are also copied to that folder if you want to make changes to the program, if you do you need to compile the program by running the following line in the Raspberry Pi terminal window. After compiling the changes should take effect, if not restart Pi.

g++ -o flowmeters flowmeters.cpp -lwiringPi

After you install it you need to adjust the settings file, to do so type in the following command in the Raspberry Pi terminal window. It will prompt to continue, press Y and then you can edit the settings file.

sudo nano /var/lib/reef-pi/flowmeters/settings.txt

This is what you should see.

flows1.PNG


You can see the actual setting value is in single quotes, those must remain and the space between the = sign.
  • First setting is how many flow meters you have, default is 0 so you must change. You can run up to 10 flow meters but easy to increase limit.
  • Second is the GPIO pin numbers you use, the first 6 defaults are for my controller sensor ports 1-6 but can be any GPIO number between 5 and 27. The pins must be in the order you use them, for example pin 5 is defaulted to flow 7, if you only have one flow but use pin 5 you must put 5 for flow 1. If you have 3 flow meters it'll use the top 3 pins only.
  • Third is the calibration factor, this is the F number on the flow meter, a lot are 4.5 but you might have 6 or something, change this to match and the accuracy should be somewhat close. If I can create a front end I'll add calibration procedure.
  • The last 3 settings you can change the output to be imperial or US system in pints, quarts, liters or gallons per second, minute, hour or day, any combination. Default is US liters per hour.
Any time you make a change to the settings file the program must be restarted, you can do that by simply unplugging the Pi from power and plug back in or run the following two commands in the Raspberry Pi terminal window.

sudo systemctl stop flowmeters.service

sudo systemctl start flowmeters.service


Now for the reef-pi side of things.

To view flow rate and total volume you need to create 2 drivers per flow meter in reef-pi. In the picture below you can see one for total volume.
  • For "name" enter anything you feel fit
  • For "type" select "file-analog"
  • For "path" you need to add the following for every driver you create for flow meters, this is the folder where all the files sit.
    • /var/lib/reef-pi/flowmeters/
    • Following that line you need to add the file for the flow meter you want to view
      • totalFlow_0.txt
        • The end result should look like this for total flow volume for flow meter 1.
          • /var/lib/reef-pi/flowmeters/totalFlow_0.txt
        • The end result should look like this for current flow rate for flow meter 1.
          • /var/lib/reef-pi/flowmeters/flowRate_0.txt
The 0 at the end of the file name is the flow meter number, 0 = 1, 1 = 2, etc... For a second flow meter the file name would look like flowRate_1.txt and so on.

flow3.PNG



After you create all the drivers go to the "Admin" tab and press the "Reload" button.

flow6.PNG



Now go to the "connectors" tab and create a connector for each of the drivers you created. Scroll to the bottom of the page and you'll see the header "Analog Inputs" add the connectors under this.
  • For "Name" anything you see fit
  • For "Driver" select the driver for the flow meter you're adding, remember you need two drivers and two connectors per flow meter if you want to view both parameters.
  • For "Pin" select 0, that's all you have in the list.
flow5.PNG



After you create all the connectors go to the "Admin" tab again and press the "Reload" button.

flow6.PNG



Now you can visit the pH tab and add the flow meters, all of the features for pH should work except calibration.

flow4.PNG


The historical chart values will be different than the current chart as the historical is rolling averages at least in my limited testing. Maybe when the flow meter is running full time the chart will be ok.

flow2.PNG


As I mentioned the total flow volume file needs to be deleted if you want the count to start over. First you need to stop the flowmeter service, delete the file and restart the program, the following 3 commands in the Raspberry Pi terminal window to do this. Remember to change the 0 in file name to the flow meter volume you want to delete.

sudo systemctl stop flowmeters.service

sudo rm /var/lib/reef-pi/flowmeters/totalFlow_0.txt

sudo systemctl start flowmeters.service
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Now what I was trying to do was make a front end to change the settings. I discovered if I put a html file in /var/lib/reef-pi/ui/assets/ folder I can view the page by going to the a link like this.


That page would have fields to make changes and calibrate and put this on the beginners level.

Using javascript I'm able to read the settings file so I can do half but of course I can't use javascript to write to the files. This is why I asked about the server reef-pi uses so I could find a connector so I could write to text files. That's all I need and things could get pretty interesting quick. I was playing with Node.js, if I run the js file with node in terminal it does what it should but I wasn't able to fire it from the web page using ajax.

Any ideas? I really want to contribute but very hard working in reef-pi, if I can figure out how to write to files without loading the Pi with more software I can create addons.
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
If anyone downloaded I just realized there was a problem with the total volume. The idea is it saves in liters and converts to what the user wishes to see so you can change on the fly and the chart will update accordingly. This was always showing in liters even if you had gallons selected.

To update just run the 3 commands to install.

sudo wget -c https://robo-tank.ca/reef-pi/flowmeters.zip

sudo unzip flowmeters.zip

sudo bash install_flowmeters.sh
 

swisschris104

Community Member
View Badges
Joined
Mar 19, 2021
Messages
65
Reaction score
57
Location
Palos Hills
Rating - 0%
0   0   0
Hi, new to the forum. I Just ordered the robotank pnp kit and plan on recording/documenting my setup on youtube and/or the forum.

This actually seems really interesting to implement on my return pump, as failsafe to be able to tell if my return pump fails, or gets blocked my a mexican turbo snail that snuck into the sump. I am not the best with electronics and only have basic understanding of how things work. I choose the technical route of becoming a system admin ;Bookworm. I may be starting a new robo-tank build thread where I will mention my plans and update on my progress, but I am going to wait until I get my tank and the board actually comes in.

To hook this up would i just set it up like the attached image and set it to pin 17.
 

Attachments

  • Flow Pump.png
    Flow Pump.png
    598.1 KB · Views: 231
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Hi, new to the forum. I Just ordered the robotank pnp kit and plan on recording/documenting my setup on youtube and/or the forum.

This actually seems really interesting to implement on my return pump, as failsafe to be able to tell if my return pump fails, or gets blocked my a mexican turbo snail that snuck into the sump. I am not the best with electronics and only have basic understanding of how things work. I choose the technical route of becoming a system admin ;Bookworm. I may be starting a new robo-tank build thread where I will mention my plans and update on my progress, but I am going to wait until I get my tank and the board actually comes in.

To hook this up would i just set it up like the attached image and set it to pin 17.
Yeah it's good for things like that. That's exactly how it connects and pin 17 for sensor port 1. You have the jumpers correct too, "Other" gives you a ground where "Optical" has a resistor inline on the ground so that's correct and no pullup or pulldown resistor required so nothing on other jumpers.
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
I forgot to explain how to connect a flow meter directly to a Raspberry Pi. Flow meters need 5v to operate, the Pi is only 3.3v so you need to add a couple resistors to drop the 5v to 3.3v.

The +5v goes to your power supply and the ground to the Pi.

flow8.png
 

swisschris104

Community Member
View Badges
Joined
Mar 19, 2021
Messages
65
Reaction score
57
Location
Palos Hills
Rating - 0%
0   0   0
would it be possible to run 2 x flow meters?
Planning twin returns.
Great work... this just gets better and better...
thanks Rob
Yes, In the first post he mentioned modifying parameters in
/var/lib/reef-pi/flowmeters/settings.txt

2 of those Parameters are
- Flow Meters Connected:
-GPIO pins used:
 

Weasel1960

Valuable Member
View Badges
Joined
Aug 22, 2020
Messages
2,139
Reaction score
9,995
Location
Monticello, WI
Rating - 0%
0   0   0
@robsworld78 Perfect timing. As I develop my plans was thinking of adding flow meters to things like return, UV, etc. I am not sure the reason for tracking total volume but the current flow so things could be fine tuned or visibly see a blockage.

Thanks for developing and definitely following as this develops.
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
@robsworld78 Perfect timing. As I develop my plans was thinking of adding flow meters to things like return, UV, etc. I am not sure the reason for tracking total volume but the current flow so things could be fine tuned or visibly see a blockage.

Thanks for developing and definitely following as this develops.
Great, hope you can make use of it. Yeah having a flow reference to go by can be quite useful with alerts. I agree total volume isn't necessary but it's just a matter of adding what flows so figured why not. If you don't need that info it doesn't need to be imported into reef-pi.
 

Dukereefnz

Active Member
View Badges
Joined
Aug 23, 2020
Messages
380
Reaction score
207
Location
Hunua - New Zealand
Rating - 0%
0   0   0
Hi Rob - looking where the flow meter/s are/ is connected to the robo tank - it looks like the temp sensor plugs?
Above pictures.

is this correct? Planning to use two but need the temp sensors... I know I am missing something here but i cant help being challenged LOL. I am better with a welder and hammer than wires but I am trying!
Thanks
 

swisschris104

Community Member
View Badges
Joined
Mar 19, 2021
Messages
65
Reaction score
57
Location
Palos Hills
Rating - 0%
0   0   0
Hi Rob - looking where the flow meter/s are/ is connected to the robo tank - it looks like the temp sensor plugs?
Above pictures.

is this correct? Planning to use two but need the temp sensors... I know I am missing something here but i cant help being challenged LOL. I am better with a welder and hammer than wires but I am trying!
Thanks
1617118674975.png


I asked Rob this earlier in the thread and hse confirmed it would be this way.

Red - Positive
Yellow - Signal
Black Ground

Yeah it's good for things like that. That's exactly how it connects and pin 17 for sensor port 1. You have the jumpers correct too, "Other" gives you a ground where "Optical" has a resistor inline on the ground so that's correct and no pullup or pulldown resistor required so nothing on other jumpers.
 
OP
OP
robsworld78

robsworld78

Well-Known Member
View Badges
Joined
Feb 14, 2020
Messages
952
Reaction score
1,281
Location
Edmonton, Canada
Rating - 0%
0   0   0
Hi Rob - looking where the flow meter/s are/ is connected to the robo tank - it looks like the temp sensor plugs?
Above pictures.

is this correct? Planning to use two but need the temp sensors... I know I am missing something here but i cant help being challenged LOL. I am better with a welder and hammer than wires but I am trying!
Thanks
They use the sensor ports. Just need to add the one jumper like @swisschris104 circled, the jumper should be on the "other" side of the pins.
 

Algae invading algae: Have you had unwanted algae in your good macroalgae?

  • I regularly have unwanted algae in my macroalgae.

    Votes: 40 34.2%
  • I occasionally have unwanted algae in my macroalgae.

    Votes: 25 21.4%
  • I rarely have unwanted algae in my macroalgae.

    Votes: 9 7.7%
  • I never have unwanted algae in my macroalgae.

    Votes: 8 6.8%
  • I don’t have macroalgae.

    Votes: 31 26.5%
  • Other.

    Votes: 4 3.4%
Back
Top