Two TSL2591 light sensors with Arduino with data logger shie

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Dinesh933
 
Posts: 3
Joined: Sun Dec 05, 2021 12:52 am

Two TSL2591 light sensors with Arduino with data logger shie

Post by Dinesh933 »

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

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Two TSL2591 light sensors with Arduino with data logger

Post by Franklin97355 »

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

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

Re: Two TSL2591 light sensors with Arduino with data logger

Post by Dinesh933 »

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 1417 times

User avatar
dastels
 
Posts: 15662
Joined: Tue Oct 20, 2015 3:22 pm

Re: Two TSL2591 light sensors with Arduino with data logger

Post by dastels »

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

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

Re: Two TSL2591 light sensors with Arduino with data logger

Post by Dinesh933 »

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

#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 1259 times

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

Return to “For Educators”