Wire up a real spectral sensor, control your own lighting, and collect a dataset worth trusting.
A simple RGB sensor reports three broad numbers. The AS7341 instead samples eight narrower wavelength bands — violet through red — giving a much more detailed “fingerprint” of what's in front of it. That detail is only useful if the lighting hitting the sensor is consistent: any stray ambient light shifts every one of the eight channels unpredictably, which is exactly why the AS7341 breakout has its own onboard white LED, controlled over the same I2C connection, that illuminates the Skittle consistently right before each reading rather than trusting the room's lighting. The NeoPixel strip wired up this week is a separate thing entirely — it plays no part in the sensor reading at all, and exists purely to give the person standing at the machine visual feedback (for example, a colour or animation showing what the machine just sorted). The sensor talks to the Pi over I2C, a shared two-wire bus where each device answers to its own address — useful to know when a sensor isn't responding at all.
Connect the AS7341 over I2C (SDA/SCL/3V3/GND — a STEMMA QT cable makes this simple) and the NeoPixel strip to a PWM-capable GPIO pin. These are two independent circuits doing two different jobs — nothing about the sensor reading depends on the NeoPixel being wired at all.
Initialise it in Python and confirm no errors:
import board
from adafruit_as7341 import AS7341
i2c = board.I2C()
sensor = AS7341(i2c)
print("Sensor ready")
The AS7341 breakout has a built-in white LED, controlled over the same I2C connection as the readings — not the NeoPixel. Turn it on to a fixed, known brightness right before each reading, and off otherwise; this consistency is the whole point:
sensor.led_current = 10
sensor.led = True
import time; time.sleep(0.25) # let it settle
# ... take a reading here ...
sensor.led = False
Print all eight values with nothing in front of the sensor first, as a baseline:
print(sensor.channel_415nm, sensor.channel_445nm, sensor.channel_480nm,
sensor.channel_515nm, sensor.channel_555nm, sensor.channel_590nm,
sensor.channel_630nm, sensor.channel_680nm)
Hold a Skittle of each colour to the sensor a few times and print the readings. Notice how, for example, yellow lights up the green/yellow/orange channels strongly while purple stays low across almost everything.
Write a script that appends one row per scan — label, timestamp, then the 8 channel values — to a tab-separated file, matching the column order Violet, Indigo, Blue, Cyan, Green, Yellow, Orange, Red so it's ready for next week's classifier.
Scan at least 5 Skittles per colour, all under the same lighting setup and enclosure — consistency here matters more than volume.
Separately from any of the above, write a tiny script that lights the NeoPixel a different colour depending on a value you pass in — this is the pattern the main program will later use to show the operator what colour was just sorted, entirely independent of the sensor reading itself.
sensor.led = True is actually being called), or the Skittle isn't close enough to the sensor.