This module is based on the I2C light-to-digital converter TSL2561 to transform light intensity to a digital signal. Different from traditional analog light sensor, as Grove - Light Sensor, this digital module features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum.
You can switch between three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode. When running under the human visible mode, this sensor will give you readings just close to your eye feelings.
Features
Selectable detection modes
high resolution 16-Bit digital output at 400 kHz I2C Fast-Mode
Wide dynamic range: 0.1 - 40,000 LUX
Wide operating temperature range: -40°C to 85°C
Programmable interrupt function with User-Defined Upper and lower threshold settings
Application Ideas
Ambient light sensing
Backlighting control for display panel
Keyboard illumination control
For all Grove users (especially beginners), we provide you guidance PDF documents. Please download and read through Preface - Getting Started and Introduction to Grove before your using of the product.
From:For more detail, please visit: http://www.seeedstudio.com/item_detail.html?p_id=1281
Introduction
This module is based on the I2C light-to-digital converter TSL2561 to transform light intensity to a digital signal. Different from traditional analog light sensor, as Grove - Light Sensor, this digital module features a selectable light spectrum range due to its dual light sensitive diodes: infrared and full spectrum.
You can switch among three detection modes to take your readings. They are infrared mode, full spectrum and human visible mode. When running under the human visible mode, this sensor will give you readings just close to your eye feelings.
![enter image description here][1]
Features
Selectable detection modes
High resolution 16-Bit digital output at 400 kHz I2C Fast-Mode
Wide dynamic range: 0.1 - 40,000 LUX
Wide operating temperature range: -40°C to 85°C
Programmable interrupt function with User-Defined Upper and lower threshold settings.
Specifications
Items Min Type Max Unit
Supply voltage, VDD 3.3 5 5.1 V
Operating temperature -30 \ 70 ℃
SCL,SDA input low voltage -0.5 \ 0.8 V
SCL,SDA input high voltage 2.3 \ 5.1 V
Interface Function
![enter image description here][2]
U1: TSL2561 IC, Light-To-Digital Converter.
U3: XC6206MR332 IC, Positive Voltage Regulators.
Q1,Q2: BSN20 IC, N-channel Enhancement Mode Vertical D-MOS Transistor.
SCL,SDA: I2C Signal Interface
TSL2561 Functional Block Diagram
![enter image description here][3]
With Arduino
1. Plug the Grove - Digital Light Sensor onto the I2C port on Grove - Base Shield, and then plug the base shield onto Arduino;
![enter image description here][4]
2. Download the library from here Digital Light Sensor Library;
3. Unzip it into the libraries file of Arduino IDE by the path: ..\arduino-1.0.1\libraries.
4. Create an Arduino sketch and paste the following codes to it or open the code directly by the path:File -> Example ->Digital_Light_Sensor->Digital_Light_Sensor.
/*
* Digital_Light_Sensor.ino
* A library for TSL2561
*
* Copyright (c) 2012 seeed technology inc.
* Website : www.seeed.cc
* Author : zhangkun
* Create Time:
* Change Log :
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include
#include
void setup()
{
Wire.begin();
Serial.begin(9600);
TSL2561.init();
}
void loop()
{
Serial.print("The Light value is: ");
Serial.println(TSL2561.readVisibleLux());
delay(1000);
}
5. Upload the code. Please click here if you do not know how to upload.
6. Open the serial monitor to see the result.
Digital Light Sensor Score Picture.jpg
In the case of completely light matte, The output result is 0.
With Raspberry Pi
1.You should have got a raspberry pi and a grovepi or grovepi+.
2.You should have completed configuring the development enviroment, otherwise follow here.
3.Connection
Plug Digital Light Sensor to the I2C sockets on grovepi.
4.Navigate to the demos' directory:
cd yourpath/GrovePi/Software/Python/grove_i2c_digital_light_sensor/
To see the code
nano grove_i2c_digital_light_sensor.py # "Ctrl+x" to exit #
import time
import smbus
from Adafruit_I2C import Adafruit_I2C
import RPi.GPIO as GPIO
import grovepi
from smbus import SMBus
global I2C_ADDRESS
global I2C_SMBUS
global _CMD
global _CMD_CLEAR
global _CMD_WORD
global _CMD_BLOCK
global _REG_CONTROL
global _REG_TIMING
global _REG_ID
global _REG_BLOCKREAD
global _REG_DATA0
global _REG_DATA1
global _POWER_UP
global _POWER_DOWN
global _GAIN_LOW
global _GAIN_HIGH
global _INTEGRATION_START
global _INTEGRATION_STOP
global _INTEGRATE_13
global _INTEGRATE_101
global _INTEGRATE_402
global _INTEGRATE_DEFAULT
global _INTEGRATE_NA
global _GAIN
global _MANUAL
global _INTEG
global _CHANNEL0
global _CHANNEL1
global _D0
global _D1
global _LUX
# bus parameters
rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
I2C_SMBUS = smbus.SMBus(1)
else:
I2C_SMBUS = smbus.SMBus(0)
# Default I2C address
I2C_ADDRESS = 0x29
# Commands
_CMD = 0x80
_CMD_CLEAR = 0x40
_CMD_WORD = 0x20
_CMD_BLOCK = 0x10
# Registers
_REG_CONTROL = 0x00
_REG_TIMING = 0x01
_REG_ID = 0x0A
_REG_BLOCKREAD = 0x0B
_REG_DATA0 = 0x0C
_REG_DATA1 = 0x0E
# Control parameters
_POWER_UP = 0x03
_POWER_DOWN = 0x00
# Timing parameters
_GAIN_LOW = 0b00000000
_GAIN_HIGH = 0b00010000
_INTEGRATION_START = 0b00001000
_INTEGRATION_STOP = 0b00000000
_INTEGRATE_13 = 0b00000000
_INTEGRATE_101 = 0b00000001
_INTEGRATE_402 = 0b00000010
_INTEGRATE_DEFAULT = _INTEGRATE_402
_INTEGRATE_NA = 0b00000011
# Testing parameters
ambient = None
IR = None
_ambient = 0
_IR = 0
_LUX = None
class Tsl2561(object):
i2c = None
def _init__(self, bus = I2C_SMBUS, addr = I2C_ADDRESS, debug = 1, pause = 0.8): # set debug = 0 stops debugging output on screen
assert(bus is not None)
assert(addr > 0b000111 and addr = 65535 or IR >= 65535): # Value(s) exeed(s) datarange
self.setGain(1) # Set lowGain
ambient = self.readFull()
IR = self.readIR()
# If either sensor is saturated, no acculate lux value can be achieved.
if (ambient == 0xffff or IR == 0xffff):
self._LUX = None
self._ambient = None
self._IR = None
return (self.ambient, self.IR, self._ambient, self._IR, self._LUX)
if (self.gain == 1):
self._ambient = 16 * ambient # Scale 1x to 16x
self._IR = 16 * IR # Scale 1x to 16x
else:
self._ambient = 1 * ambient
self._IR = 1 * IR
if (self.debug):
print "IR Result without scaling: ", IR
print "IR Result: ", self._IR
print "Ambient Result without scaling: ", ambient
print "Ambient Result: ", self._ambient
if (self._ambient == 0):
# Sometimes, the channel 0 returns 0 when dark ...
self._LUX = 0.0
return (ambient, IR, self._ambient, self._IR, self._LUX)
ratio = (self._IR / float(self._ambient)) # Change to make it run under python 2
if (self.debug):
print "ratio: ", ratio
if ((ratio >= 0) and (ratio