Skip to main content

TSL2591 Python Library

GitHub stars GitHub forks GitHub issues Inspired by Adafruit Build Status

This is a simple python library for the Adafruit TSL2591 breakout board based on the Arduino library from Adafruit. It was developed to work on a Raspberry PI.

Requirements

To use this library, you must have the following:

  1. TSL2591 sensor (not the TSL2561)
  2. I2C enabled device
  3. Python 3 (though Python 2 should technically still work)

Installation

This module can be installed using pip (and can find a copy of this module on PyPi).

pip install python-tsl2591

Quickstart

This library comes with an example file you can use, or you can copy and paste the following:

from python_tsl2591 import tsl2591
import time

if __name__ == '__main__':

    tsl = tsl2591()  # initialize
    # full, ir = tsl.get_full_luminosity()  # Read raw values (full spectrum and infared spectrum).
    # lux = tsl.calculate_lux(full, ir)  # Convert raw values to Lux.

    while True:
        print(tsl.get_current()) # Return object with all values.
        # print (lux, full, ir)
        time.sleep(2)

Install from Source

You can also install this Python module from source:

git clone https://github.com/kyletaylored/python-tsl2591
cd python-tsl2591
python setup.py install

Enabling I2C on your Raspberry Pi

You can enable I2C on the Raspberry Pi by following the instructions on Adafruit.

The quick version is:

  1. Run sudo raspi-config
  2. Select Advanced Options
  3. Enable I2C
  4. Reboot (sudo reboot)

When testing I2C (sudo i2cdetect -y 1), you should see at least one connected device, your TSL2591 at 0x29. For more information, see the FAQ.

FAQ

Fatal error (deprecated)

UPDATE: We have integrated the smbus2 library, which is an smbus library built in Python, and does not require any system packages like smbus-cffi or libffi-dev.

If you do not have those Raspbian packages installed prior to installing this library, you will run into errors that look similar to this.

fatal error: ffi.h: No such file or directory
     #include <ffi.h>
                     ^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

I2C Check for Static Address

Because the TSL2591 connects via I2C, it's always good to run the I2C detection to verify the address is being read. Unlike the TSL2561 with programmable addresses, the TSL2591's address is hard coded and cannot be changed - thus it will always show 0x29.

In the example output below, you can see there are two I2C devices detected, one being the TSL2591.

pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

License

Python files in this repository are released under the MIT license.

Metadata

Release files for python-tsl2591 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-tsl2591 0.2.0
File Size Uploaded
python-tsl2591-0.2.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-tsl2591 0.2.0
File Interpreter ABI Platform
python_tsl2591-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 19.0 kB

Release files / python-tsl2591-0.2.0.tar.gz

Download URL python-tsl2591-0.2.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e4d8c2843b6b78451e31550472a06325a2d6a1b5ba7ee3574849ca5dbc7095fa
BLAKE2b-256 checksum
How to use checksums
3c48173a383806fbf3bcec97868b84c3afc040f47f44090f0a25aa82874561a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / python_tsl2591-0.2.0-py2.py3-none-any.whl

Download URL python_tsl2591-0.2.0-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4568864c7ff7497b2a4418f9113c7dafd9d56239f8795f7bf523945173364ca6
BLAKE2b-256 checksum
How to use checksums
698c165e5103f7374d9aa2604cddc1ae62381c5ec74ed9494f5320f0a6b4fc4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page