-
Notifications
You must be signed in to change notification settings - Fork 50
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
Suggested lux calculation improvement #14
Comments
Fixed with 2b3b098 ... thanks for taking the time to suggest an improvement here! |
I am unsure if this actually fixes it, as I'm using the current calculation and still get the 65535 (negative number in an unsigned int). However, I am unsure if this can be related to another error (where it jumps from 0 to 65535) and the sensor has to be sampled more than 2 times. |
Also still having negative lux results in low light environments with |
At MID and LOW gain, and matching integration times, briefly shadowing the sensor still returns negative numbers. A slow EMA filter will often prevent this from happening, but when one changes gain/integration time on the fly with a button, the sensor restarts often with large negative values returned. Ironically, the old TSL2561 fares better here. |
Please see my somewhat gigantic response to the lux issue here: adafruit/Adafruit_CircuitPython_TSL2591#7 (comment) I've tried to dig into this, and put some theory down and separate photometric units (illuminance measure in lux, based an an estimation of human vision) from radiometric units (irradiance), and show how the two are mapped based on the CIE 1931 luminous functions, but the final conversion coefficients are still a WIP. :( If possible, maybe the conversation should be continued there just to have everything in one place? |
Reopening this issue until the related issue is also resolved since this is still an open question. |
Not sure on the attitude to cross-posting here but this may help someone. adafruit/Adafruit_CircuitPython_TSL2591#7 (comment) |
@SimonMerrett All good, and you're right to cross post here, thanks again. |
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. |
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. |
@Llamero is right, there is no common solution. The TSL2591 needs to be calibrated for specific light sources. Somebody with a Lux-meter should do this. The @iquizzle approach, that is currently implemented in the library cannot be right. If you take this equation lux = ( ch0 - ch1) * (1 - ch1/ch0 ) / cpl and multiply it out you get lux =( ch0 - 2 * ch1 - ch1*ch1/ch0 ) / cpl There are two problems with this:
|
The current algorithms produce a negative lux under certain conditions (especially low light).
Current:
lux1 = ( (float)ch0 - (TSL2591_LUX_COEFB * (float)ch1) ) / cpl;
The fixed value of TSL2591_LUX_COEFB can cause negative values when IR intensity is high. This should be replaced by a dynamically scaling coefficient. A better implementation would be this:
Improved:
lux = ( ((float)ch0 - (float)ch1 )) * (1.0F - ((float)ch1/(float)ch0) ) / cpl;
The raw difference is taken initially and a correction factor of 1-ch1/ch0 is applied to scale down the lux with increasing IR intensity. This ratio represents the amount of IR present within the full spectrum. This should give a better approximation to lux given the 2-channel constraint of the sensor.
The text was updated successfully, but these errors were encountered: