Home Circuitpython Adafruit Feather M0 and TSL2591 light-to-digital converter circuitpython example

Adafruit Feather M0 and TSL2591 light-to-digital converter circuitpython example

by shedboy71

In this example we connect a TSL2591 light-to-digital converter to an Adafruit Feather M0 running Circuitpython

The TSL2591 is a very high sensitivity light-to-digital converter that transforms light intensity into a digital signal output capable of direct I2C interface. The device combines one broadband photodiode (visible plus infrared) and one infrared-responding photodiode on a single CMOS integrated circuit. Two integrating ADCs convert the photodiode currents into a digital output that represents the irradiance measured on each channel.

This digital output can be input to a microprocessor where illuminance (ambient light level) in lux is derived using an empirical formula to approximate the human eye response. The TSL2591 supports a traditional level style interrupt that remains asserted until the firmware clears it.


  • Highest sensitivity to 188µLux
  • Patented dual-diode architecture
  • 600M:1 dynamic range
  • Programmable interrupt function
  • UV-rejection package

Product parameters

Supply Voltage [V] 2.7 – 3.6
Interface I2C – VDD
Programmable Gain, integration time, interrupt
Max. Lux 88000
Temperature Range [°C] -30 to 70


This is the sensor I purchased, link below

Parts List


Name Link
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
TSL2591 TSL2591 Optical Light Sensor Development Board
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



feather and tsl2591

feather and tsl2591



I used Mu for development as per Adafruit’s advice

The following is based on a library , I copied the TSL2591 library to the lib folder to my Feather M0 Express – https://circuitpython.org/libraries

# Simple demo of the TSL2591 sensor.  Will print the detected light value
# every second.
import time
import board
import busio
import adafruit_tsl2591
# Initialize the I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Initialize the sensor.
sensor = adafruit_tsl2591.TSL2591(i2c)
# Read the total lux, IR, and visible light levels and print it every second.
while True:
    # Read and calculate the light level in lux.
    lux = sensor.lux
    print("Total light: {0}lux".format(lux))
    # You can also read the raw infrared and visible light levels.
    # These are unsigned, the higher the number the more light of that type.
    # There are no units like lux.
    # Infrared levels range from 0-65535 (16-bit)
    infrared = sensor.infrared
    print("Infrared light: {0}".format(infrared))
    # Visible-only levels range from 0-2147483647 (32-bit)
    visible = sensor.visible
    print("Visible light: {0}".format(visible))
    # Full spectrum (visible + IR) also range from 0-2147483647 (32-bit)
    full_spectrum = sensor.full_spectrum
    print("Full spectrum (IR + visible) light: {0}".format(full_spectrum))



Here is what I saw in Mu REPL window

Total light: 1.18157lux

Infrared light: 9

Visible light: 589837

Full spectrum (IR + visible) light: 589846

Total light: 1.01837lux

Infrared light: 9

Visible light: 589836

Full spectrum (IR + visible) light: 589845




You may also like

Leave a Comment