Kenji Arai / TSL2561

Dependents:   MusicBoxForFathersDay FTHR_SensorHub Affich_Lum_Moist Projetv0 ... more

Embed: (wiki syntax)

« Back to documentation index

TSL2561 Class Reference

TSL2561 Class Reference

Interface for Luminosity sensor, TSL2561. More...

#include <TSL2561.h>

Public Member Functions

 TSL2561 (PinName p_sda, PinName p_scl)
 Configure data pin.
 TSL2561 (I2C &p_i2c)
 Configure data pin (with other devices on I2C line)
float lux (void)
 Get approximates the human eye response in the commonly used Illuminance unit of Lux.
float lux_auto (void)
 Get approximates the human eye response with "Auto Range" in the commonly used Illuminance unit of Lux.
uint8_t set_timing_reg (uint8_t parameter)
 Set timing register.
uint8_t read_timing_reg (void)
 Read timing register.
void frequency (int hz)
 Set I2C clock frequency.
uint8_t who_am_i (void)
 check Device ID number
uint8_t read_ID (void)
 Read ID and Revision Number.
void power_up (void)
 Power Up/Down.
bool init ()
 Initializes I2C connection and settings. Attempts to determine if the sensor is contactable, then sets up a default integration time and gain. Then powers down the chip.
void enableAutoRange (bool enable)
 Enables or disables the auto-gain settings when reading data from the sensor.
void setIntegrationTime (TSL2561IntegrationTime_t time)
 Sets the integration time for the TSL2561. Higher time means more light captured (better for low light conditions) but will take longer to run readings.
void setGain (TSL2561Gain_t gain)
 Adjusts the gain on the TSL2561 (adjusts the sensitivity to light)
void getLuminosity (uint16_t *broadband, uint16_t *ir)
 Gets the broadband (mixed lighting) and IR only values from the TSL2561, adjusting gain if auto-gain is enabled.
uint32_t calculateLux (uint16_t broadband, uint16_t ir)
 Converts the raw sensor values to the standard SI lux equivalent.
bool getEvent (uint32_t *)
 Gets the most recent sensor event.
void getSensor (sensor_t *)
 Gets the sensor_t data.

Detailed Description

Interface for Luminosity sensor, TSL2561.

 #include "mbed.h"
 #include "TSL2561.h"

 // I2C Communication
  TSL2561      lum(dp5,dp27);    // TSL2561 SDA, SCL
 // If you connected I2C line not only this device but also other devices,
 //     you need to declare following method.
  I2C          i2c(dp5,dp27); // SDA, SCL
  TSL2561      lum(i2c); // TSL2561 SDA, SCL (Data available every 400mSec)

 int main() {;
   while(true){
      printf("Illuminance: %+7.2f [Lux]\r\n", lum.lux());
      wait(1.0);
   }
 }

Class that stores state and functions for interacting with TSL2561 Light Sensor

Definition at line 169 of file TSL2561.h.


Constructor & Destructor Documentation

TSL2561 ( PinName  p_sda,
PinName  p_scl 
)

Configure data pin.

Parameters:
dataSDA and SCL pins

Definition at line 136 of file TSL2561.cpp.

TSL2561 ( I2C &  p_i2c )

Configure data pin (with other devices on I2C line)

Parameters:
I2Cprevious definition

Definition at line 150 of file TSL2561.cpp.


Member Function Documentation

uint32_t calculateLux ( uint16_t  broadband,
uint16_t  ir 
)

Converts the raw sensor values to the standard SI lux equivalent.

Parameters:
broadbandThe 16-bit sensor reading from the IR+visible light diode.
irThe 16-bit sensor reading from the IR-only light diode.
Returns:
The integer Lux value we calcuated. Returns 0 if the sensor is saturated and the values are unreliable, or 65536 if the sensor is saturated.

Returns

Definition at line 471 of file TSL2561.cpp.

void enableAutoRange ( bool  enable )

Enables or disables the auto-gain settings when reading data from the sensor.

Parameters:
enableSet to true to enable, False to disable

Definition at line 277 of file TSL2561.cpp.

void frequency ( int  hz )

Set I2C clock frequency.

Parameters:
freq.
Returns:
none

Definition at line 772 of file TSL2561.cpp.

bool getEvent ( uint32_t *  event )

Gets the most recent sensor event.

Parameters:
eventPointer to a sensor_event_t type that will be filled with the lux value, timestamp, data type and sensor ID.
Returns:
True if sensor reading is between 0 and 65535 lux, false if sensor is saturated

Definition at line 610 of file TSL2561.cpp.

void getLuminosity ( uint16_t *  broadband,
uint16_t *  ir 
)

Gets the broadband (mixed lighting) and IR only values from the TSL2561, adjusting gain if auto-gain is enabled.

Parameters:
broadbandPointer to a uint16_t we will fill with a sensor reading from the IR+visible light diode.
irPointer to a uint16_t we will fill with a sensor the IR-only light diode.

Definition at line 330 of file TSL2561.cpp.

void getSensor ( sensor_t sensor )

Gets the sensor_t data.

Parameters:
sensorA pointer to a sensor_t structure that we will fill with details about the TSL2561 and its capabilities

Definition at line 636 of file TSL2561.cpp.

bool init (  )

Initializes I2C connection and settings. Attempts to determine if the sensor is contactable, then sets up a default integration time and gain. Then powers down the chip.

Returns:
True if sensor is found and initialized, false otherwise.

Definition at line 236 of file TSL2561.cpp.

float lux ( void   )

Get approximates the human eye response in the commonly used Illuminance unit of Lux.

Parameters:
none
Returns:
Lux

Definition at line 175 of file TSL2561.cpp.

float lux_auto ( void   )

Get approximates the human eye response with "Auto Range" in the commonly used Illuminance unit of Lux.

Parameters:
none
Returns:
Lux

Definition at line 218 of file TSL2561.cpp.

void power_up ( void   )

Power Up/Down.

Parameters:
none
Returns:
none

Definition at line 761 of file TSL2561.cpp.

uint8_t read_ID ( void   )

Read ID and Revision Number.

Parameters:
none
Returns:
ID + REVNO

Definition at line 742 of file TSL2561.cpp.

uint8_t read_timing_reg ( void   )

Read timing register.

Parameters:
timingparameter
Returns:
timing read data

Definition at line 707 of file TSL2561.cpp.

uint8_t set_timing_reg ( uint8_t  parameter )

Set timing register.

Parameters:
timingparameter
Returns:
timing read data

Definition at line 700 of file TSL2561.cpp.

void setGain ( TSL2561Gain_t  gain )

Adjusts the gain on the TSL2561 (adjusts the sensitivity to light)

Parameters:
gainThe value we'd like to set the gain to

Definition at line 308 of file TSL2561.cpp.

void setIntegrationTime ( TSL2561IntegrationTime_t  time )

Sets the integration time for the TSL2561. Higher time means more light captured (better for low light conditions) but will take longer to run readings.

Parameters:
timeThe amount of time we'd like to add up values

Definition at line 290 of file TSL2561.cpp.

uint8_t who_am_i ( void   )

check Device ID number

Parameters:
none
Returns:
TSL2561 = 1, others 0

Definition at line 748 of file TSL2561.cpp.