#!/usr/bin/python3 #This script uses a as7262 6 colour spectral scanner from Pimoroni and displays the #Spectral results and XYZ colour RGB colour co-coordinates. #raspberryconnect.com from as7262 import AS7262 from colormath.color_objects import SpectralColor,XYZColor from colormath.color_conversions import convert_color as7262 = AS7262() as7262.set_gain(1) # 1, 3.7, 16, 64 as7262.set_integration_time(10) #1 to 255 x 2.8ms exposure #mode 0 - bank 1 only continuous, mode 1 - bank 2 only continuous, mode 2 - both banks continuous, mode 3 - both banks single read as7262.set_measurement_mode(2) #2 all colours continuous as7262.set_illumination_led_current(12.5) #12.5mA 25mA 50mA 100mA as7262.set_illumination_led(1) # led on def spectral_to_xyz(self): """Convert Scan to RGB Colour""" spc = SpectralColor( observer='10', illuminant='D65', spec_650nm=str(self[0]), spec_600nm=str(self[1]), spec_570nm=str(self[2]), spec_550nm=str(self[3]), spec_500nm=str(self[4]), spec_450nm=str(self[5])) xyz = convert_color(spc, XYZColor) #convert spectral signals to XYZ colour space return xyz def cleanup(): as7262.set_measurement_mode(3) #deactivate scanner to scan on command as7262.set_illumination_led(0) #switch off led def main(): try: a = input("Press a key when ready, enter q to quit") while a != "q": values = as7262.get_calibrated_values() #get values from scan spec = [float(i) for i in list(values)] #convert results from string to float xyzcol = spectral_to_xyz(spec) #convert spectral scan to xyz colour space values print("Spectral Scan ROYGBV:",spec) print("XYZ Color",xyzcol) a = input() #wait for user cleanup() except KeyboardInterrupt: cleanup() if __name__ == '__main__': main()