TSL-2591 lux calculation

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Matadormac
 
Posts: 33
Joined: Tue Aug 05, 2014 8:51 am

Re: TSL-2591 lux calculation

Post by Matadormac »

swdick wrote:Hi all,
I'm implementing a 2591 in my enlarger. The idea is to obtain the lightlevels of the darkest and lightest parts of the negative in order to calculate the exposure time and filter to get a well exposed print.
The problem I have seems related to the discussion in this thread.
I use the advancedRead function as posted by vega_rm, slightly modified so that I can use the value of Visible in my Measure function.
I get values that seem OK but once in a while there is an unexplainable overflow in Visible or a negative value of some other variable (Num, Lux1).
Hello. I am a photographer too. Are you using the most current Adafruit TSL2591 libraries? Townsend did significant upgrades about two months ago. One of them was to implement two calls for a light reading so that the first one which is usually false is ignored. Also, there was an issue with changing gain settings resulting in a wild first reading after. I believe the two calls for a light reading with discarding the first one took care of those false readings.

I also have used Vega's coding..

If you are working with normal photographic papers there will be little effect of the IR part of any light of course. Most effect is in bluer ends of the spectrum. Chromagenic materials will differ I believe but that is something I am not knowledgeable about.

Good luck.

User avatar
swdick
 
Posts: 7
Joined: Tue Mar 08, 2016 9:46 am

Re: TSL-2591 lux calculation

Post by swdick »

Thanks, Yes, I think I'm using the latest version. Downloaded only 10 days ago.
The library files don't show the version though.
I skip any value that is not in the range 0 - 65000. Seems to work.

It would be nice though to have an autogain function in the library.
I guess I'll have to build one in my sketch.

User avatar
swdick
 
Posts: 7
Joined: Tue Mar 08, 2016 9:46 am

Re: TSL-2591 lux calculation

Post by swdick »

I've been playing with the 2591 a lot and tried all sorts of screenings to get reliable results.
The lux values are too often way out and useless, e.g. negative, or of an exteme high value.
The values of lum, ir, visible and full are often out of range without cause.
First values are often wrong as also stated somewhere in this thread.
Changes of light intensity alsolead to wrong values.
For my purposes this renders the thing completely useless.

What can be the problem? Or does the thing not what it promisses?

User avatar
vega_rm
 
Posts: 7
Joined: Mon Dec 07, 2015 2:02 pm

Re: TSL-2591 lux calculation

Post by vega_rm »

Apologies, last year was really swamped. First i must say that i have finished (at least for now) my exposure meter,
found several issues along the way and to give some info back this is what i found and how i solved with my TSL2591.

I was overrunning my device and gave an error (do not remember exactly the message) because i tried to get the sample
before it was ready ( i use 100 ms sample rate), ended up increasing it to 105 ms and measures were consistent and stable.
Used library (1.0.2 at the time) wait for 120 ms between samples, but i because in one mode i measure the light from a
off camera flash, i had to continuously measure ambient light to catch the event. There is no link from flash to meter.

I had a factor of about four difference from library lux equation to calculated lux from my camera settings. reflected
from an 18% gray card which resulted in overexposed photograph. I still do not understand the logic behind a dual equation
used in lux calculation and then selecting the maximum value of them, I am simply using one similar to one of the library,
but different value for TSL2591_LUX_DF, in library it has a value of 408.0, I don't know how it was calculated, but using data
from most recent datasheet i found, found it to be 1032.9, about 2.5 times larger.

Here is how i reached that value, from datasheet sensitivity is 264.1 counts/uW/cm2, at Med gain (400) and 100 ms.
This value must be scaled to actual conditions, that is multiply by actual gain and actual integration time, then divide
by 40,000 (400 times 100) and apply value to visible light count, that is counter0 - 1.67 * counter1. Factor 1.67 is due
to different sensitivities (may be the IR filter) on each channel.

There is one missing factor in the equation above, to convert from uW/cm2, to lux multiply result by 6.82:
400 * 100 * 6.82 / 264.1 = 1032.9

Let me know if any question comes up, hopefully will answer before end of this year :-)

User avatar
emilino
 
Posts: 2
Joined: Mon Mar 07, 2016 4:25 pm

Re: TSL-2591 lux calculation

Post by emilino »

Hi vega_rm, your 6.82 factor works well for me. I diffused my TSL2591 sensor with half a ping pong ball, with your 6.82 factored in, I got almost exactly EV 15 under a sunny day.

Mind to share how you come up with this magic factor?

User avatar
emilino
 
Posts: 2
Joined: Mon Mar 07, 2016 4:25 pm

Re: TSL-2591 lux calculation

Post by emilino »

vega_rm wrote: I still do not understand the logic behind a dual equation used in lux calculation and then selecting the maximum value of them...
I understand it now. The dual-diode design of these TAOS sensors allow them to measure the ratio of IR over full spectrum (CH1/CH0), and this ratio is very useful as it allows the estimation of the type of light source present. See the figure below:
LightSourceVsRatio.jpg
LightSourceVsRatio.jpg (82.27 KiB) Viewed 1848 times
So once we know what kind of light source we are dealing with, we can have a different empirical lux equation for every different light source. For example the TSL2561 sensor has 7 lux equations defined according to the CH1/CH0 ratio, but somehow these 7 linear equations can also be simplified into just two segments. For example, take a look at the two-segment lux equation of TSL2771 (I don't have the diagram for TSL2561 or 2591):
TwoLuxZones.jpg
TwoLuxZones.jpg (70.19 KiB) Viewed 1848 times
Two linear lines seem good enough to approximate the sensor. And notice that for the two segments, CH1/CH0 from 0.0 to roughly 0.4, and roughly 0.4 or beyond, it is the higher values of these two lines that we need. Hence the library function calculates lux values from both linear lines regardless, and simply take the max. You can also calculate the CHI/CH0 ratio first, and know exactly which equation out of the two to use for lux calculation. Same thing.

User avatar
swdick
 
Posts: 7
Joined: Tue Mar 08, 2016 9:46 am

Re: TSL-2591 lux calculation

Post by swdick »

A related question: I have restarted my project with the TLS2591. What I'm wondering now how I get sub 1 lux values. The functions SimpleRead and AdvancedRead, etc. use uint16_t for the Lux values. That would give integers as a result. ???

User avatar
adafruit_support_bill
 
Posts: 88442
Joined: Sat Feb 07, 2009 10:11 am

Re: TSL-2591 lux calculation

Post by adafruit_support_bill »

@swdick - Which library are you using? calculateLux() in the Adafruit library returns a float value. It looks like the library has been updated recently with improvements to the lux conversion calculations.

https://github.com/adafruit/Adafruit_TSL2591_Library

User avatar
swdick
 
Posts: 7
Joined: Tue Mar 08, 2016 9:46 am

Re: TSL-2591 lux calculation

Post by swdick »

OK, thanks seems to work. I call this now in advanced read. Can I also call it in SimpleRead or anywhere?

User avatar
adafruit_support_bill
 
Posts: 88442
Joined: Sat Feb 07, 2009 10:11 am

Re: TSL-2591 lux calculation

Post by adafruit_support_bill »

CalculateLux() requires both the full and IR readings. The SimpleRead() function only looks at the visible light reading.

User avatar
tciii
 
Posts: 21
Joined: Mon Apr 08, 2013 1:23 pm

Re: TSL-2591 lux calculation

Post by tciii »

I recently purchased two of the Adafruit tsl2591 modules to be able to determine sunlight lux levels for a two axes solar tracker. Since the tsl2591 will saturate beyond 88,000 lux and direct, bright sunlight can reach lux levels well beyond 132,000 lux, I determined that a 1/32 thick piece of Teflon would provide sufficient attenuation so that the tsl2591 would not go into saturation.
Using my attenuator and a wide range light meter calibrated to a secondary source traceable to NIST, I determined that I needed a multiplication factor of ~4 when using the attenuator. However as was documented above, I would get an occasional negative lux reading and the sensor would output readings over 200,000 lux during sun to cloud to sun transitions when using the "advancedRead subroutine to read the lux level from the sensor.
Finally I decided to try the "unifiedSensorAPIRead" subroutine to read the lux level from the sensor. During the first sensor lux level reading in bright sunlight, the sensor lux level reading was within 1,000 lux of my calibrated light meter and in cloudy/diffuse sunlight, the reading was within 500 lux of the calibrated light meter. On a fully sunny day with no clouds, I plan to plot sensor/light meter data points every hour from sunrise to near sunset and perform a retrogression calculation to determine a best fit curve for the tsl2591 sensor and make any necessary adjustments to my attenuator multiplication factor.
Bottom line here is that the "Unified Sensor API" routine should be looked at so as to determine why its accuracy and consistency seems to be much better than the "Advanced Read" routine.
Update: After reviewing the "unifiedSensorAPIRead" it appears that the luminosity is read twice in sequence before the lux calculations are completed which appears to negate a negative or ridiculously large lux reading.

User avatar
AdamSheni
 
Posts: 2
Joined: Thu May 02, 2019 11:18 pm

Re: TSL-2591 lux calculation

Post by AdamSheni »

Is there a way to get under 1 lux resolution?

tried the provided code:

void advancedRead(void)
{
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
tcaselect(0);

uint32_t lum = tsl1.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;

Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
Serial.print("IR: "); Serial.print(ir); Serial.print(" ");
Serial.print("Full: "); Serial.print(full); Serial.print(" ");
Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" ");
Serial.print("Lux: "); Serial.println(tsl1.calculateLux(full, ir));
//*****

but cannot seem to change the int to float without an error...

any suggestions?

Thanks

User avatar
tciii
 
Posts: 21
Joined: Mon Apr 08, 2013 1:23 pm

Re: TSL-2591 lux calculation

Post by tciii »

@Adam,

Have you tried using the "unifiedSensorAPIRead" routine?

Regards,
TCIII

User avatar
AdamSheni
 
Posts: 2
Joined: Thu May 02, 2019 11:18 pm

Re: TSL-2591 lux calculation

Post by AdamSheni »

tciii wrote:@Adam,

Have you tried using the "unifiedSensorAPIRead" routine?

Regards,
TCIII

Hi Yes, tried all lux reading methods they have in the file and all return a 1 lux resolution value. it says that also in the header

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”