- Joined
- Feb 14, 2020
- Messages
- 946
- Reaction score
- 1,259
- Review score
- +0 /0 /-0
- Location
- Edmonton, Canada
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.
You can see the actual setting value is in single quotes, those must remain and the space between the = sign.
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.
After you create all the drivers go to the "Admin" tab and press the "Reload" button.
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.
After you create all the connectors go to the "Admin" tab again and press the "Reload" button.
Now you can visit the pH tab and add the flow meters, all of the features for pH should work except calibration.
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.
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
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.
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.
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 end result should look like this for total flow volume for flow meter 1.
- totalFlow_0.txt
After you create all the drivers go to the "Admin" tab and press the "Reload" button.
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.
After you create all the connectors go to the "Admin" tab again and press the "Reload" button.
Now you can visit the pH tab and add the flow meters, all of the features for pH should work except calibration.
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.
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