I just bought this sensor, https://www.adafruit.com/product/5591 and was running the sample code named ltr329_simpletest.ino. It compiles and loads ok but in the serial monitor window it gives a reading of 65527 and moving my hand over the sensor the last 3 digits change but it is always 65000 something. Seems wrong to me ?
thanks
Adafruit LTR-329 Light Sensor odd readings
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- sj_remington
- Posts: 997
- Joined: Mon Jul 27, 2020 4:51 pm
Re: Adafruit LTR-329 Light Sensor odd readings
That behavior suggests that the gain is too high or integration time is too long, although the code attempts to set them to reasonable values for high illumination environments (1X and 50 ms). Try reading out the settings, changing them to other values, etc. See the advanced test example.
If you continue to get unexpected results, the sensor may be defective.
If you continue to get unexpected results, the sensor may be defective.
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit LTR-329 Light Sensor odd readings
thanks for the reply. I did try their other example today, ltr329_advanced_test.ino, which works so I think the sensor is ok. Looking at the code they use a different function call, maybe this is a software bug in their ltr329_simpletest.ino code ?
Hopefully an adafruit tech will see this and confirm/comment.
thanks
Hopefully an adafruit tech will see this and confirm/comment.
thanks
- sj_remington
- Posts: 997
- Joined: Mon Jul 27, 2020 4:51 pm
Re: Adafruit LTR-329 Light Sensor odd readings
Does look like bug in the library.
This
should be something like:
This
Code: Select all
uint16_t Adafruit_LTR329::readVisible(void) {
uint16_t visible_plus_ir, infrared;
if (!readBothChannels(visible_plus_ir, infrared)) {
return 0xFFFF;
}
return visible_plus_ir - infrared;
}
Code: Select all
uint16_t Adafruit_LTR329::readVisible(void) {
uint16_t visible_plus_ir, infrared;
if (!readBothChannels(&visible_plus_ir, &infrared)) { //note the '&'
return 0xFFFF;
}
return visible_plus_ir - infrared;
}
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit LTR-329 Light Sensor odd readings
Nice ! Thank you
Hopefully Adafruit will see this and post a fix to the library, thanks again
Hopefully Adafruit will see this and post a fix to the library, thanks again
- sj_remington
- Posts: 997
- Joined: Mon Jul 27, 2020 4:51 pm
Re: Adafruit LTR-329 Light Sensor odd readings
If you want to get the library maintainer's attention, post an issue on the Github repository page.
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit LTR-329 Light Sensor odd readings
good to know, thanks !
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit LTR-329 Light Sensor odd readings
sj_remington - fyi changing the library to include the & resulted in a compiler error. I did post it on github after creating an account there and someone replied:
The library function being called is passing by reference:
https://github.com/adafruit/Adafruit_LT ... 3.cpp#L231
so the library code syntax is OK - it's not missing &s.
It's more likely the determination of visible requires more logic than the simple math being done:
https://github.com/adafruit/Adafruit_LT ... 3.cpp#L252
This same behavior can be seen with the ltr329_advanced_test example. That example does not output visible, just the two main channel readings. Running that example with a finger over the sensor produces values like this:
Visible + IR: 20 Infrared: 35
Visible + IR: 20 Infrared: 35
Visible + IR: 20 Infrared: 35
Visible + IR: 21 Infrared: 35
Visible + IR: 22 Infrared: 37
Note the infrared value is higher than the visible+infrared value. So the math for visible will result in a negative number. You're seeing the values in the 65000 range since the return value is unsigned (uint16_t)
not what I expected from a 'simple' visible light sensor program to get a negative reading.
thanks
The library function being called is passing by reference:
https://github.com/adafruit/Adafruit_LT ... 3.cpp#L231
so the library code syntax is OK - it's not missing &s.
It's more likely the determination of visible requires more logic than the simple math being done:
https://github.com/adafruit/Adafruit_LT ... 3.cpp#L252
This same behavior can be seen with the ltr329_advanced_test example. That example does not output visible, just the two main channel readings. Running that example with a finger over the sensor produces values like this:
Visible + IR: 20 Infrared: 35
Visible + IR: 20 Infrared: 35
Visible + IR: 20 Infrared: 35
Visible + IR: 21 Infrared: 35
Visible + IR: 22 Infrared: 37
Note the infrared value is higher than the visible+infrared value. So the math for visible will result in a negative number. You're seeing the values in the 65000 range since the return value is unsigned (uint16_t)
not what I expected from a 'simple' visible light sensor program to get a negative reading.
thanks
- adafruit_support_carter
- Posts: 29150
- Joined: Tue Nov 29, 2016 2:45 pm
- sj_remington
- Posts: 997
- Joined: Mon Jul 27, 2020 4:51 pm
Re: Adafruit LTR-329 Light Sensor odd readings
My mistake, for some reason I was thinking that pointers were required.
If you look at the visible and IR photodiode response curves in the data sheet, it is not really clear what you are calculating when you take the simple difference of the two measurements. CH1 (IR) response extends well into the yellow-green (500 nm), and CH0 (visible + IR) response extends well into the NIR at 900 nm.
Given the actual data posted above, it clearly makes no sense to subtract 35 from 20 to get the "visible" contribution. Indeed, for incoming light with wavelength > 600 nm, the result of the subtraction will always be negative.
If you look at the visible and IR photodiode response curves in the data sheet, it is not really clear what you are calculating when you take the simple difference of the two measurements. CH1 (IR) response extends well into the yellow-green (500 nm), and CH0 (visible + IR) response extends well into the NIR at 900 nm.
Given the actual data posted above, it clearly makes no sense to subtract 35 from 20 to get the "visible" contribution. Indeed, for incoming light with wavelength > 600 nm, the result of the subtraction will always be negative.
Please be positive and constructive with your questions and comments.