This is a simple python library for the Adafruit TSL2591 breakout board based on the Arduino library from Adafruit. python-tsl2591 was developed to work on a Raspberry PI. I then forked it to create a Micropython version. There were two changes from the original:
- Micropython does not provide an smbus api, so smbus was emulated on top of the lower-level I2C library it does provide.
- The ESP8266 and other chips are severely memory limited. With the Raspberry Pi version, even importing the tsl2591 module caused it to run out of memory on the ESP8266. The code was simplified were possible and all the comments stripped out.
Coming soon...
Just copy tsl2591.py to your micropython board. Micropython's webrepl has experimental support for copying files. I instead used the mpfshell to copy files to my ESP8266 board.
import tsl2591
tsl = tsl2591.Tsl2591() # initialize
full, ir = tsl.get_full_luminosity() # read raw values (full spectrum and ir spectrum)
lux = tsl.calculate_lux(full, ir) # convert raw values to lux
print lux, full, ir
Python files in this repository are released under the MIT license.