element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum TSL2591 Light Sensor
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 6 replies
  • Subscribers 391 subscribers
  • Views 1485 views
  • Users 0 members are here
Related

TSL2591 Light Sensor

aureta
aureta over 10 years ago

Hi, according to the specs of the Adafruit TSL2591 High Dynamic Range Digital Light Sensor it can sense from 0.000118 to 88,000 Lux. So far I wasn´t able to get readings below 0 lux. Is it really possible to get readings as low as advertised?. If so, ca I get help with the coding for Arduino?. Best, Alejandro.

  • Sign in to reply
  • Cancel

Top Replies

  • neilk
    neilk over 10 years ago in reply to aureta +1
    aureta you never came back and told us if you solved your earlier problem with the TSL2591 - headed "Sensor Interference" It's always useful to know that a problem has been solved (and why) Neil
Parents
  • gadget.iom
    gadget.iom over 10 years ago

    Are you working with integers?

    If so you will only get representation of whole numbers.

     

    It is difficult to assist with coding problems unless you are able/willing to share your code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • aureta
    aureta over 10 years ago in reply to gadget.iom

    Hi, I am working now with this code but it does not compile..

     

    /* TSL25911 Digital Light Sensor */

    /* Dynamic Range: 600M:1 */

    /* Maximum Lux: 88K */

     

     

    #include <Wire.h>

    #include <Adafruit_Sensor.h>

    #include "Adafruit_TSL2591.h"

     

     

    // Example for demonstrating the TSL2591 library - public domain!

     

     

    // connect SCL to analog 5

    // connect SDA to analog 4

    // connect Vin to 3.3-5V DC

    // connect GROUND to common ground

     

     

    Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)

     

     

    /**************************************************************************/

    /*

        Displays some basic information on this sensor from the unified

        sensor API sensor_t type (see Adafruit_Sensor for more information)

    */

    /**************************************************************************/

    void displaySensorDetails(void)

    {

      sensor_t sensor;

      tsl.getSensor(&sensor);

      Serial.println("------------------------------------");

      Serial.print  ("Sensor:       "); Serial.println(sensor.name);

      Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);

      Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);

      Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");

      Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");

      Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux"); 

      Serial.println("------------------------------------");

      Serial.println("");

      delay(500);

    }

     

     

    /**************************************************************************/

    /*

        Configures the gain and integration time for the TSL2561

    */

    /**************************************************************************/

    void configureSensor(void)

    {

      // You can change the gain on the fly, to adapt to brighter/dimmer light situations

      //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)

      tsl.setGain(TSL2591_GAIN_MED);      // 25x gain

      //tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain

     

      // Changing the integration time gives you a longer time over which to sense light

      // longer timelines are slower, but are good in very low light situtations!

      tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)

     

     

      /* Display the gain and integration time for reference sake */ 

      Serial.println("------------------------------------");

      Serial.print  ("Gain:         ");

      tsl2591Gain_t gain = tsl.getGain();

      switch(gain)

      {

        case TSL2591_GAIN_LOW:

          Serial.println("1x (Low)");

          break;

        case TSL2591_GAIN_MED:

          Serial.println("25x (Medium)");

          break;

        case TSL2591_GAIN_HIGH:

          Serial.println("428x (High)");

          break;

        case TSL2591_GAIN_MAX:

          Serial.println("9876x (Max)");

          break;

      }

      Serial.print  ("Timing:       ");

      Serial.print((tsl.getTiming() + 1) * 100, DEC);

      Serial.println(" ms");

      Serial.println("------------------------------------");

      Serial.println("");

    }

     

     

    /**************************************************************************/

    /*

        Program entry point for the Arduino sketch

    */

    /**************************************************************************/

    void setup(void)

    {

      Serial.begin(9600);

     

      Serial.println("Starting Adafruit TSL2591 Test!");

     

      if (tsl.begin())

      {

        Serial.println("Found a TSL2591 sensor");

      }

      else

      {

        Serial.println("No sensor found ... check your wiring?");

        while (1);

      }

       

      /* Display some basic information on this sensor */

      displaySensorDetails();

     

      /* Configure the sensor */

      configureSensor();

       

      // Now we're ready to get readings ... move on to loop()!

    }

     

     

    /**************************************************************************/

    /*

        Shows how to perform a basic read on visible, full spectrum or

        infrared light (returns raw 16-bit ADC values)

    */

    /**************************************************************************/

    void simpleRead(void)

    {

      // Simple data read example. Just read the infrared, fullspecrtrum diode

      // or 'visible' (difference between the two) channels.

      // This can take 100-600 milliseconds! Uncomment whichever of the following you want to read

      uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);

      //uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM);

      //uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);

     

     

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("Luminosity: ");

      Serial.println(x, DEC);

    }

     

     

    /**************************************************************************/

    /*

        Show how to read IR and Full Spectrum at once and convert to lux

    */

    /**************************************************************************/

    void advancedRead(void)

    {

      // More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum

      // That way you can do whatever math and comparisons you want!

      uint32_t lum = tsl.getFullLuminosity();

      uint16_t ir, full;

      ir = lum >> 16;

      full = lum & 0xFFFF;

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("IR: "); Serial.print(ir);  Serial.print("  ");

      Serial.print("Full: "); Serial.print(full); Serial.print("  ");

      Serial.print("Visible: "); Serial.print(full - ir); Serial.print("  ");

      Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));

    }

     

     

    /**************************************************************************/

    /*

        Performs a read using the Adafruit Unified Sensor API.

    */

    /**************************************************************************/

    void unifiedSensorAPIRead(void)

    {

      /* Get a new sensor event */

      sensors_event_t event;

      tsl.getEvent(&event);

     

      /* Display the results (light is measured in lux) */

      Serial.print("[ "); Serial.print(event.timestamp); Serial.print(" 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("Invalid data (adjust gain or timing)");

      }

      else

      {

        Serial.print(event.light); Serial.println(" lux");

      }

    }

     

     

    /**************************************************************************/

    /*

        Arduino loop function, called once 'setup' is complete (your own code

        should go here)

    */

    /**************************************************************************/

    void loop(void)

    {

      // simpleRead();

      // advancedRead();

      unifiedSensorAPIRead();

     

      delay(250);

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to aureta

    Please edit the post and put the code with the correct syntax higligting, so we can copy and paste it and eventually try. Then, please tell us what kind of error you have. In the bottom side of the Arduino IDE you will see the error and line number where it occurs.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • gadget.iom
    gadget.iom over 10 years ago in reply to aureta

    Have you imported the Adafruit_Sensor library?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • aureta
    aureta over 10 years ago in reply to balearicdynamics

    I am again including the code. I have the Adafruit Sensor Master library. The error message I get is underneath the code. A. 

     

    #include <Wire.h>

    #include <Adafruit_Sensor.h>

    #include "Adafruit_TSL2591.h"

     

     

     

    Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);

    void displaySensorDetails(void)

    {

      sensor_t sensor;

      tsl.getSensor(&sensor);

    Serial.println("------------------------------------");

      Serial.print ("Sensor:       "); Serial.println(sensor.name);

      Serial.print ("Driver Ver:   "); Serial.println(sensor.version);

      Serial.print ("Unique ID:    "); Serial.println(sensor.sensor_id);

      Serial.print ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");

      Serial.print ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");

      Serial.print ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux"); 

    Serial.println("------------------------------------");

      Serial.println("");

      delay(500);

    }

     

    void configureSensor(void)

    {

      //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)

      tsl.setGain(TSL2591_GAIN_MED);      // 25x gain

      //tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain

     

     

    tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)

    Serial.println("------------------------------------");

      Serial.print ("Gain:         ");

      tsl2591Gain_t gain = tsl.getGain();

      switch(gain)

      {

        case TSL2591_GAIN_LOW:

          Serial.println("1x (Low)");

          break;

        case TSL2591_GAIN_MED:

          Serial.println("25x (Medium)");

          break;

        case TSL2591_GAIN_HIGH:

          Serial.println("428x (High)");

          break;

        case TSL2591_GAIN_MAX:

          Serial.println("9876x (Max)");

          break;

      }

      Serial.print ("Timing:       ");

      Serial.print((tsl.getTiming() + 1) * 100, DEC);

      Serial.println(" ms");

    Serial.println("------------------------------------");

      Serial.println("");

    }

     

    void setup(void)

    {

      Serial.begin(9600);

     

      Serial.println("Starting Adafruit TSL2591 Test!");

     

      if (tsl.begin())

      {

        Serial.println("Found a TSL2591 sensor");

      }

      else

      {

        Serial.println("No sensor found ... check your wiring?");

        while (1);

      }

       

      displaySensorDetails();

     

      configureSensor();

       

    }

     

    void simpleRead(void)

    {

      uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);

      //uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM);

      //uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);

     

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("Luminosity: ");

      Serial.println(x, DEC);

    }

     

    void advancedRead(void)

    {

      uint32_t lum = tsl.getFullLuminosity();

      uint16_t ir, full;

      ir = lum >> 16;

      full = lum & 0xFFFF;

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("IR: "); Serial.print(ir); Serial.print("  ");

      Serial.print("Full: "); Serial.print(full); Serial.print(" ");

      Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" ");

      Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));

    }

     

    void unifiedSensorAPIRead(void)

    {

        sensors_event_t event;

      tsl.getEvent(&event);

     

     

      Serial.print("[ "); Serial.print(event.timestamp); Serial.print(" ms ] ");

      if ((event.light == 0) |

          (event.light > 4294966000.0) |

          (event.light <-4294966000.0))

      {

        Serial.println("Invalid data (adjust gain or timing)");

      }

      else

      {

        Serial.print(event.light); Serial.println(" lux");

      }

    }

     

    void loop(void)

    {

      // simpleRead();

      // advancedRead();

    unifiedSensorAPIRead();

     

      delay(250);

    }

     

     

     

     

    ------------------------------------------------------

    Error Message:

    Arduino:1.6.1 (Windows 8.1), Placa:"Arduino Mega ADK"

     

    In file included from sketch_jun01a.ino:4:0:

    C:\Users\alejandro\Documents\Arduino\libraries\Adafruit_TSL2591/Adafruit_TSL2591.h:144:8: error: conflicting return type specified for 'virtual void Adafruit_TSL2591::getEvent(sensors_event_t*)'

       void getEvent  ( sensors_event_t* );

            ^

    In file included from sketch_jun01a.ino:3:0:

    C:\Users\alejandro\Documents\Arduino\libraries\Adafruit_Sensor-master/Adafruit_Sensor.h:147:16: error:   overriding 'virtual bool Adafruit_Sensor::getEvent(sensors_event_t*)'

       virtual bool getEvent(sensors_event_t*) = 0;

                    ^

    Error de compilación

     

      This report would have more information with

      "Show verbose output during compilation"

      activala desde Archivo > Preferencias

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • aureta
    aureta over 10 years ago in reply to balearicdynamics

    I am again including the code. I have the Adafruit Sensor Master library. The error message I get is underneath the code. A. 

     

    #include <Wire.h>

    #include <Adafruit_Sensor.h>

    #include "Adafruit_TSL2591.h"

     

     

     

    Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);

    void displaySensorDetails(void)

    {

      sensor_t sensor;

      tsl.getSensor(&sensor);

    Serial.println("------------------------------------");

      Serial.print ("Sensor:       "); Serial.println(sensor.name);

      Serial.print ("Driver Ver:   "); Serial.println(sensor.version);

      Serial.print ("Unique ID:    "); Serial.println(sensor.sensor_id);

      Serial.print ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");

      Serial.print ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");

      Serial.print ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux"); 

    Serial.println("------------------------------------");

      Serial.println("");

      delay(500);

    }

     

    void configureSensor(void)

    {

      //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)

      tsl.setGain(TSL2591_GAIN_MED);      // 25x gain

      //tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain

     

     

    tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);

    //tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);

      //tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)

    Serial.println("------------------------------------");

      Serial.print ("Gain:         ");

      tsl2591Gain_t gain = tsl.getGain();

      switch(gain)

      {

        case TSL2591_GAIN_LOW:

          Serial.println("1x (Low)");

          break;

        case TSL2591_GAIN_MED:

          Serial.println("25x (Medium)");

          break;

        case TSL2591_GAIN_HIGH:

          Serial.println("428x (High)");

          break;

        case TSL2591_GAIN_MAX:

          Serial.println("9876x (Max)");

          break;

      }

      Serial.print ("Timing:       ");

      Serial.print((tsl.getTiming() + 1) * 100, DEC);

      Serial.println(" ms");

    Serial.println("------------------------------------");

      Serial.println("");

    }

     

    void setup(void)

    {

      Serial.begin(9600);

     

      Serial.println("Starting Adafruit TSL2591 Test!");

     

      if (tsl.begin())

      {

        Serial.println("Found a TSL2591 sensor");

      }

      else

      {

        Serial.println("No sensor found ... check your wiring?");

        while (1);

      }

       

      displaySensorDetails();

     

      configureSensor();

       

    }

     

    void simpleRead(void)

    {

      uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);

      //uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM);

      //uint16_t x = tsl.getLuminosity(TSL2561_INFRARED);

     

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("Luminosity: ");

      Serial.println(x, DEC);

    }

     

    void advancedRead(void)

    {

      uint32_t lum = tsl.getFullLuminosity();

      uint16_t ir, full;

      ir = lum >> 16;

      full = lum & 0xFFFF;

      Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");

      Serial.print("IR: "); Serial.print(ir); Serial.print("  ");

      Serial.print("Full: "); Serial.print(full); Serial.print(" ");

      Serial.print("Visible: "); Serial.print(full - ir); Serial.print(" ");

      Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));

    }

     

    void unifiedSensorAPIRead(void)

    {

        sensors_event_t event;

      tsl.getEvent(&event);

     

     

      Serial.print("[ "); Serial.print(event.timestamp); Serial.print(" ms ] ");

      if ((event.light == 0) |

          (event.light > 4294966000.0) |

          (event.light <-4294966000.0))

      {

        Serial.println("Invalid data (adjust gain or timing)");

      }

      else

      {

        Serial.print(event.light); Serial.println(" lux");

      }

    }

     

    void loop(void)

    {

      // simpleRead();

      // advancedRead();

    unifiedSensorAPIRead();

     

      delay(250);

    }

     

     

     

     

    ------------------------------------------------------

    Error Message:

    Arduino:1.6.1 (Windows 8.1), Placa:"Arduino Mega ADK"

     

    In file included from sketch_jun01a.ino:4:0:

    C:\Users\alejandro\Documents\Arduino\libraries\Adafruit_TSL2591/Adafruit_TSL2591.h:144:8: error: conflicting return type specified for 'virtual void Adafruit_TSL2591::getEvent(sensors_event_t*)'

       void getEvent  ( sensors_event_t* );

            ^

    In file included from sketch_jun01a.ino:3:0:

    C:\Users\alejandro\Documents\Arduino\libraries\Adafruit_Sensor-master/Adafruit_Sensor.h:147:16: error:   overriding 'virtual bool Adafruit_Sensor::getEvent(sensors_event_t*)'

       virtual bool getEvent(sensors_event_t*) = 0;

                    ^

    Error de compilación

     

      This report would have more information with

      "Show verbose output during compilation"

      activala desde Archivo > Preferencias

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • neilk
    neilk over 10 years ago in reply to aureta

    aureta you never came back and told us if you solved your earlier problem with the TSL2591 - headed "Sensor Interference"

     

    It's always useful to know that a problem has been solved (and why) image

     

    Neil

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube