Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1585

Python • RPi 3 with TCS3200 sensor: lgpio.error: 'bad event request'

$
0
0
Hello there,

I am working on a student project that measures colour with the TCS3200 and a RPi 3 but I'm running into an issue with the code. When I try to run my code while the sensor is looking at something bright (produces a high frequency on the TCS3200 output pin) I get an error that I don't know how to fix.

My code is:

Code:

'''Output pins:    output 1 -> board 19 -> bcm 10'''import timeimport RPi.GPIO as GPIOdef meas(rep):    for i in range(rep):        # chooses active diodes        GPIO.output(S2_pin, GPIO.HIGH)        GPIO.output(S3_pin, GPIO.LOW)                time.sleep(0.01)                count = 0        start = time.time()                while (meas_time - (time.time() - start)) > 0:            GPIO.wait_for_edge(out_1_pin, GPIO.RISING)            count += 1                print(count)S0_pin = 11S1_pin = 12S2_pin = 15S3_pin = 13out_1_pin = 19# initialisation of GPIOGPIO.setmode(GPIO.BOARD)GPIO.setwarnings(False)GPIO.setup(S0_pin, GPIO.OUT)GPIO.setup(S1_pin, GPIO.OUT)GPIO.setup(S2_pin, GPIO.OUT)GPIO.setup(S3_pin, GPIO.OUT)GPIO.setup(out_1_pin, GPIO.IN, pull_up_down = GPIO.PUD_UP)# frequency scalingGPIO.output(S0_pin, GPIO.LOW)GPIO.output(S1_pin, GPIO.HIGH)# testmeas_time = 2# interval for measuringrep_num = 10# number of repetitionsmeas(rep_num)
When the sensor outputs higher frequencies I get these errors:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 800, in wait_for_edge
alert = _get_alert(gpio, mode, edge, bouncetime)
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 295, in _get_alert
alert = _alerts[gpio]
KeyError: 10

During handling of the above exception, another exception occorred:

Traceback (most recent call last):
File "/home/rpi/Documents/svetloba/test.py", line 48, in <module>
meas(rep_num)
File "/home/rpi/Documents/svetloba/test.py", line 19, in meas
GPIO.wait_for_edge(out_1_pin, GPIO.RISING)
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 803, in wait_for_edge
alert = _set_alert(gpio, mode, edge, bouncetime)
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 309, in _set_alert
_check(lgpio.gpio_claim_alert(_chip, gpio, {
File "/usr/lib/python3/dist-packages/lgpio.py", line 1294, in gpio_claim_alert
return _u2i(_lgpio._gpio_claim_alert(
File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i
raise error(error_text(v))
lgpio.error: 'bad event request'

If anyone knows what could be going wrong, please let me know.

Statistics: Posted by robold — Mon Oct 27, 2025 4:56 pm



Viewing all articles
Browse latest Browse all 1585

Trending Articles