API Reference
adafruit_tsl2591
CircuitPython module for the TSL2591 precision light sensor. See examples/simpletest.py for a demo of the usage.
Author(s): Tony DiCola
Implementation Notes
Hardware:
Adafruit TSL2591 High Dynamic Range Digital Light Sensor (Product ID: 1980)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- adafruit_tsl2591.CLEAR_ALL_INTERRUPTS = 7
Clears ALS and no persist ALS interrupt
- adafruit_tsl2591.CLEAR_INTERRUPT = 6
Clears ALS interrupt
- adafruit_tsl2591.CLEAR_PERSIST_INTERRUPT = 10
Clears no persist ALS interrupt
- adafruit_tsl2591.ENABLE_AIEN = 16
ALS Interrupt Enable. When asserted permits ALS interrupts to be generated.
- adafruit_tsl2591.ENABLE_NPAIEN = 144
ALS and No Persist Interrupt Enable.
- adafruit_tsl2591.ENABLE_NPIEN = 128
No Persist Interrupt Enable. When asserted NP Threshold conditions will generate an interrupt.
- adafruit_tsl2591.GAIN_HIGH = 32
High gain (428x)
- adafruit_tsl2591.GAIN_LOW = 0
Low gain (1x)
- adafruit_tsl2591.GAIN_MAX = 48
Max gain (9876x)
- adafruit_tsl2591.GAIN_MED = 16
Medium gain (25x)
- adafruit_tsl2591.INTEGRATIONTIME_100MS = 0
100 millis
- adafruit_tsl2591.INTEGRATIONTIME_200MS = 1
200 millis
- adafruit_tsl2591.INTEGRATIONTIME_300MS = 2
300 millis
- adafruit_tsl2591.INTEGRATIONTIME_400MS = 3
400 millis
- adafruit_tsl2591.INTEGRATIONTIME_500MS = 4
500 millis
- adafruit_tsl2591.INTEGRATIONTIME_600MS = 5
600 millis
- class adafruit_tsl2591.TSL2591(i2c: I2C, address: int = 41)[source]
TSL2591 high precision light sensor.
- Parameters:
Quickstart: Importing and using the device
Here is an example of using the
TSL2591class. First you will need to import the libraries to use the sensorimport board import adafruit_tsl2591
Once this is done you can define your
board.I2Cobject and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_tsl2591.TSL2591(i2c)
Now you have access to the
lux,infraredvisibleandfull_spectrumattributeslux = sensor.lux infrared = sensor.infrared visible = sensor.visible full_spectrum = sensor.full_spectrum
- clear_interrupt(operation: int) None[source]
Send special function command to control interrupt bits in the status register (0x13). Can be a value of: -
CLEAR_INTERRUPT-CLEAR_ALL_INTERRUPTS-CLEAR_PERSIST_INTERRUPT
- disable_interrupt(interrupts: int) None[source]
Disables the requested interrupts. Can be a value of: -
ENABLE_NPIEN-ENABLE_AIEN-ENABLE_NPAIEN
- enable_interrupt(interrupts: int) None[source]
Enable interrupts on device. ENABLE_NPIEN will turn on No Persist interrupts, these bypass the persist filter and assert immediately when values are detected above the high threshold or below the low threshold. Similarly, ENABLE_AIEN will assert at the respective ALS thresholds, but only after the values persist longer than the persist filter cycle duration. The device powers on with thresholds at 0, meaning enabling interrupts may cause an immediate assertion. Can be a value of: -
ENABLE_NPIEN-ENABLE_AIEN-ENABLE_NPAIEN
- property full_spectrum: int
Read the full spectrum (IR + visible) light and return its value as a 16-bit unsigned number.
- property gain: int
Get and set the gain of the sensor. Can be a value of:
GAIN_LOW(1x)GAIN_MED(25x)GAIN_HIGH(428x)GAIN_MAX(9876x)
- property integration_time: int
Get and set the integration time of the sensor. Can be a value of:
INTEGRATIONTIME_100MS(100 millis)INTEGRATIONTIME_200MS(200 millis)INTEGRATIONTIME_300MS(300 millis)INTEGRATIONTIME_400MS(400 millis)INTEGRATIONTIME_500MS(500 millis)INTEGRATIONTIME_600MS(600 millis)
- property lux: float
Read the sensor and calculate a lux value from both its infrared and visible light channels.
Note
luxis not calibrated!
- property nopersist_threshold_high: int
Get and set the No Persist ALS high threshold bytes. An interrupt will be triggered immediately once the detected value is above the high threshold. Can be 16-bit value.
- property nopersist_threshold_low: int
Get and set the No Persist ALS low threshold bytes. An interrupt will be triggered immediately once the detected value is below the low threshold. Can be 16-bit value.
- property persist: int
Get and set the interrupt persist filter - the number of consecutive out-of-range ALS cycles necessary to generate an interrupt. Valid persist values are 0 - 15 (inclusive), corresponding to a preset number of cycles. Only the 4 lower bits will be used to write to the device. Can be a value of: -
0 (0000)- Every ALS cycle generates an interrupt. -1 (0001)- Any value outside of threshold range. -2 (0010)- 2 consecutive values out of range. -3 (0011)- 3 consecutive values out of range. -4 (0100)- 5 consecutive values out of range. -5 (0101)- 10 consecutive values out of range. -6 (0110)- 15 consecutive values out of range. -7 (0111)- 20 consecutive values out of range. -8 (1000)- 25 consecutive values out of range. -9 (1001)- 30 consecutive values out of range. -10 (1010)- 35 consecutive values out of range. -11 (1011)- 40 consecutive values out of range. -12 (1100)- 45 consecutive values out of range. -13 (1101)- 50 consecutive values out of range. -14 (1110)- 55 consecutive values out of range. -15 (1111)- 60 consecutive values out of range.
- property raw_luminosity: Tuple[int, int]
Read the raw luminosity from the sensor (both IR + visible and IR only channels) and return a 2-tuple of those values. The first value is IR + visible luminosity (channel 0) and the second is the IR only (channel 1). Both values are 16-bit unsigned numbers (0-65535).
- property threshold_high: int
Get and set the ALS interrupt high threshold bytes. If the detected value is above the high threshold for the number of persist filter cycles an interrupt will be triggered. Can be 16-bit value.