In this article we connect a TSL2591 light-to-digital converter to a Raspberry Pi Pico running Circuitpython
Sensor Information
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.
Features
- 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 Required
Name | Link |
Pico | Raspberry Pi Pico Development Board |
TSL2591 | TSL2591 High Dynamic Range Digital Light Sensor Module |
Connecting cables | Aliexpress product link |
Schematic/Connection
I used the Adafruit TSL2591 sensor
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
So color coded for ease of use, this layout shows a connection to the module
Code Example
I used Thonny for development
The following is based on a library , I copied the adafruit_tsl2591.mpy library for this device to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries
This is the basic example which comes with the library
[codesyntax lang=”python”]
import time import board import adafruit_tsl2591 import busio # Create sensor object, communicating over the board's default I2C bus i2c = busio.I2C(scl=board.GP1, sda=board.GP0) # uses board.SCL and board.SDA # Initialize the sensor. sensor = adafruit_tsl2591.TSL2591(i2c) # You can optionally change the gain and integration time: # sensor.gain = adafruit_tsl2591.GAIN_LOW (1x gain) # sensor.gain = adafruit_tsl2591.GAIN_MED (25x gain, the default) # sensor.gain = adafruit_tsl2591.GAIN_HIGH (428x gain) # sensor.gain = adafruit_tsl2591.GAIN_MAX (9876x gain) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_100MS (100ms, default) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_200MS (200ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_300MS (300ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_400MS (400ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_500MS (500ms) # sensor.integration_time = adafruit_tsl2591.INTEGRATIONTIME_600MS (600ms) # 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)) time.sleep(1.0)
[/codesyntax]
Output
Here is what I saw in Thonny REPL window
Total light: 18.9704lux
Infrared light: 109
Visible light: 7143610
Full spectrum (IR + visible) light: 7143719
Total light: 19.1923lux
Infrared light: 110
Visible light: 7209148
Full spectrum (IR + visible) light: 7209258
Total light: 24.4931lux
Infrared light: 128
Visible light: 8388840
Full spectrum (IR + visible) light: 8388968
Total light: 35.3491lux
Infrared light: 160
Visible light: 10486079
Full spectrum (IR + visible) light: 10486239