0

TSL2591 increasing gain reduces the result of the light read
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

TSL2591 increasing gain reduces the result of the light read

by mglowinski on Mon Feb 22, 2021 2:12 pm

Hi,
recently I've started using TSL2591 with Python (library https://github.com/adafruit/Adafruit_Ci ... on_TSL2591)

My sensor:
TSL2561.jpg
TSL2561.jpg (409.67 KiB) Viewed 83 times


Here is code, which i did for a test:
Code: Select all | TOGGLE FULL SIZE
import board
import busio
import adafruit_tsl2591
from adafruit_tsl2591 import GAIN_HIGH, GAIN_MED, INTEGRATIONTIME_100MS, GAIN_MAX, \
    INTEGRATIONTIME_600MS, INTEGRATIONTIME_300MS

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_tsl2591.TSL2591(i2c)

print("Gain: 0x10, integration_time: 100ms")
sensor.gain = GAIN_MED
sensor.integration_time = INTEGRATIONTIME_100MS
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))
print("---------------------------------------")

print("Gain: 0x10, integration_time: 600ms")
sensor.gain = GAIN_MED
sensor.integration_time = INTEGRATIONTIME_300MS
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))

print("---------------------------------------")
print("Gain: 0x30, integration_time: 100ms")
sensor.gain = GAIN_MAX
sensor.integration_time = INTEGRATIONTIME_100MS
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))

print("---------------------------------------")
print("Gain: 0x30, integration_time: 600ms")
sensor.gain = GAIN_MAX
sensor.integration_time = INTEGRATIONTIME_600MS
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))


In general it worked, but results which i got are different then described here: https://learn.adafruit.com/adafruit-tsl ... cuitpython .

My results
At dark place:
Code: Select all | TOGGLE FULL SIZE
Gain: 0x10, integration_time: 100ms
Light: 10.405632 lux
Visible: 1048650
Infrared: 16
---------------------------------------
Gain: 0x10, integration_time: 600ms
Light: 0.004390117456460106 lux
Visible: 1048650
Infrared: 16
---------------------------------------
Gain: 0x30, integration_time: 100ms
Light: 0.026340704738760636 lux
Visible: 1048650
Infrared: 16
---------------------------------------
Gain: 0x30, integration_time: 600ms
Light: 0.004390117456460106 lux
Visible: 1048650
Infrared: 16


During day with bulb on:
Code: Select all | TOGGLE FULL SIZE
Gain: 0x10, integration_time: 100ms
Light: 1689.361536 lux
Visible: 166670027
Infrared: 2543
---------------------------------------
Gain: 0x10, integration_time: 600ms
Light: 0.7127385986229242 lux
Visible: 166670027
Infrared: 2543
---------------------------------------
Gain: 0x30, integration_time: 100ms
Light: 4.276431591737546 lux
Visible: 166670027
Infrared: 2543
---------------------------------------
Gain: 0x30, integration_time: 600ms
Light: 0.7127385986229242 lux
Visible: 166670027
Infrared: 254


Moreover while I put switched on bulb really close to sensor, I got Python Exception:
Code: Select all | TOGGLE FULL SIZE
Gain: 0x10, integration_time: 100ms
Traceback (most recent call last):
  File "main.py", line 13, in <module>
    print('Light: {0} lux'.format(sensor.lux))
  File "/home/pi/Documents/tsl2591/project-name/.env/lib/python3.7/site-packages/adafruit_tsl2591.py", line 247, in lux
    raise RuntimeError("Overflow reading light channels!")
RuntimeError: Overflow reading light channels!



I would expect that increasing GAIN would increase sensitivities of a sensor, the same with integration time.
Do you have any tip why I got results like that?

Moreover, why I'm getting RuntimeError exception? I'm getting this exception everytime, when I put a strong light on the sensor.

mglowinski
 
Posts: 3
Joined: Mon Feb 22, 2021 11:18 am

Re: TSL2591 increasing gain reduces the result of the light

by adafruit_support_carter on Mon Feb 22, 2021 7:51 pm

The overflow is expected behavior. That happens when you saturate the sensor.

For the other behavior, try adding some delay between the gain/integration time settings and when making the readings. Here's an example. Also added a printout of the raw ADC values which all the other values are computed from.
Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
import adafruit_tsl2591
from adafruit_tsl2591 import GAIN_HIGH, GAIN_MED, INTEGRATIONTIME_100MS, GAIN_MAX, \
INTEGRATIONTIME_600MS, INTEGRATIONTIME_300MS

READING_DELAY = 1

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_tsl2591.TSL2591(i2c)

print("Gain: 0x10, integration_time: 100ms")
sensor.gain = GAIN_MED
sensor.integration_time = INTEGRATIONTIME_100MS
time.sleep(READING_DELAY)
print('RAW: ', sensor.raw_luminosity)
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))
print("---------------------------------------")

print("Gain: 0x10, integration_time: 600ms")
sensor.gain = GAIN_MED
sensor.integration_time = INTEGRATIONTIME_300MS
time.sleep(READING_DELAY)
print('RAW: ', sensor.raw_luminosity)
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))
print("---------------------------------------")
print("Gain: 0x30, integration_time: 100ms")
sensor.gain = GAIN_MAX
sensor.integration_time = INTEGRATIONTIME_100MS
time.sleep(READING_DELAY)
print('RAW: ', sensor.raw_luminosity)
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))
print("---------------------------------------")
print("Gain: 0x30, integration_time: 600ms")
sensor.gain = GAIN_MAX
sensor.integration_time = INTEGRATIONTIME_600MS
time.sleep(READING_DELAY)
print('RAW: ', sensor.raw_luminosity)
print('Light: {0} lux'.format(sensor.lux))
print('Visible: {0}'.format(sensor.visible))
print('Infrared: {0}'.format(sensor.infrared))

adafruit_support_carter
 
Posts: 18729
Joined: Tue Nov 29, 2016 2:45 pm

Re: TSL2591 increasing gain reduces the result of the light

by mglowinski on Tue Feb 23, 2021 3:39 am

Thank you @adafruit_support_carter for quick response!

Now results are like bellow:
Code: Select all | TOGGLE FULL SIZE
Gain: 0x10, integration_time: 100ms
RAW:  (479, 136)
Light: 41.772672 lux
Visible: 8913239
Infrared: 136
---------------------------------------
Gain: 0x10, integration_time: 600ms
RAW:  (2802, 797)
Light: 40.661824 lux
Visible: 52234197
Infrared: 797
---------------------------------------
Gain: 0x20, integration_time: 100ms
RAW:  (8199, 2291)
Light: 42.342011214953274 lux
Visible: 150148884
Infrared: 2291
---------------------------------------
Gain: 0x20, integration_time: 600ms
RAW:  (48052, 13431)
Light: 41.34838504672897 lux
Visible: 880248637
Infrared: 13431


So changing GAIN from 0x10 to 0x20 almost did not have any impact on measurements, while according to https://learn.adafruit.com/adafruit-tsl ... cuitpython i should expect a few times overstated measurement. Also it is not clear why extending integration time, decreased read values.

About overflow, what is the limit of luxes? According to https://learn.adafruit.com/adafruit-tsl2591 I should be able to read up to 88,000 Lux, while it is getting saturated on about 8,000 Lux.

mglowinski
 
Posts: 3
Joined: Mon Feb 22, 2021 11:18 am

Re: TSL2591 increasing gain reduces the result of the light

by adafruit_support_carter on Tue Feb 23, 2021 11:18 am

The value for lux is taking in to account the gain and integration times. That is - it's reporting actual lux, which is independent of gain / integration time. The other values are more like "raw" values. Note how they are changing. For example:

6x change in integration time:
(479, 136) @ 100ms -> (2802, 797) @ 600ms

2802 / 479 = 5.85
797 / 136 = 5.86

So both are increasing about the 6x expected.

adafruit_support_carter
 
Posts: 18729
Joined: Tue Nov 29, 2016 2:45 pm

Re: TSL2591 increasing gain reduces the result of the light

by mglowinski on Wed Feb 24, 2021 3:48 am

Oh, i got it now!
Thx for explanation:)

mglowinski
 
Posts: 3
Joined: Mon Feb 22, 2021 11:18 am

Please be positive and constructive with your questions and comments.