|
you need to set the Tr as HIGH again, or the Ec will continue to read the data from Tr.
------------
you can simply use the code below to get the distance information.
import ultra
distance = ultra.cheeckdist()
------------
if you don't want to keep read 0 from Ec, you can edit the ultra.py by adding 'GPIO.output(Tr, GPIO.HIGH)' after line 27 t2 = time.time()
like this:
def checkdist(): #Reading distance
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Tr, GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(Ec, GPIO.IN)
GPIO.output(Tr, GPIO.HIGH)
time.sleep(0.000015)
GPIO.output(Tr, GPIO.LOW)
while not GPIO.input(Ec):
pass
t1 = time.time()
while GPIO.input(Ec):
pass
t2 = time.time()
GPIO.output(Tr, GPIO.HIGH) ###<<<add it here
return (t2-t1)*340/2
|
|