embello

Embedded software from JeeLabs

Embello Home Page
Hardware Documentation
Forth Library Documentation

TSL4531 I2C ambient light sensor

This is an I2C driver for the Taos/AMS TSL4531 digital light sensor.

API

To initialize the chip and the driver tsl-init must be called. This places the chip in normal (continuous) conversion mode using a 400ms integration time. tsl-data returns the result of the last conversion as a 32-bit integer Lux value.

: tsl-init ( -- nak ) \ put device into normal mode, 400ms integration
: tsl-data ( -- v ) \ read data

For low power operation (e.g. battery) the chip can be put to sleep and woken up when a conversion is desired. Start with tsl-sleep and when a conversion is desired, use tsl-convert to initiate a one-shot conversion. It returns the number of milliseconds to wait before the conversion data can be retrieved using tsl-data. The chip goes back to sleep automatically after the conversion.

: tsl-sleep ( -- ) \ put device to sleep
: tsl-convert ( -- ms ) \ one-shot conversion, returns time to sleep before tsl-data

Constants

The I2C address is hard-coded as $29.