TSL2561 Module¶
| Since | Origin / Contributor | Maintainer | Source |
|---|---|---|---|
| 2015-08-22 | Michael Lucas | Michael Lucas | tsl2561.c |
tsl2561.getlux()¶
Reads sensor values from the device and returns calculated lux value.
Syntax¶
tsl2561.getlux()
Parameters¶
none
Returns¶
luxthe calculated illuminance in lux (lx)statusvalue indicating success or failure as explained below:tsl2561.TSL2561_OKtsl2561.TSL2561_ERROR_I2CINITcan't initialize I²C bustsl2561.TSL2561_ERROR_I2CBUSYI²C bus busytsl2561.TSL2561_ERROR_NOINITinitialize I²C bus before calling functiontsl2561.TSL2561_ERROR_LAST
Example¶
status = tsl2561.init(5, 6, tsl2561.ADDRESS_FLOAT, tsl2561.PACKAGE_T_FN_CL)
if status == tsl2561.TSL2561_OK then
lux = tsl2561.getlux()
print("Illuminance: "..lux.." lx")
end
tsl2561.getrawchannels()¶
Reads the device's 2 sensors and returns their values.
Syntax¶
tsl2561.getrawchannels()
Parameters¶
none
Returns¶
ch0value of the broad spectrum sensorch1value of the IR sensorstatusvalue indicating success or failure as explained below:tsl2561.TSL2561_OKtsl2561.TSL2561_ERROR_I2CINITcan't initialize I²C bustsl2561.TSL2561_ERROR_I2CBUSYI²C bus busytsl2561.TSL2561_ERROR_NOINITinitialize I²C bus before calling functiontsl2561.TSL2561_ERROR_LAST
Example¶
status = tsl2561.init(5, 6, tsl2561.ADDRESS_FLOAT, tsl2561.PACKAGE_T_FN_CL)
if status == tsl2561.TSL2561_OK then
ch0, ch1 = tsl2561.getrawchannels()
print("Raw values: "..ch0, ch1)
lux = tsl2561.getlux()
print("Illuminance: "..lux.." lx")
end
tsl2561.init()¶
Initializes the device on pins sdapin & sclpin. Optionally also configures the devices address and package. Default: address pin floating (0x39) and FN package.
Syntax¶
tsl2561.init(sdapin, sclpin[, address[, package]])
Parameters¶
sdapinpin number of the device's I²C sda connectionsclpinpin number of the device's I²C scl connectionaddressoptional address of the device on the I²C bustsl2561.ADDRESS_GNDtsl2561.ADDRESS_FLOAT(default when omitted)tsl2561.ADDRESS_VDD
packageoptional device's package type (slight difference in lux calculation)tsl2561.PACKAGE_CStsl2561.PACKAGE_T_FN_CL(default when omitted)
Returns¶
status value indicating success or failure as explained below:
tsl2561.TSL2561_OKtsl2561.TSL2561_ERROR_I2CINITcan't initialize I²C bustsl2561.TSL2561_ERROR_I2CBUSYI²C bus busytsl2561.TSL2561_ERROR_NOINITInitialize I²C bus before calling functiontsl2561.TSL2561_ERROR_LAST
Example¶
status = tsl2561.init(5, 6, tsl2561.ADDRESS_FLOAT, tsl2561.PACKAGE_T_FN_CL)
if status == tsl2561.TSL2561_OK then
lux = tsl2561.getlux()
print("Illuminance: "..lux.." lx")
end
tsl2561.settiming()¶
Sets the integration time and gain settings of the device. When tls2561.init() is called, these values default to 402 ms and no gain.
Syntax¶
tsl2561.settiming(integration, gain)
Parameters¶
integrationsets the device's integration period. Valid options are:tsl2561.INTEGRATIONTIME_13MStsl2561.INTEGRATIONTIME_101MStsl2561.INTEGRATIONTIME_402MS(default when omitted)
gainsets the device's gain. Valid options are:tsl2561.GAIN_1X(default when omitted)tsl2561.GAIN_16X
Returns¶
status value indicating success or failure as explained below:
tsl2561.TSL2561_OKtsl2561.TSL2561_ERROR_I2CINITcan't initialize I²C bustsl2561.TSL2561_ERROR_I2CBUSYI²C bus busytsl2561.TSL2561_ERROR_NOINITinitialize I²C bus before calling functiontsl2561.TSL2561_ERROR_LAST
Example¶
status = tsl2561.init(5, 6, tsl2561.ADDRESS_FLOAT, tsl2561.PACKAGE_T_FN_CL)
if status == tsl2561.TSL2561_OK then
status = tsl2561.settiming(tsl2561.INTEGRATIONTIME_101MS, tsl2561.GAIN_16X)
end
if status == tsl2561.TSL2561_OK then
lux = tsl2561.getlux()
print("Illuminance: "..lux.." lx")
end