-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equation for Lux calculation does not reflect Library #7
Comments
What should be changed in the CircuitPython library? |
Yes, but I am not sure which equation is right given the following open issue: adafruit/Adafruit_TSL2591_Library#24 |
@caternuson Do you know what the correct equation is? |
@tannewt TLDR - no It looks like the disagreement between the libraries is a result of this commit: I am having trouble finding a definitive lux equation for the TSL2591. The datasheet for the TSL2591 does not have one: |
I'd be tempted to follow the AN since its linked. Maybe try it out and see? |
The datasheet table for ATIME Max Count in "Control Register (0x01)" and findings from issue #5 created. |
Thanks. Looks like the same info is contained in the summary table as well. For the TSL2591 there's this: Now for lux... Back to my question from above. I can't figure out where this came from: |
Well, they (TSL2561 vs. TSL2591) behave differently. So anecdotally, I think the TSL2591 is different. I sent a request to AMS (they bought TAOS) to ask them for what they consider the proper lux equation for the TSL2591. This was via a web form accessed from here: |
Has anyone taken an actual Lux meter and compared the values? I've been reading a little bit on these formulas and haven't seen anyone mention it. |
We've done a little with a lux meter and scale based on the difference of the reading. Also, clipping to 0 if the lux value is negative. |
There is unfortunately a bit of complexity in deriving lux in the case of the TSL2591, partly because the required information isn't terribly clear in the datasheet. Trying to do some reading on this (not being an expert in the domain myself!), there are some important points to consider talking about lux:
The goal then, to derive lux, is to convert from irradiance (a radiometric measurement) to illuminance (a photometric value based on an estimation of human vision), which is done using the CIE 1931 photopic curve.
You can see the CIE 1931 photopic curve here, image taken from the wikipedia page for Luminous Function: Normal human vision can detect wavelengths from 380-780nm, but our sense of 'brightness' is very heavily concentrated in the green to yellow range in the middle. It comes down to the design our our eyes which are made of of codes and rods. Our eyes have three 'cones' that roughly are sensitive to red, green and blue wavelengths. The red cones (higher nm values) are most sensitive to light and are more abundant (64% red cones, 32% green cones and only 2% blue cones), but 'brightness' is more associated with the green cones than red and blue. (Bonus fact: Now you know why there are two green photodiodes to every 1 red and blue in bayer pattern sensors. 🙂). This is why the photopic luminous curve that forms the basis of lux (the black curve above) is heavily biased by the green to yellow wavelengths (the peak in the middle). Anyway ... enough botched anatomy I'm surely mischaracterizing. :P The problem is taking radiometric values that we can accurately measure and converting them to the equivalent photometric units based on this estimation of human vision. The TSL2591 datasheet lists irradiance, the radiometric response, at two wavelengths: At 4000K (what they are calling White light, though the idea of 'White' light is highly complex and a colorimetry tutorial in itself), with ATIME=100ms and GAIN=MAX (~9876x):
At 850nm, which is OUTSIDE HUMAN VISION and in the non-visible infrared range, we would get:
This makes sense since CH1 is more concentrated towards the IR range, as shown below: In order to calculate lux, you will need to find a way to map the spectral responsivity of the sensor's photodiode(s) to the photopic curve mentioned earlier.
While accurate 'lux' values don't 'really' exist since it's a somewhat arbitrary 'estimation' to begin with, to get the closest match we can to the photopic curve, it helps to know the spectral density of your light source. As the two datasheet values show, infrared heavy light will give different output than light more concentrated in the visual range, but both may have a very strong radiometric response. Converting Radiance (Radiometric) to Irradiance (Photometric)To try to make something useful out of this giant response, we can take the 4000K white LED light as a starting point, and calculate counts per uW/cm^2 based on the following values:
It seems to me the best we can do to convert this to an equivalent photometric unit (lux) is to correlate the peak responsivity of the sensor, which looks to be ~650nm in the normalised spectral responsivity in the DS with the same position on the photopic curve. Here is an overlay of the two curves: I don't have an instant answer on the coefficients to map these two values, and it depends largely on the spectral composition of the light source you are measuring, but I think this at least explains all the science behind lux and how to calculate it since AMS apparently doesn't want to make life easy for us. :P I'll have to think about this some more and follow up, but hopefully this gets the ball rolling towards better lux values, and establishes a solid 'scientific' bases for future calculations. to be continued ... PS: I'm not an expert in this domain, so please feel free to correct me on any mischaracterisations above if you're more knowledgable on the subject matter! |
Awesome info dump. Thanks. Just to update on the approach I was taking - AMS never got back to me on my request for their lux equation. :( |
It sounds like these sensors were never intended to accurately measure light in the first place. Maybe more effort should go into configuring the interrupt registers on the device. My TSL2591 works great as a light intensity switch when configured properly. |
I wouldn't go that far. These sensors have a fairly typical response curve, and with a combination of finding the right coefficient to match the photopic luminosity function, and probably a second 'device factor' coefficient that takes into account the physical characteristics of the sensor and enclosure you should be able to get 'reasonable' values. It just takes a fair amount of reading and some digging into the theory, but I think 90% of it is covered above. That said ... RGB sensors are actually better suited to LUX conversions since you have a finer degree of control when 'selecting' values that fall within the photopic luminosity function. |
AMS is kind of awful for support through public channels. Every time I've sent them a Q, however precise, I get an email to say that it was forwarded ... and then it falls into a black hole. Even when I send a second followup ping. :P But that's kind of par for the course, sadly. The only company with really good support (that I've worked with) is Nordiic, who set the bar extremely high. I think the approach documented here is the right one, I just need some more time to work through it to find a good pair of coefficients, though there is also an element of the light source and the IR component. LED lights, for example, have almost no IR component, but natural sunlight has a huge component, which will change the weight of the output values. Just one more reason that a straight-forward 'accurate' lux conversion is anything but 'straight-forward' or 'accurate' when you dig into the theory and physics behind it. :) |
Just in case anyone fancies having a go at mapping photopic luminosity function to the TSL2591 spectral response curves, I decided to extract the CH0 and CH1 XY curve points here. It makes a nice plot in Excel and I found a cool tool (see readme.md) into the bargain! |
@SimonMerrett Nice find on the tool! I was going to write one myself, glad I won't have to. And thanks for sharing the data. I have my hands full with some new HW at the moment, but have saved a copy of this. |
I was so excited I nearly submitted to the Hackaday tips line. Then I stopped and checked, and of course, Jenny List told us this tool existed nearly three years ago! |
@microbuilder go and save the new .csv I committed, which contains both the CH0, CH1 and the photopic 1931/2005 and scoptopic xy values. Then get it into Excel or HeuristicLab's symbolic regression tool, depending on how hard you think the problem is! |
No need to reinvent the wheel; AMS provides datasheets on how to improve the accuracy of the sensor, even providing calibration software to calculate the coefficients: https://ams.com/tsl25911#tab/documents Specifically, this is a good place to start: https://ams.com/documents/20143/36005/AmbientLightSensors_AN000173_2-00.pdf/ce3360f8-fb85-bc22-0bad-b60d3b31efc8 Note that there is no one size fits all equation, as it is dependent on the type of light you expect to encounter. |
@caternuson Is this working looking into again? |
@kattni I think to really resolve this for the TSL2591 we would need calibration hardware. One solution may be to get rid of the |
@caternuson After looking into it, we'll keep |
I've just done a bunch of work on getting this library to work in my application, and, although I am not an expert in light, I did figure out what seems to problematic. The issue is that in low light at LOW gain, The trick to getting it to work in low light is to start at I've attached a sketch (renamed as Anyway, feel free to close this issue again. But I just thought i would get my observation on the record for the next person coming along. ` [g=gain, l=luminosity, i=IR, f=full spectrum] |
The calculations in this project (CircuitPython) reference the AdatFruit_TSL2591_Library, but the equations do not match.
https://github.com/adafruit/Adafruit_TSL2591_Library/blob/master/Adafruit_TSL2591.cpp#L220
This project does take into account the max_count for saturation and sensor overflow, but the source project does not.
The text was updated successfully, but these errors were encountered: