WL
11.10.2013, 08:58
Der TSL45315 ist ein Lichtsensor der über I2C die Werte (16Bit) direkt in Lux ausgibt .
Ein Breakout ist bei Watterott erhältlich : http://www.watterott.com/de/TSL45315-Breakout
Das Datenblatt z.B. hier : http://media.digikey.com/pdf/Data%20Sheets/Austriamicrosystems%20PDFs/TSL4531.pdf
'------------------------------------------------------------------------------
'Demo TSL 45315 (DIGITAL AMBIENT LIGHT SENSOR)
'Watterott Breakout > http://www.watterott.com/de/TSL45315-Breakout
'ATMega88
'------------------------------------------------------------------------------
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
Config Sda = Portc.4 ' I2C Data
Config Scl = Portc.5 ' I2C Clock
I2Cinit
'************************************************* *********************
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Initlcd
Cls
Dim adress_w As Byte
adress_w = &H52 'Write Adress
Dim adress_r As Byte
adress_r = &H53 'Read Adress
Dim Lux As Long
Dim Rohdaten As Word
Dim Lsb As Byte at Rohdaten overlay
Dim Msb As Byte at Rohdaten + 1 overlay
Dim Temp$ As String * 32
'_________________________________________________ _____________________________
I2cstart 'Initialisieren
I2cwbyte adress_w
I2cwbyte &H80 'Command Adresse 0 = Control
I2cwbyte &H03 'Control= &H11 = Normal Operation
I2cstart
I2cwbyte adress_w
I2cwbyte &H81 'Command Adresse 1 = Configuration Register
I2cwbyte &H01 'Configuration Register= &H01 = Multiplier x2
I2cstop
Waitms 500 'Multiplier x1=480ms / x2=240ms / x4=120ms
'_________________________________________________ _____________________________
Do
I2cstart
I2cwbyte adress_w 'Daten holen
I2cwbyte &H84 'Command Adresse 4 = Data LOW Register
I2cstart
I2cwbyte adress_r
I2crbyte Lsb , Ack 'LSB und acknowledge
I2crbyte Msb , Ack 'MSB und acknowledge
I2cstop
upperline
Lux = Rohdaten * 2
Temp$ = str(Lux)
lcd Temp$ ; " Lux "
lowerline
Temp$ = str(Rohdaten) + " "
lcd Temp$
Waitms 500 'Multiplier x1=480ms / x2=240ms / x4=120ms
Loop
'_________________________________________________ _____________________________
End
Ein Breakout ist bei Watterott erhältlich : http://www.watterott.com/de/TSL45315-Breakout
Das Datenblatt z.B. hier : http://media.digikey.com/pdf/Data%20Sheets/Austriamicrosystems%20PDFs/TSL4531.pdf
'------------------------------------------------------------------------------
'Demo TSL 45315 (DIGITAL AMBIENT LIGHT SENSOR)
'Watterott Breakout > http://www.watterott.com/de/TSL45315-Breakout
'ATMega88
'------------------------------------------------------------------------------
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
Config Sda = Portc.4 ' I2C Data
Config Scl = Portc.5 ' I2C Clock
I2Cinit
'************************************************* *********************
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Initlcd
Cls
Dim adress_w As Byte
adress_w = &H52 'Write Adress
Dim adress_r As Byte
adress_r = &H53 'Read Adress
Dim Lux As Long
Dim Rohdaten As Word
Dim Lsb As Byte at Rohdaten overlay
Dim Msb As Byte at Rohdaten + 1 overlay
Dim Temp$ As String * 32
'_________________________________________________ _____________________________
I2cstart 'Initialisieren
I2cwbyte adress_w
I2cwbyte &H80 'Command Adresse 0 = Control
I2cwbyte &H03 'Control= &H11 = Normal Operation
I2cstart
I2cwbyte adress_w
I2cwbyte &H81 'Command Adresse 1 = Configuration Register
I2cwbyte &H01 'Configuration Register= &H01 = Multiplier x2
I2cstop
Waitms 500 'Multiplier x1=480ms / x2=240ms / x4=120ms
'_________________________________________________ _____________________________
Do
I2cstart
I2cwbyte adress_w 'Daten holen
I2cwbyte &H84 'Command Adresse 4 = Data LOW Register
I2cstart
I2cwbyte adress_r
I2crbyte Lsb , Ack 'LSB und acknowledge
I2crbyte Msb , Ack 'MSB und acknowledge
I2cstop
upperline
Lux = Rohdaten * 2
Temp$ = str(Lux)
lcd Temp$ ; " Lux "
lowerline
Temp$ = str(Rohdaten) + " "
lcd Temp$
Waitms 500 'Multiplier x1=480ms / x2=240ms / x4=120ms
Loop
'_________________________________________________ _____________________________
End