The Python example below reports the clear, red, green, and blue light levels for a given sample (printing them to the console).
SDA P3 GPIO 0 (SDA)
SCL P5 GPIO 1 (SCL)
3V3 P1 3V3
bus = smbus.SMBus(1)
# I2C address 0x29
# Register 0x12 has device ver.
# Register addresses must be OR'ed with 0x80
ver = bus.read_byte(0x29)
# version # should be 0x44
if ver == 0x44:
print "Device found\n"
bus.write_byte(0x29, 0x80|0x00) # 0x00 = ENABLE register
bus.write_byte(0x29, 0x01|0x02) # 0x01 = Power on, 0x02 RGB sensors enabled
bus.write_byte(0x29, 0x80|0x14) # Reading results start register 14, LSB then MSB
data = bus.read_i2c_block_data(0x29, 0)
clear = clear = data << 8 | data
red = data << 8 | data
green = data << 8 | data
blue = data << 8 | data
crgb = "C: %s, R: %s, G: %s, B: %s\n" % (clear, red, green, blue)
print "Device not found\n"
To keep this example simple, I have left the timing/power consumption for the analog to digital converters on the sensor board and sensor gain at their default values. For more information about these (and other settings) see the datasheet.