Add a TSL2561 Lux sensor to the Pi
Please note, the code on this page has not been tested and installed before by me
Power down the Pi before you connect anything to the GPIO pins!
Install i2c-tools
To see the I²C address matrix:
$ sudo apt-get install i2c-tools -y
Check sensor address
$ sudo i2cdetect -y 1
There must now be a number in the matrix, this is the address of the sensor. This is default 0x39.
Install the CircuitPython TSL2561 Library
Check if the library does exist on
pypi.org with the search command
CircuitPython tsl2561
Once you know the name, install it with:
$ pip3 install adafruit-circuitpython-tsl2561
Run that code!
The finish line is right up ahead. You can now run one of the (many in some cases) example scripts we've written for you.
Check out the examples for your library by visiting the repository for the library and looking in the example folder.
In this case, it would be
https://github.com/adafruit/Adafruit_CircuitPython_TSL2561/blob/master/examples/tsl2561_simpletest.py
Save this code to your Pi by copying and pasting it into a text file, downloading it directly from the Pi, etc.
Then in your command line run:
$ python tsl2561_simpletest.py
If the code is in a continuous loop, you can stop this by Ctrl c
Now you're ready to read values from the sensor using any of these properties:
- lux - The computed light lux value measured by the sensor
- broadband - The broadband channel value
- infrared - The infrared channel value
- luminosity - A 2-tuple of broadband and infrared channel values
In addition there are some properties you can both read and write to change how the sensor works:
- gain - Get and set the gain of the light sensor. A value of 0 is low gain mode, and a value of 1 is high gain / 16x mode
- integration_time - Get and set the integration time of the sensor. A value 0 is 13.7ms, 1 is 101ms, 2 is 402ms, and 3 is manual mode
Python
External addresses to Adafruit:
Python & CircuitPython
Python Docs (Adafruit BMP280 Python Library)