#!/usr/bin/python # TSL2561 import smbus import time address = 0x29 # Get I2C bus bus = smbus.SMBus(1) # Select control register, 0x00 with command register, 0x80 # 0x03 == Power ON mode bus.write_byte_data(address, 0x00 | 0x80, 0x03) # Select timing register, 0x01 with command register, 0x80 # 0x02 == Nominal integration time INTEG=402ms, GAIN=1X bus.write_byte_data(address, 0x01 | 0x80, 0x02) time.sleep(0.5) # Read data back from 0x0C with command register, 0xA0, Read Word # ch0 LSB, ch0 MSB data0 = bus.read_i2c_block_data(address, 0x0C | 0xA0, 2) # Read data back from 0x0E with command register, 0xA0, Read Word # ch1 LSB, ch1 MSB data1 = bus.read_i2c_block_data(address, 0x0E | 0xA0, 2) # Convert the data ch0 = data0[1] * 256 + data0[0] ch1 = data1[1] * 256 + data1[0] # Output data to screen print "Full Spectrum(IR + Visible) :%d lux" %ch0 print "Infrared Value :%d lux" %ch1 print "Visible Value :%d lux" %(ch0 - ch1)