Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tank Level control & Drain valve closure
#7
Hi Dan,

Sorry I'm new to this and willing to learn. I was asking when the rain sensor has detected rain, excluding the use of any station, to be able to run anytime, and to use a spare gpio to energize a relay to close the drain actuators. Sorry but I have very limited experience with python as well, but would it be easier to create a plugin from proto.py? 

With the water level, I was asking to have a constant readout of the water level on the home page down near the cpu temp. I'm not sure how to add this code (below) as a plugin to use and then have it as a selection to stop stations once water level is to low.
Code:
#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# ultrasonic_2.py
# Measure distance using an ultrasonic module
# in a loop.
#
# Author : Matt Hawkins
# Date   : 28/01/2013

# -----------------------
# Import required Python libraries
# -----------------------
import time
import RPi.GPIO as GPIO

# -----------------------
# Define some functions
# -----------------------

def measure():
 # This function measures a distance
 GPIO.output(GPIO_TRIGGER, True)
 time.sleep(0.00001)
 GPIO.output(GPIO_TRIGGER, False)
 start = time.time()

 while GPIO.input(GPIO_ECHO)==0:
   start = time.time()

 while GPIO.input(GPIO_ECHO)==1:
   stop = time.time()

 elapsed = stop-start
 distance = (elapsed * 34300)/2

 return distance

def measure_average():
 # This function takes 3 measurements and
 # returns the average.
 distance1=measure()
 time.sleep(0.1)
 distance2=measure()
 time.sleep(0.1)
 distance3=measure()
 distance = distance1 + distance2 + distance3
 distance = distance / 3
 return distance

# -----------------------
# Main Script
# -----------------------

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO    = 24

print "Ultrasonic Measurement"

# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT)  # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN)      # Echo

# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)

# Wrap main content in a try block so we can
# catch the user pressing CTRL-C and run the
# GPIO cleanup function. This will also prevent
# the user seeing lots of unnecessary error
# messages.
try:

 while True:

   distance = measure_average()
   print "Distance : %.1f" % distance
   time.sleep(1)

except KeyboardInterrupt:
 # User pressed CTRL-C
 # Reset GPIO settings
 GPIO.cleanup()
 
Best regards,

Ben
Reply


Messages In This Thread
RE: Tank Level control & Drain valve closure - by beno_283 - 2018 Oct 13, 01:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)