Flow Meter Sample Code
I don't have any flow meters but my understanding is you could use the RPM Input and determine the flow rate based on the RPM. This can be used with a Conditional Function to open/close a solenoid or valve, either via on/off-open/closed or PWM to adjust the opening based on the flow range (e.g. 5 <= flow_rpm <= 10, do this, 10 <= flow_rpm <= 15, do that) . A PID could also be used with the flow RPM Input to adjust a PWM signal that adjusts a valve's opening.
Furthermore, you can create a conversion at Configure -> Measurements -> Add Conversion, for example, RPM to water speed (liters per hour), with the conversion x*10. Then in the RPM Input, you can set the conversion from measured RPM to liters per hour. This would allow for convenient measurement storage as the exact flow and makes programming downstream easier.
Following up on this thread from a while ago-- I'm trying using a flow meter to dispense specific volumes of liquid through a trigger
Example: a button triggers a relay that turns on a pump. The pump stays on until a specific volume of liquid flows through the flow meter.
A few questions:
- Is there a way to pass parameters to mycodo as part of the trigger? I'm thinking of having another python application calling the trigger.
- I think I can use the conversion feature of mycodo to convert pulses to mL, but is there a way to calibrate this through mycodo-client python parameters?
- If I have two sensors with different pulse to mL conversions, is there a better way to distinguish between the conversions than just giving them different names?
- Is there a way to store other variables/data in the influx database that mycodo uses?
- I want to be able to have a variable that I can read externally that contains the volume of liquid last dispensed. This will be important for a manual dispensing mode (the variable continuously increments as liquid is dispensed and would be reset to 0 on trigger event).
- I did think of using the sum function from start and stop timestamps
There are a lot of ways to accomplish dispensing a specific amount of liquid using a solenoid and flow meter. But there are a few things I'd need to understand to be able to configure Mycodo to do so.
1. What will determine when fluid needs to be dispensed?
2. What will determine how much needs to be dispensed?
Also, any numeric data can be both stored in and retrieved from influxdb.
The two use cases that I'm currently working on is a button press (software or hardware) that dispenses a predetermined volume of water (eg: button A dispenses 30mL; button B dispenses 100mL, etc) and a button press that turns dispenses an amount of water that is not predetermined (manual mode). In the not predetermined case, I want to be able to represent the volume of water, while it is being dispensed, as sort of a ticker. This would be for something like filling up a container for which you don't know its volume.
The best real world analogy that I can relate this to is those water bottle filling stations. I'll have a preset button (fill my 16oz bottle) and I'll have a manual fill button. For this manual fill button, as you're filling the bottle it would tick up from 0 fl oz to the total volume as you fill.
Overall, the main thing that I want to keep track of is the volume of water that was just dispensed (real-time, if possible).
Sorry to bump- Thinking about this further, I'm not sure if trying to do all of the above in mycodo is the best method. I'm thinking maybe I should track the individual session event's pulses via the initiating python script.
Per the above, is there an API for the using/modifying the unit conversions that are in mycodo?
I'm having a difficult time thinking of a good solution to your desired effect. There are Atlas Scientific peristaltic pumps that I recently integrated into Mycodo that can pump specific volumes and would work wonderfully for this application. However, what you want to accomplish is a bit more complex, as you will need to poll the sensor very quickly to get an accurate assessment of how fast the fluid is flowing and when to start/stop the flow. I'm leaning toward some custom script that Mycodo basically can call with a parameter such as --time_seconds 10 or --volume_ml 50 to initiate a dispense.
The flow meter is an edge sensor. Since each pulse will be a specific volume of liquid, once the number of edge detection are recorded the GPIO pin controlling the pump and solenoid can be triggered off.
- Command --volume_ml 50
- Begin counting edge detection of flow meter at time stamp 17:39:01.31.
- While count < 50 * pulse_to_ml_conversion GPIO pump & solenoid 1 HIGH
- Result log: 50 ml targeted, 51 ml dispensed [pulses * pulse_to_ml_conversion]
Again, not sure how much of this makes sense to be done in mycodo vs an external python script... I think for mycodo I'd really like to be able to use the unit conversion functions through parameters (query what conversion and modify the conversion). Additionally, is there a way to use the SUM function with timestamps?