Datasheet

Raw Data Access API
If you don't wish to use the Unified Sensor API, you can access the raw data for this sensor via the following three
functions:
uint16_t getLuminosity (uint8_t channel );
uint32_t getFullLuminosity ( );
uint32_t calculateLux ( uint16_t ch0, uint16_t ch1 );
getLuminosity can be used to read either the visible spectrum light sensor, or the infrared light sensor. It will return the
raw 16-bit sensor value for the specified channel, as shown in the code below:
getFullLuminosity reads both the IR and full spectrum sensors at the same time to allow tigher correlation between the
values, and then separates them in SW. The function returns a 32-bit value which needs to be split into two 16-bit
/**************************************************************************/
/*
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);
}
/**************************************************************************/
/*
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);
}
© Adafruit Industries https://learn.adafruit.com/adafruit-tsl2591 Page 17 of 24