Beaglebone and TSL2561 Luminosity Sensor example


In this article we look at an TSL2561 connected to a Beaglebone first of all lets look at the sensor.

The TSL2561 is a light-to-digital converter that transforms light intensity to a digital signal output capable of an I2C interface. Each device combines one broadband photodiode (visible plus infrared) and one infrared-responding photodiode on a single CMOS integrated circuit capable of providing a near photopic response over an effective 20-bit dynamic range (16-bit resolution).

Two integrating ADCs convert the photodiode currents to 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 TSL2561 device supports a traditional level style interrupt that remains asserted until the firmware clears it


Patented dual-diode architecture
1M:1 dynamic range
Programmable interrupt function
I²C digital interface
Available in 1.25mm x 1.75mm chip-scale or 2.6mm x 3.8mm TMB or 2mm x 2mm Dual Flat no-lead (FN) packages


Enables operation in IR light environments
Enables dark room to high lux sunlight operation
Reduces microprocessor interrupt overhead
Digital interface is less susceptible to noise
Reduces board space requirements while simplifying designs


Parts Required


Name Link
Beaglebone BeagleBone Black TI AM3358 Cortex-A8 development BB-Black Rev.C
TSL2561 TSL2561 Luminosity Sensor Breakout infrared Light Sensor module integrating sensor AL
Connecting wire Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire


beaglebone and TSL2561
beaglebone and TSL2561

Code Example

This is a controleverything example – they have code examples for various platforms. This is the C example from

#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
void main() 
	// Create I2C bus
	int file;
	char *bus = "/dev/i2c-2";
	if((file = open(bus, O_RDWR)) < 0) 
		printf("Failed to open the bus. \n");
	// Get I2C device, TSL2561 I2C address is 0x39(57)
	ioctl(file, I2C_SLAVE, 0x39);
	// Select control register(0x00 | 0x80)
	// Power ON mode(0x03)
	char config[2] = {0};
	config[0] = 0x00 | 0x80;
	config[1] = 0x03;
	write(file, config, 2);
	// Select timing register(0x01 | 0x80)
	// Nominal integration time = 402ms(0x02)
	config[0] = 0x01 | 0x80;
	config[1] = 0x02;
	write(file, config, 2);
	// Read 4 bytes of data from register(0x0C | 0x80)
	// ch0 lsb, ch0 msb, ch1 lsb, ch1 msb
	char reg[1] = {0x0C | 0x80};
	write(file, reg, 1);
	char data[4] = {0};
	if(read(file, data, 4) != 4)
		printf("Erorr : Input/output Erorr \n");
		// Convert the data
		float ch0 = (data[1] * 256 + data[0]);
		float ch1 = (data[3] * 256 + data[2]);
		// Output data to screen
		printf("Full Spectrum(IR + Visible) : %.2f lux \n", ch0);
		printf("Infrared Value : %.2f lux \n", ch1);
		printf("Visible Value : %.2f lux \n", (ch0 - ch1));

Save this as TSL2561.c, I used the Cloud 9 IDE

First of all compile the c program.

$>gcc TSL2561.c -o TSL2561

Run the c program.




After running you should see something like this

Full Spectrum(IR + Visible) : 591.00 lux
Infrared Value : 493.00 lux
Visible Value : 98.00 lux

Up to 39% on Arduino &amp; DIY Modules


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.