My daughter and I are trying to build a bead sorting machine. Off a 2040 we’ve got a servo to bring beads under a RGB sensor, and a stepper to control a deposit disc (that will hold containers).
The mechanics seem to work well but I’ve had really poor luck with the RGB detection. I started with a cheap (in every sense) “TCS34725” but the output was garbage. So I bought a Breakout BH1745 from you and while the range of garbage is much wider —it’s making up all sorts of wonderful colours— it’s still not what I want. Which means I’m probably doing it wrong.
There’s loads of light leak through the sides but it also doesn’t work in a pitch black room. I’ve tried messing around with measurement times, LEDs, ADC multipliers and it all just makes it worse. My conclusion is there’s something wrong with the physical setup.
So what’s the Right Way™ to use a BH1745 to measure the colour of something very small directly underneath it?
- Do I need complete light isolation?
- Should the chamber (and its surround in the disc that brings it to the sensor) be black or white or something else?
- Is there anything I could be doing to calibrate the sensor on an empty chamber?
- Is there a physical distance between bead and sensor I should be aiming for? Do I need a lens?
I don’t think there’s anything special about my code. I’m using the BreakoutBH1745
library from the Pimoroni build of MicroPython. I think this is the smallest version of my code that still works.
from machine import I2C, Pin
from breakout_bh1745 import BreakoutBH1745
i2c = I2C(1, scl=15, sda=14)
rgb_sensor = BreakoutBH1745(i2c, 0x38)
rgb_sensor.leds(1)
while True:
rgb = rgb_sensor.rgbc_scaled()[:3]
print('\033[48;2;{0};{1};{2}m#{0:02x}{1:02x}{2:02x}\033[0m'.format(*rgb))
Again, I’ve tried the various rgbc_raw
/ rgbc_clamped
/ rgbc_clamped
methods too.