Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MusicBoxForFathersDay FTHR_SensorHub Affich_Lum_Moist Projetv0 ... more
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 | ||
) |
TSL2561 | ( | I2C & | p_i2c ) |
Configure data pin (with other devices on I2C line)
- Parameters:
-
I2C previous 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:
-
broadband The 16-bit sensor reading from the IR+visible light diode. ir The 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:
-
enable Set to true to enable, False to disable
Definition at line 277 of file TSL2561.cpp.
void frequency | ( | int | hz ) |
bool getEvent | ( | uint32_t * | event ) |
Gets the most recent sensor event.
- Parameters:
-
event Pointer 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:
-
broadband Pointer to a uint16_t we will fill with a sensor reading from the IR+visible light diode. ir Pointer 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:
-
sensor A 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 | ) |
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:
-
timing parameter
- Returns:
- timing read data
Definition at line 707 of file TSL2561.cpp.
uint8_t set_timing_reg | ( | uint8_t | parameter ) |
Set timing register.
- Parameters:
-
timing parameter
- 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:
-
gain The 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:
-
time The 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.
Generated on Wed Jul 13 2022 17:46:41 by
