First of all let me introduce the problem. I am busy working on a HC SR04 + servo combination to measure the distance in certain angles. But lately some weird errors are coming up. The script( which i will post down here) worked when we started with it but lately it stopped working and we are getting certain errors which never occured.
This error keeps coming up and we really dont know what we have to do anymore. We installed a clean and new version of Raspbian but that didnt help. Changed our pins but didn't work. Changed the script to work with a Try statement and an except keyboard statement but that didn't work either. So if anyone knows what we are doing wrong, please tell us.
Error # sonar2.py:17: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger ^CTraceback (most recent call last): File "sonar2.py", line 32, in <module> start = time.time() KeyboardInterrupt Script# #!/usr/bin/python # Import required Python libraries import time import RPi.GPIO as GPIO # Use BCM GPIO references # instead of physical pin numbers GPIO.setmode(GPIO.BOARD) # Define GPIO to use on Pi GPIO_TRIGGER = 21 GPIO_ECHO = 15 # 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) # Allow module to settle time.sleep(0.5) # Send 10us pulse to trigger 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() # Calculate pulse length elapsed = stop-start # Distance pulse travelled in that time is time # multiplied by the speed of sound (cm/s) distance = elapsed * 34300 # That was the distance there and back so halve the value distance = distance / 2 print "Afstand : %.1f" % distance # Reset GPIO settings GPIO.cleanup()