Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
bd7a986d
Commit
bd7a986d
authored
Jan 12, 2016
by
devsaurus
Browse files
transferred tsl2561 module documentation
parent
6c75dd40
Changes
2
Show whitespace changes
Inline
Side-by-side
docs/en/modules/tsl2561.md
0 → 100644
View file @
bd7a986d
# TSL2561 Module
## tsl2561.getlux()
Reads sensor values from the device and returns calculated lux value.
#### Syntax
`tsl2561.getlux()`
#### Parameters
none
#### Returns
-
`lux`
the calculated illuminance in lux (lx)
-
`status`
value indicating success or failure as explained below:
*
`tsl2561.TSL2561_OK`
*
`tsl2561.TSL2561_ERROR_I2CINIT`
can't initialize I2C bus
*
`tsl2561.TSL2561_ERROR_I2CBUSY`
I2C bus busy
*
`tsl2561.TSL2561_ERROR_NOINIT`
initialize I2C bus before calling function
*
`tsl2561.TSL2561_ERROR_LAST`
#### Example
```
lua
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
-
`ch0`
value of the broad spectrum sensor
-
`ch1`
value of the IR sensor
-
`status`
value indicating success or failure as explained below:
*
`tsl2561.TSL2561_OK`
*
`tsl2561.TSL2561_ERROR_I2CINIT`
can't initialize I2C bus
*
`tsl2561.TSL2561_ERROR_I2CBUSY`
I2C bus busy
*
`tsl2561.TSL2561_ERROR_NOINIT`
initialize I2C bus before calling function
*
`tsl2561.TSL2561_ERROR_LAST`
#### Example
```
lua
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
-
`sdapin`
pin number of the device's I2C sda connection
-
`sclpin`
pin number of the device's I2C scl connection
-
`address`
optional address of the device on the I2C bus
*
`tsl2561.ADDRESS_GND`
*
`tsl2561.ADDRESS_FLOAT`
(default when omitted)
*
`tsl2561.ADDRESS_VDD`
-
`package`
optional device's package type (slight difference in lux calculation)
*
`tsl2561.PACKAGE_CS`
*
`tsl2561.PACKAGE_T_FN_CL`
(default when omitted)
#### Returns
`status`
value indicating success or failure as explained below
-
`tsl2561.TSL2561_OK`
-
`tsl2561.TSL2561_ERROR_I2CINIT`
can't initialize I2C bus
-
`tsl2561.TSL2561_ERROR_I2CBUSY`
I2C bus busy
-
`tsl2561.TSL2561_ERROR_NOINIT`
Initialize I2C bus before calling function
-
`tsl2561.TSL2561_ERROR_LAST`
#### Example
```
lua
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
-
`integration`
sets the device's integration period. Valid options are:
*
`tsl2561.INTEGRATIONTIME_13MS`
*
`tsl2561.INTEGRATIONTIME_101MS`
*
`tsl2561.INTEGRATIONTIME_402MS`
(default when omitted)
-
`gain`
sets 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_OK`
-
`tsl2561.TSL2561_ERROR_I2CINIT`
can't initialize I2C bus
-
`tsl2561.TSL2561_ERROR_I2CBUSY`
I2C bus busy
-
`tsl2561.TSL2561_ERROR_NOINIT`
initialize I2C bus before calling function
-
`tsl2561.TSL2561_ERROR_LAST`
#### Example
```
lua
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
```
mkdocs.yml
View file @
bd7a986d
...
@@ -48,6 +48,7 @@ pages:
...
@@ -48,6 +48,7 @@ pages:
-
'
sntp'
:
'
en/modules/sntp.md'
-
'
sntp'
:
'
en/modules/sntp.md'
-
'
spi'
:
'
en/modules/spi.md'
-
'
spi'
:
'
en/modules/spi.md'
-
'
tmr'
:
'
en/modules/tmr.md'
-
'
tmr'
:
'
en/modules/tmr.md'
-
'
tsl2561'
:
'
en/modules/tsl2561.md'
-
'
u8g'
:
'
en/modules/u8g.md'
-
'
u8g'
:
'
en/modules/u8g.md'
-
'
uart'
:
'
en/modules/uart.md'
-
'
uart'
:
'
en/modules/uart.md'
-
'
ucg'
:
'
en/modules/ucg.md'
-
'
ucg'
:
'
en/modules/ucg.md'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment