This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OPT3001: OPT3001DNP interface with ARDUINO for INTERRUPT

Part Number: OPT3001

Hi team,

We are using OPT3001DNP(ALS sensor) with Arduino nano and trying to read interrupt signal while reading lux value 
we are using 12c communicatin for that and able to read lux value properly but
when we try to observe interrupt signal on DSO by probing, we are not getting any interrupt signal on DSO.

i am attaching the Arduino sketch that we are using .....kindly look in and provide some modifications if required.

#include <Wire.h>
#define OPT3001_A_ADDR 0x44       // Light sensor 1 HEX address


void setup() {
  
  Serial.begin(9600);                            // Initialize serial communication at 9600
  Wire.begin();                                  // Initialize Arduino in I2C master.
  Wire.beginTransmission(OPT3001_A_ADDR);                  // I2C address of OPT3001 = 0x44
  Wire.write(0x01);                              // Config register address 0x01
  Wire.write(0xCE);
  Wire.write(0x10);                              // Write 0xCE10 to turn on sensor
  Wire.endTransmission();
  Serial.println("Data received \t\t Lux");
}

void loop() {
  Wire.beginTransmission(OPT3001_A_ADDR);
  Wire.write(0x00);                              // Send result register address
  Wire.endTransmission();
  delay(100);
  
  Wire.requestFrom(OPT3001_A_ADDR, 2);                     // Request 2 bytes data from OPT3001
  uint16_t iData;
  uint8_t  iBuff[2];
  while (Wire.available()) { 

    iBuff[0]=Wire.read();
    iBuff[1]=Wire.read();

    
    iData = (iBuff[0] << 8) | iBuff[1];
    float fLux = SensorOpt3001_convert(iData);   // Calculate LUX from sensor data
 
 Serial.print(iData,BIN);                     // Print the received data
    Serial.print("\t\t");
    Serial.println(fLux);                        // Print it on serial terminal
  }
  delay(1000);
}

float SensorOpt3001_convert(uint16_t iRawData){
 
  uint16_t iExponent, iMantissa;
  iMantissa = iRawData & 0x0FFF;                 // Extract Mantissa
  iExponent = (iRawData & 0xF000) >> 12;         // Extract Exponent 
  return iMantissa * (0.01 * pow(2, iExponent)); // Calculate final LUX
}
 

  • Hi Vishal,

    Thank you for posting to the Sensing forum.

    In line 12 you are setting bit 4 of the Configuration to 1, which places the device in latched window-style comparison mode. Please ensure that you are reading the Configuration register to clear the interrupt flags.

    In latched window-style comparison mode the interrupt is latched after a fault event until the Configuration register is read, which clears the INT pin and flag low/high fields. If the Configuration register is not read, the interrupt reporting mechanisms will stay latched.

    Table 2 in Section 7.4.2.1 of the datasheet details the behavior of the interrupt reporting mechanisms. 

       

    Best regards,

    Nicole

  • Hi Nicole,

    Thanks for your response, We are looking to use the OPT in 'End of Conversion' Mode so may you help to achieve that and please clarify do we have to read the interrupt manually in End of Conversion mode.

    >In line 12 you are setting bit 4 of the Configuration to 1
    is it the right practice ??

  • Hi Vishal,

    End-of-Conversion mode is entered by setting bits LE[3:2] in the Low-Limit Register to 11b. End-of-conversion mode can be used with the latched window-style comparison mode, there is no problem with that. The Configuration Register still needs to be read in order to clear INT pin and high/low flags.

    Best regards,
    Nicole