0

TSL2591 Interrupt Question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

TSL2591 Interrupt Question

by teosegura13 on Fri Jun 11, 2021 11:23 am

Hello,

I am using the TSL2591 Sensor (https://learn.adafruit.com/adafruit-tsl2591) in a battery powered project. It needs to wake up when the lights turn off (its an alarm). My problem is that when I try to use the file /examples/tsl2591_interrupt.ino I can only get the interrupt to trigger the INT pin when I poll the device values in loop().

I want my device to be on sleep mode if the changes in the thresholds are not crossed, but if they're crossed, I want the INT pin to wake up the MCU.

1. Is this even possible? I read through the Datasheet and couldn't quite figure out if this is even an option (without polling the register from ASL interrupt)
2. Is there an error with the library? Or is this how it was designed to be
3. Any help or guidance OR examples would be greatly appreciated.

Thank you for your time!

teosegura13
 
Posts: 1
Joined: Fri Jun 11, 2021 11:10 am

Re: TSL2591 Interrupt Question

by blnkjns on Sun Jun 13, 2021 8:05 am

What is the microcontroller that you use with the sensor?

blnkjns
 
Posts: 663
Joined: Fri Oct 02, 2020 3:33 am

Re: TSL2591 Interrupt Question

by sj_remington on Sun Jun 13, 2021 11:18 am

On the TSL2591, the INT pin is open drain, so you need a pullup resistor to form a logic signal.

Yes, it is possible to have INT wake the processor.

sj_remington
 
Posts: 135
Joined: Mon Jul 27, 2020 4:51 pm

Re: TSL2591 Interrupt Question

by senfruit123 on Thu Aug 05, 2021 8:33 am

Hello,

I have the same problem. I also use the TSL2591 Sensor and I want my device to be on sleep mode and wake up only if light changes (above or below threshold).
The INT pin of TSL2591 is connected to PD3 of ATMEGA328P (pullup resistor is implemented). The function of the INT pin is working, if I poll the device values in loop.
But not if the ATMEGA328P is in sleep mode.
If I manually set the PD3 Pin to GND, the ATMEGA328P wakes up. So the problem is, that the INT function of TSL2591 doesn't work if I don't poll the device values in loop.

Can anyone help?

Thank you for your help!

senfruit123
 
Posts: 3
Joined: Thu Aug 05, 2021 7:42 am

Re: TSL2591 Interrupt Question

by sj_remington on Thu Aug 05, 2021 1:28 pm

Most likely, you have not set up the sensor correctly. Post the code, using code tags.

sj_remington
 
Posts: 135
Joined: Mon Jul 27, 2020 4:51 pm

Re: TSL2591 Interrupt Question

by senfruit123 on Mon Aug 09, 2021 5:08 am

Hi,

here are the relevant code lines from void setup() and void loop() in Arduino IDE.

Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_TSL2591.h"

void setup()
{
       setup_sensor();
}

void loop()
{
       advancedRead();
       tsl.clearInterrupt();
       delay(500);
}

void setup_sensor()
{
       tsl.setGain(TSL2591_GAIN_MED);                 // medium gain (25x)
       tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // integration time 100 ms
       tsl2591Gain_t gain = tsl.getGain();
       tsl.clearInterrupt();
       tsl.registerInterrupt(200,600,TSL2591_PERSIST_ANY); // (lowerThreshold, upperThreshold, values out of range)
}

void advancedRead(void)
{
       current_value =  tsl.getLuminosity(TSL2591_VISIBLE);
}



For the sensor TSL2591 I used the code from
https://github.com/adafruit/Adafruit_TSL2591_Library

I have made one change in the library from github: I did not enable the no-persist Interrupt, because if both interrupt types (ALS and no-persist) are enabled the interrupt function is not working.

Code: Select all | TOGGLE FULL SIZE
/**************************************************************************/
/*!
    @brief  Enables the chip, so it's ready to take readings
*/
/**************************************************************************/
void Adafruit_TSL2591::enable(void)
{
  if (!_initialized)
  {
    if (!begin())
    {
      return;
    }
  }

  // Enable the device by setting the control bit to 0x01
  write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE,
   TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN); // | TSL2591_ENABLE_NPIEN);
}


Thank you for helping!

senfruit123
 
Posts: 3
Joined: Thu Aug 05, 2021 7:42 am

Re: TSL2591 Interrupt Question

by sj_remington on Mon Aug 09, 2021 10:35 am

I did not enable the no-persist Interrupt, because if both interrupt types (ALS and no-persist) are enabled the interrupt function is not working.


There is only one interrupt, subject to various conditions. I think you misunderstand what "no-persist" means. You should spend some more time studying the TSL2591 data sheet, in order to understand how the interrupt works.

sj_remington
 
Posts: 135
Joined: Mon Jul 27, 2020 4:51 pm

Re: TSL2591 Interrupt Question

by senfruit123 on Tue Aug 17, 2021 7:41 am

Thanks for your replies. I found the cause.
The library from github power off the sensor at the end of every function.
I eliminated this lines, so that the sensor stays on.

After that, the sensor triggered the interrupt correctly, also if the MCU is powered off and does not poll the values via I2C.

@teosegura13: Maybe this works for you too?

senfruit123
 
Posts: 3
Joined: Thu Aug 05, 2021 7:42 am

Please be positive and constructive with your questions and comments.