Adafruit LTR-329 Light Sensor odd readings

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Adafruit LTR-329 Light Sensor odd readings

Post by jimk123 »

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

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by sj_remington »

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.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by jimk123 »

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

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by sj_remington »

Does look like bug in the library.

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;
}
should be something like:

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;
}

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by jimk123 »

Nice ! Thank you
Hopefully Adafruit will see this and post a fix to the library, thanks again

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by sj_remington »

If you want to get the library maintainer's attention, post an issue on the Github repository page.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by jimk123 »

good to know, thanks !

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by jimk123 »

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

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by adafruit_support_carter »


User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: Adafruit LTR-329 Light Sensor odd readings

Post by sj_remington »

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.
Capture.PNG
Capture.PNG (22.04 KiB) Viewed 122 times
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.

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

Return to “Other Products from Adafruit”