I would like to know how I can fix this error, the code in question Im using an TCS3200, the pinout is: TCS3200 Color Sensor has 8-pins. Connect Pins 1 and 2 i.e. S0 and S1 to +5V. Then connect theand GND to gnd of the Raspberry Pi.
Connect the VDD pin of the TCS3200 Color Sensor to +5V of Raspberry Pi. Pin 6 i.e. OUT pin of the Sensor is connected to Physical Pin 22 i.e. GPIO25 of Raspberry Pi.
Finally, connect the S2 and S3 of the color sensor to physical pins 16 and 18 i.e. GPIO23 and GPIO24 of the Raspberry Pi.
Here is the code:
`
`
and here is the error:
import RPi.GPIO as GPIO
import time
s2 = 23
s3 = 24
signal = 25
NUM_CYCLES = 10
def setup():
GPIO.setwarnings(False) # Desactivar las advertencias de GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(signal, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(s2, GPIO.OUT)
GPIO.setup(s3, GPIO.OUT)
print("n")
def loop():
temp = 1
while True:
GPIO.output(s2, GPIO.LOW)
GPIO.output(s3, GPIO.LOW)
time.sleep(0.3)
start = time.time()
for impulse_count in range(NUM_CYCLES):
GPIO.wait_for_edge(signal, GPIO.FALLING)
duration = time.time() - start
red = NUM_CYCLES / duration
GPIO.output(s2, GPIO.LOW)
GPIO.output(s3, GPIO.HIGH)
time.sleep(0.3)
start = time.time()
for impulse_count in range(NUM_CYCLES):
GPIO.wait_for_edge(signal, GPIO.FALLING)
duration = time.time() - start
blue = NUM_CYCLES / duration
GPIO.output(s2, GPIO.HIGH)
GPIO.output(s3, GPIO.HIGH)
time.sleep(0.3)
start = time.time()
for impulse_count in range(NUM_CYCLES):
GPIO.wait_for_edge(signal, GPIO.FALLING)
duration = time.time() - start
green = NUM_CYCLES / duration
if green < 7000 and blue < 7000 and red > 12000:
print("red")
temp = 1
elif red < 12000 and blue < 12000 and green > 12000:
print("green")
temp = 1
elif green < 7000 and red < 7000 and blue > 12000:
print("blue")
temp = 1
elif red > 10000 and green > 10000 and blue > 10000 and temp == 1:
print("place the object.....")
temp = 0
def endprogram():
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
endprogram()
/media/diego/D21D-2733/Codigo/Couleur.py:15: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(s2,GPIO.OUT)
/media/diego/D21D-2733/Codigo/Couleur.py:16: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(s3,GPIO.OUT)
Traceback (most recent call last):
File "/media/diego/D21D-2733/Codigo/Couleur.py", line 78, in <module>
loop()
File "/media/diego/D21D-2733/Codigo/Couleur.py", line 32, in loop
GPIO.wait_for_edge(signal, GPIO.FALLING)
RuntimeError: Error waiting for edge
------------------
(program exited with code: 1)
Press return to continue
I have tried to check the pinout again and its good, sudo apt update, ios 64 bits,
Diego Cortez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.