Hardware Reference
In-Depth Information
if (self.debug):
print "IR Result", IR
print "Ambient Result", ambient
if ((ratio >= 0) & (ratio <= 0.52)):
lux = (0.0315 * ambient) - (0.0593 * ambient * (ratio**1.4))
elif (ratio <= 0.65):
lux = (0.0229 * ambient) - (0.0291 * IR)
elif (ratio <= 0.80):
lux = (0.0157 * ambient) - (0.018 * IR)
elif (ratio <= 1.3):
lux = (0.00338 * ambient) - (0.0026 * IR)
elif (ratio > 1.3):
lux = 0
return lux
oLuxmeter=Luxmeter()
print "LUX HIGH GAIN ", oLuxmeter.getLux(16)
print "LUX LOW GAIN ", oLuxmeter.getLux(1)
print "LUX AUTO GAIN ", oLuxmeter.getLux()
A copy of this script is also available in the GitHub repository for this topic . Be sure you
put this file in the Adafruit_I2C directory. To read the lux values, run:
$ chmod +x tsl2561-lux.py
$ su -c './tsl2561-lux.py'
This script does all of the hard work for you. It reads in the values from the sensor at
the different gain settings and then does the math necessary to convert those values
into lux units.
Accessing the Sensor Directly from the Kernel
It is also possible to interface directly to the TSL2561 sensor via the I2C bus at the
kernel level, assuming you have enabled that support in a custom kernel (as described
in Hack #22 ). First, you need to tell the kernel (as root) to attach the TSL2561 driver to
the I2C device at 0x39 (or 0x29/0x49 if you changed the address with the ADDR pin):
$ su -
$ echo tsl2563 0x39 > /sys/class/i2c-adapter/i2c-1/new_device
When you do this, it will output a message like this to dmesg :
 
Search WWH ::




Custom Search