Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Two TSL2591 light sensors with Arduino with data logger shie
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Two TSL2591 light sensors with Arduino with data logger shie

by Dinesh933 on Sun Dec 05, 2021 12:59 am

Hey everyone
I m try to make data logging lux sensor for our polyhouse which requires to collect lux data inside and outside of polyhouse for which i m trying to use two TSL2591 sensors but they r not working well together (one sensor work perfectly) if i cover one during test the other one give arbitrary data for both sensors.
should i use muliplex for i2c bus as it is not possible to change i2c address of tsl2591
Thanks in advance

Dinesh933
 
Posts: 3
Joined: Sun Dec 05, 2021 12:52 am

Re: Two TSL2591 light sensors with Arduino with data logger

by franklin97355 on Sun Dec 05, 2021 2:28 am

i2c requires each sensor to have a unique address so a multiplexer would be recommended.

franklin97355
 
Posts: 22414
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Two TSL2591 light sensors with Arduino with data logger

by Dinesh933 on Sun Dec 05, 2021 12:00 pm

Hey
Thanks for the quick reply
can u please elaborate what adafruit want to explain in this constructer part as i m new to stuff like this
32 bit object ? is it like declaring it equal to some float object
Attachments
Screenshot_20211205-212227.jpg
Screenshot_20211205-212227.jpg (169.35 KiB) Viewed 572 times

Dinesh933
 
Posts: 3
Joined: Sun Dec 05, 2021 12:52 am

Re: Two TSL2591 light sensors with Arduino with data logger

by dastels on Sun Dec 05, 2021 1:26 pm

As franklin97355 said, to use more than one of these sensors you need either multiple I2C busses or an I2C multiplexor https://www.adafruit.com/product/2717.

If you do have multiple of them, the constructor argument provides an ID to that sensor that is used to tag readings from it. That way you can always associate a reading with exactly where it came from.

Dave

dastels
 
Posts: 8430
Joined: Tue Oct 20, 2015 3:22 pm

Re: Two TSL2591 light sensors with Arduino with data logger

by Dinesh933 on Mon Dec 13, 2021 10:34 am

Hey Guys

As u suggested, now i m trying TCA9548A multiplexer for TSL2591 but when i try to run code serial monitor shows "No sensor found" as sensor failed to begin
while using "TCA9548 I2CScanner.ino" code it shows two devices which shows connection might be right.
please check code i m trying
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"

#define TCAADDR 0x70

Adafruit_TSL2591 tsl1 = Adafruit_TSL2591(1);
Adafruit_TSL2591 tsl2 = Adafruit_TSL2591(2);


void configureSensor1(void)
{
   tsl1.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
   tsl1.setTiming(TSL2591_INTEGRATIONTIME_400MS);
   
}

void configureSensor2(void)
{
   tsl2.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
   tsl2.setTiming(TSL2591_INTEGRATIONTIME_400MS);
   
}

void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission(); 
}

void setup(void)
{
  Serial.begin(9600);

    tcaselect(2);
    if (tsl1.begin())
  {
    Serial.println(F("Found a TSL2591 sensor1"));
  }
  else
  {
    Serial.println(F("No sensor found ... check your wiring1?"));
    while (1);
  }

  tcaselect(6);
  if (tsl2.begin())
  {
    Serial.println(F("Found a TSL2591 sensor"));
  }
  else
  {
    Serial.println(F("No sensor found ... check your wiring2?"));
    while (1);
  }
  tcaselect(2);
  configureSensor1();

  tcaselect(6);
  configureSensor2();
}

void loop(void)
{
    sensors_event_t event;

  tcaselect(2);
  tsl1.getEvent(&event);
  if ((event.light == 0) |
      (event.light > 4294966000.0) |
      (event.light <-4294966000.0))
  {
    /* If event.light = 0 lux the sensor is probably saturated */
    /* and no reliable data could be generated! */
    /* if event.light is +/- 4294967040 there was a float over/underflow */
    Serial.println(F("Invalid data (adjust gain or timing)"));
  }
  else
  {
    Serial.print(event.light); Serial.println(F(" lux1"));
}

  tcaselect(6);
  tsl2.getEvent(&event);

 // Serial.print(F("[ ")); Serial.print(event.timestamp); Serial.print(F(" ms ] "));
if ((event.light == 0) |
      (event.light > 4294966000.0) |
      (event.light <-4294966000.0))
  {
    /* If event.light = 0 lux the sensor is probably saturated */
    /* and no reliable data could be generated! */
    /* if event.light is +/- 4294967040 there was a float over/underflow */
    Serial.println(F("Invalid data (adjust gain or timing)"));
  }
  else
  {
    Serial.print(event.light); Serial.println(F(" lux"));
}
  delay(1000);
}
Attachments
Capture.PNG
Capture.PNG (13.62 KiB) Viewed 414 times

Dinesh933
 
Posts: 3
Joined: Sun Dec 05, 2021 12:52 am

Please be positive and constructive with your questions and comments.