TSL2561 - Senzor suncevog zracenja, vidljivi i infra-crveni opseg

Proizvodjač: TAOS - Texas Advanced Optoelectronic Solutions Inc. (The LUMENOLOGY Company)
Napon napajanja: 2.7...3.6 V
Izlazni signal: I2C interface
Opseg merenja: vidljiv λp=640 nm, IR infra-crveni λp=940 nm, 0...200000 lux
Rezolucija merenja: 0.1 lux
Period merenja: 13.7...402 ms


Lemljenjem pina ADDR (2) na L (GND), dobijamo adresu 0x29.
Software in C++ for Raspberry Pi
//****************************************************************************
// Calculate values - SOLAR - Sunce
//****************************************************************************
#define solar_const    126.58	// ??? 1lux = 0.0079W/m2 => 1/0.0079=126.58

//****************************************************************************
// Calibration values - TSL2561
//**************************************************************************** 
#define LUX_SCALE    14         // scale by 2^14
#define RATIO_SCALE  9          // scale ratio by 2^9
//---------------------------------------------------
// Integration time scaling factors
//---------------------------------------------------
#define CH_SCALE 10             // scale channel values by 2^10
#define CHSCALE_TINT0 0x7517    // 322/11 * 2^CH_SCALE
#define CHSCALE_TINT1 0x0fe7    // 322/81 * 2^CH_SCALE
//---------------------------------------------------
// T, FN, and CL Package coefficients
//---------------------------------------------------
// For Ch1/Ch0=0.00 to 0.50
// Lux/Ch0=0.0304-0.062*((Ch1/Ch0)^1.4)
// piecewise approximation
// For Ch1/Ch0=0.00 to 0.125:
// Lux/Ch0=0.0304-0.0272*(Ch1/Ch0)
//
// For Ch1/Ch0=0.125 to 0.250:
// Lux/Ch0=0.0325-0.0440*(Ch1/Ch0)
//
// For Ch1/Ch0=0.250 to 0.375:
// Lux/Ch0=0.0351-0.0544*(Ch1/Ch0)
//
// For Ch1/Ch0=0.375 to 0.50:
// Lux/Ch0=0.0381-0.0624*(Ch1/Ch0)
//
// For Ch1/Ch0=0.50 to 0.61:
// Lux/Ch0=0.0224-0.031*(Ch1/Ch0)
//
// For Ch1/Ch0=0.61 to 0.80:
// Lux/Ch0=0.0128-0.0153*(Ch1/Ch0)
//
// For Ch1/Ch0=0.80 to 1.30:
// Lux/Ch0=0.00146-0.00112*(Ch1/Ch0)
//
// For Ch1/Ch0>1.3:
// Lux/Ch0=0
//---------------------------------------------------
#define K1T 0x0040      // 0.125   * 2^RATIO_SCALE
#define B1T 0x01f2      // 0.0304  * 2^LUX_SCALE
#define M1T 0x01be      // 0.0272  * 2^LUX_SCALE
#define K2T 0x0080      // 0.250   * 2^RATIO_SCALE
#define B2T 0x0214      // 0.0325  * 2^LUX_SCALE
#define M2T 0x02d1      // 0.0440  * 2^LUX_SCALE
#define K3T 0x00c0      // 0.375   * 2^RATIO_SCALE
#define B3T 0x023f      // 0.0351  * 2^LUX_SCALE
#define M3T 0x037b      // 0.0544  * 2^LUX_SCALE
#define K4T 0x0100      // 0.50    * 2^RATIO_SCALE
#define B4T 0x0270      // 0.0381  * 2^LUX_SCALE
#define M4T 0x03fe      // 0.0624  * 2^LUX_SCALE
#define K5T 0x0138      // 0.61    * 2^RATIO_SCALE
#define B5T 0x016f      // 0.0224  * 2^LUX_SCALE
#define M5T 0x01fc      // 0.0310  * 2^LUX_SCALE
#define K6T 0x019a      // 0.80    * 2^RATIO_SCALE
#define B6T 0x00d2      // 0.0128  * 2^LUX_SCALE
#define M6T 0x00fb      // 0.0153  * 2^LUX_SCALE
#define K7T 0x029a      // 1.3     * 2^RATIO_SCALE
#define B7T 0x0018      // 0.00146 * 2^LUX_SCALE
#define M7T 0x0012      // 0.00112 * 2^LUX_SCALE
#define K8T 0x029a      // 1.3     * 2^RATIO_SCALE
#define B8T 0x0000      // 0.000   * 2^LUX_SCALE
#define M8T 0x0000      // 0.000   * 2^LUX_SCALE

//----------------------------------------------------------------------
...
// ----- Suncevo zracenje (lux, W/m2)
		s0 = hex_val2(buf[28],buf[29],buf[30],buf[31]);
		s1 = hex_val2(buf[32],buf[33],buf[34],buf[35]);
		s = CalculateLux(1,2,s0,s1);	// (lux)
		sw = s / solar_const;	// (W/m2)
		printf("%dlux %4.1fW/m2 ", s, sw);
...

//----------------------------------------------------------------------
unsigned int CalculateLux(unsigned int iGain, unsigned int tInt, unsigned int ch0, unsigned int ch1)
{
        //------------------------------------------------------------------------
        // first, scale the channel values depending on the gain and integration time
        // 16x, 402mS is nominal.
        // scale if integration time is NOT 402 msec
        unsigned long chScale;
        unsigned long channel1;
        unsigned long channel0;

//        chScale = CHSCALE_TINT1;

		switch (tInt)
		{
			case 0: // 13.7 msec
				chScale = CHSCALE_TINT0;
				break;
			case 1: // 101 msec
				chScale = CHSCALE_TINT1;
				break;
			default: // assume no scaling
				chScale = (1 << CH_SCALE);
			break;
		}
        // scale if gain is NOT 16X
        if (!iGain) chScale = chScale << 4; // scale 1X to 16X

        // scale the channel values
        channel0 = (ch0 * chScale) >> CH_SCALE;
        channel1 = (ch1 * chScale) >> CH_SCALE;
        //------------------------------------------------------------------------

        // find the ratio of the channel values (Channel1/Channel0)
        // protect against divide by zero
        unsigned long ratio1 = 0;
        if (channel0 != 0) ratio1 = (channel1 << (RATIO_SCALE+1)) / channel0;

        // round the ratio value
        unsigned long ratio = (ratio1 + 1) >> 1;
        // is ratio <= eachBreak ?
        unsigned int b, m;

// T, FN and CL package
        if ((ratio >= 0) && (ratio <= K1T))
                {b=B1T; m=M1T;}
        else if (ratio <= K2T)
                {b=B2T; m=M2T;}
        else if (ratio <= K3T)
                {b=B3T; m=M3T;}
        else if (ratio <= K4T)
                {b=B4T; m=M4T;}
        else if (ratio <= K5T)
                {b=B5T; m=M5T;}
        else if (ratio <= K6T)
                {b=B6T; m=M6T;}
        else if (ratio <= K7T)
                {b=B7T; m=M7T;}
        else if (ratio > K8T)
                {b=B8T; m=M8T;}
        else;

        unsigned long temp;
        temp = ((channel0 * b) - (channel1 * m));

        // do not allow negative lux value
        if (temp < 0) temp = 0;

       // round lsb (2^(LUX_SCALE-1))
        temp += (1 << (LUX_SCALE-1));

        // strip off fractional portion
        unsigned long lux = temp >> LUX_SCALE;

        return(lux);
}
//----------------------------------------------------------------------


Software in Assembler for PIC16F876, rutina se poziva kod starta 
;---------------------------------------------------------------------
;Inicijalizacija TLS2561
Init_TLS2561
	i2c_start
	movlw	0x52		;Module address WR , ADDR=L (0x29)
	call	i2c_send

	movlw	0x80		;command Write address 0x0
	call	i2c_send
 
	movlw	0x03		;Power ON mode, defaults TIMING=0x02 (GAIN=1X, INTEG=402ms)
	call	i2c_send

	i2c_stop
	return
;---------------------------------------------------------------------

Software in Assembler for PIC16F876, rutina se poziva svake sekunde
;---------------------------------------------------------------------
; Citaj podatke TLS2561 - Jacina sunca
TLS2561
	i2c_restart
	movlw	0x52		;Module address WR, ADDR=L (0x29)
	call	i2c_send

	movlw	0xAC		;command, Read Word address 0xC
	call	i2c_send

	i2c_restart
	movlw	0x53		;Module address RD, ADDR=L (0x29)
	call	i2c_send

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 1
	movwf	S0_L

	i2c_receive
	i2c_send_NACK
	movf	SSPBUF,W	;uzmi podatak 2
	movwf	S0_H
	i2c_stop

;- - - - - - - - - - - - - - - - - - - - - - - -
	i2c_restart
	movlw	0x52		;Module address WR, ADDR=L (0x29)
	call	i2c_send

	movlw	0xAE		;command, Read Word address 0xE
	call	i2c_send

	i2c_restart
	movlw	0x53		;Module address RD, ADDR=L (0x29)
	call	i2c_send

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 3
	movwf	S1_L

	i2c_receive
	i2c_send_NACK
	movf	SSPBUF,W	;uzmi podatak 4
	movwf	S1_H

	i2c_stop
	return
;---------------------------------------------------------------------


Download File:
  • tsl2561.py - Python software za testiranje TSL2561
  • Šema RPI WS
  • Šema PIC WS
  • Data Sheet - TSL2561.pdf