This Code is written by ChatGPT on the base of the Arduino library. The output is always like 5 no matter what surface the sensor is infront-> means it clearly doesnt work since in the description white should return a value of like 150 and black of over 1000.
The connections are pretty straight forward.
VCC to 3.3V
GND to GND
ODD to GPIO 17 (PIN 11, WiringPi Pin 0)
1 to GPIO 27 (Pin 13, WiringPi Pin 2)
for the beginning I only connect 1 emmiter to test if it works. The EVN pin is not connected but I reckon it doesnt matter, since I only connected emmiter 1.
Can you post some pictures showing your connections as well as your setup for testing the senor? Also, do you have something else you can monitor the sensor output with (like an oscilloscope), or do you have another device that you can test the sensor with (like a Raspberry Pi Pico or an Arduino)? In general, Raspberry Pi computers are not well suited for timing sensitive tasks like controlling and reading these types of sensors.
I sadly dont have a other device to test it nor an oscilloscope. The only thing I have is a multimeter.
I sadly have no other option rather than a Raspberry Pi. Is it just not optimal or is it not possible. I only have to differentiate black and white for now, so if its just not that accurate with a Pi thats fine as long there is a comfortable gap between those two to differentiate it from another.
The connections look okay in your pictures, but we tried it with a Raspberry Pi here and only observed outputs around 5 µs when there was nothing connected, so please check those again. You might want to try different rows on your breadboard or replacing your jumper wires as well.
We also found that for the sensor to work well we had to add something disabling the pull-downs on the GPIO connected to your sensor output pin. We used the command below, which you can add into your readQTRSensor() function after you change the pin mode to input:
Now an other question. I dont have enough GPIO pins to connect all emmiters. Does a simple GPIO port expander like this work? Or in other words is this fast enough to detect the difference between white and black, or does it only take time to switch from one channel to another?
We have not tried a setup like that ourselves, but since reading these sensors relies on timing how long it takes the signal pin to drop farther than your input’s low threshold, anything that adds to how long it takes to ready your digital pins is going to negatively impact the resolution of your measurements. Ultimately, it will be up to you to figure out whether that trade-off is acceptable in your application, but a better approach might be to use a separate microcontroller (like a Raspberry Pi Pico, an Arduino, or one of our Arduino compatible A-Stars) to read the sensors and communicate the result back to your Raspberry Pi 5.