Hallo ihr da draußen,
habe folgendes Problem:
Möchte ein SRF05 Ultraschallsensor mit dem Raspberry Pi betreiben.
-> mit 2 Pins (TRIGGER und ECHO) getrennt überhaupt keine Problem.
Allerdings mit 1 Pin (TRIGGER UND ECHO auf der selben Leitung bekomme ich den Code irgentwie nicht hin. :s
Von der Verkabelung her ist alles Richtig (mehrmals gegengecheckt).
(2x Masse+1PLUS+1SIGNALLEITUNG).
Code wäre dieser Hier:
#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# ultrasonic_1.py
# Measure distance using an ultrasonic module
#
# Author : Matt Hawkins
# Date : 09/01/2013
# -----------------------
# Import required Python libraries
import time
import RPi.GPIO as GPIO
# 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)
# 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()
GPIO.cleanup()
###############################################################
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO.setup(GPIO_TRIGGER,GPIO.IN)
GPIO.input(GPIO_TRIGGER, False)
while GPIO.output(GPIO_TRIGGER)==0:
start = time.time()
while GPIO.input(GPIO_TRIGGER)==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 "Distance : %.1f" % distance
# Reset GPIO settings
GPIO.cleanup()
Daraufhin bekomme ich die Fehlermeldung:
Ultrasonic Measurement
Traceback (most recent call last):
File "ultrasonic_1.py", line 57, in <module>
GPIO.input(GPIO_TRIGGER, False)
TypeError: function takes exactly 1 argument (2 given)
Steh grad total aufm Schlauch bei 38 Grad.
Wäre Super wenn vielleicht jemand über den Code schaut.
Vielen Dank schon mal im Vorraus.