-
Notifications
You must be signed in to change notification settings - Fork 8
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
All pulled data is zero #2
Comments
@nemirog1 Any luck on making this sketch work? |
Yes! The sketch is not written very well, and as a result, not only does the LTR-303 not work, but the sketch spits out inaccurate lux numbers (actually, just zeroes). I received all of the data sheets, and made some adjustments. I built this to operate around a Teensy 3.6, but it should be pretty straightforward to modify for any other Arduino based setup. Attached is a zip file that includes my updated version of the driver, a sketch that should work to show how the sensor is supposed to work, the original datasheet, and the rare (for whatever reason) Appendix A for the sensor. |
Many thanks. Looking into that right away |
For anyone trying this code, required changes are (thanks to @nemirog1 )
} |
Thanks for all the anseres, this helped me to get mine going. However it only works if this part is unchanged: (For the easiest way to get this going "out-of-the-box".
not
in the LTR303.cpp. It would be highly appreaciated if the lib gets fixed. |
The example also didn't work. Calling "setPowerUp()" sets it to standby mode. I had to comment this line, and then use "setControl(gain, false, true)". Looks like the library is abandoned. Anyone who wants to fork it and integrate all the fixes in this issue? The library should also save the values of gain and integration time as member variables of the class, and then "getLux" can use this, doesn't make sense to pass it as parameters. The same parameters could be used for setPowerUp. Or just remove setPowerUp, it is kind of redundant because setControl sets already all bits in the control register. And while we are at it: passing CH0 and CH1 doesn't make sense either in getLux. The function should read the sensor. I don't care about the low-level details as a user of the library, I just want the Lux value. If I care, I can use the low-level getData function. |
This is not right, because it will do an integer division, so ratio is often 0. One solution would be this:
This is wrong. The right formula is this for the range from 0.64 to 0.85:
You probably never noticed it, because your ratio was always wrong as well. Also note that you don't need as many parentheses as you used.
I would probably write it without else, because it is the only remaining case. But might be good to test it anyway, in case there was a division by zero error for the ratio, but which should be tested anyway earlier. |
I've rolled out my own version of the function for a while now and dealt with the ratio not being a double but the one thing that I completely missed was that minus (-) in the formula. Thanks to your eagle eye, I'll fix that! As for the parenthesis, you're also right. You can reduce. It's an old habit that I have to make sure I don't rely on someone's else understanding of operator priority when they read or refactor the code especially when mixing operators. |
First, thank you for putting the effort into this library! Have an issue where I can see the Part ID, Manufacturer ID, and it seems to set the configuration commands. After that, all data pulled is set to zero. I tried modifying the code to directly see the results of errors, but it is always zero. If you use the Arduino example, you get something like:
10:20:43.950 -> LTR303-ALS example sketch
10:20:43.950 -> Got Sensor Part ID: 0XA0
10:20:43.950 -> Got Sensor Manufacturer ID: 0X5
10:20:43.950 -> data0: 0
10:20:43.950 -> data1: 0
10:20:43.950 -> lux: 0.00
10:20:43.950 -> (good)
So it seems that it thinks the I2C communications are good, but all the data is zero. I thought I might have a bad device, so I tried on a separate sensor and Arduino, same results. I saw that someone else was posting up with this issue on various forums. Do you have any ideas on what to check?
The text was updated successfully, but these errors were encountered: