Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.21 KB

README.md

File metadata and controls

31 lines (20 loc) · 1.21 KB

TSL2591 driver for Android things

This driver supports Adafruit TSL2591 light sensor. It is based on the TSL2591 Arduino library, but modified for Android Things and Kotlin.

NOTE: the driver is not production ready. There is no guarantee of correctness, completeness or robustness.

How to use

Sample usage

//  Connecting to the sensor
//  NOTE: the sensor is always at address 0x29
val device = PeripheralManager.getInstance().openI2cDevice("I2C1", 0x29);
val sensor = TSL2591(device)

//  For low light conditions you can set the integration time as well as gain
sensor.time = TSL.TSL2591_INTEGRATIONTIME_400MS
sensor.gain = TSL.TSL2591_GAIN_HIGH

//  Before using, remember to power on the sensor, because it starts off unpowered
sensor.powerOn()

//  To receive lux readings, just subscribe to the observable
//  NOTE: the first few values might not be the most accurate
sensor.getLux().subscribe { lux -> Log.d("TSL2591", "Lux:$lux") }

//  Once you complete your readings, you have to power off the device and close the connection
sensor.powerOff()
sensor.close()