Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

COLOR SENSOR - TCS3471 IC

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051
View previous topic :: View next topic  
Author Message
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Wed Jan 16, 2013 8:42 am    Post subject: COLOR SENSOR - TCS3471 IC Reply with quote

Hi 8051 gurus,

I am a hobbyist and working on my new project which is color sensing device. I got the color sensor module from our shop - TCS3471. I'll include here the schematic and datasheet of the IC. Here's the site were you can download the said module

http://www.e-gizmo.com/KIT/COLOR%20SENSOR.html

This is my first time to deal with I2C that is why im asking for help how to get data from this module if you can add sample code in a very simple way will be super much appreciated.

I just want to read two colors yellow and green


I hope you can help me here people.. Thank you so much!

_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Fri Jan 18, 2013 5:17 pm    Post subject: Reply with quote

Hi,
I never used the 8051 only Bascom-avr
so I did download demo version for test
seems like it can compile it ok

you have to setup the mcu xtal and pins for SDA SCL I dont know howto in 8051

something like this but check in help there is more info about I2C:
Code:

' config I2C bus
Config Scl = P3.6
' I2C Clock
Config Sda = P3.7
' I2C Data


but think you can use some of the info in the code

the code init TCS3471

then it can read the RGBC

the read is low high byte of the color and it make a word from the 2 bytes

I did use address H14 to read all (start with Clear) but you can use address pr datasheet for the R G B C
see datasheet for RGBC Channel Data Registers (0x14 − 0x1B)

this I hope will work for the TCS3471

Code:
' datasheet
'http://www.ams.com/eng/content/download/250256/975981/142695



Const Tcs3471w = &H52
Const Tcs3471r = &H53

Declare Sub Rgb_init()
Declare Sub Rgbc_read()

Dim Light As Word
Dim Clear_l As Byte
Dim Clear_h As Byte

Dim Red As Word
Dim Red_l As Byte
Dim Red_h As Byte

Dim Green As Word
Dim Green_l As Byte
Dim Green_h As Byte

Dim Blue As Word
Dim Blue_l As Byte
Dim Blue_h As Byte

Dim A As Byte

Call Rgb_init

Do
Call Rgbc_read

'add you'r code here
' Tcs3471 Vars value
'Light (clear)
'Red
'Green
'Blue
Loop
End

'Datasheet
'Table 1. Register Address
'Table 2. Command Register
'Table 3. Command Register
'init TCS3471
Sub Rgb_init()
   I2cstart
   I2cwbyte Tcs3471w
   I2cwbyte &B10100000
   I2cstop
   Waitms 10
   I2cstart
   I2cwbyte Tcs3471w
   I2cwbyte 0
   I2cwbyte &B00001001
   I2cstop
   Waitms 10
   I2cstart
   I2cwbyte Tcs3471w
   I2cwbyte 0
   I2cwbyte &B00001011
   I2cstop
   Waitms 10
End Sub

'Datasheet Table 12. ADC Channel Data Registers
Sub Rgbc_read()
   I2cstart
   I2cwbyte Tcs3471w
   I2cwbyte &H14
   I2cstart
   I2cwbyte Tcs3471r
   I2crbyte Clear_l , Ack                                   'Clear low
   I2crbyte Clear_h , Ack                                   'Clear high
   I2crbyte Red_l , Ack                                     'red high
   I2crbyte Red_h , Ack                                     'red low
   I2crbyte Green_l , Ack                                   'green high
   I2crbyte Green_h , Ack                                   'green low
   I2crbyte Blue_l , Ack                                    'blue high
   I2crbyte Blue_h , Nack                                   'blue low
   I2cstop

   Light = Makeint(clear_l , Clear_h)                       ' make word from low - high
   Red = Makeint(red_l , Red_h)
   Green = Makeint(green_l , Green_h)
   Blue = Makeint(blue_l , Blue_h)
End Sub

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Sat Jan 19, 2013 3:19 am    Post subject: Reply with quote

Thanks kimni.. I will test the code later and i will post it here any details i will get. Again thank you so much for the support... Wink
_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Mon Feb 04, 2013 2:48 am    Post subject: Reply with quote

Good Day Sir,,

After several test.. i find nothing ;( i think my code is wrong... heres the whole code you send me plus i included my little code to display on LCD the values of RGB...


Please Help... Thank you so much




$large
$crystal = 11059200


Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = P0.5 , Db5 = P0.4 , Db6 = P0.3 , Db7 = P0.2
Config Lcdpin = Pin , Rs = P0.0 , E = P0.1
'LCD INITIALIZATIONS
Lcdinit
Wait 2
Display On




' config I2C bus
Config Scl = P2.0
' I2C Clock
Config Sda = P2.1
' I2C Data





Const Tcs3471w = &H52
Const Tcs3471r = &H53

Declare Sub Rgb_init()
Declare Sub Rgbc_read()

Dim Light As Word
Dim Clear_l As Byte
Dim Clear_h As Byte

Dim Red As Word
Dim Red_l As Byte
Dim Red_h As Byte

Dim Green As Word
Dim Green_l As Byte
Dim Green_h As Byte

Dim Blue As Word
Dim Blue_l As Byte
Dim Blue_h As Byte

Dim A As Byte

Call Rgb_init

Do
Call Rgbc_read

Locate 1 , 1 : Lcd Red
Locate 1 , 7 : Lcd Blue
Locate 2 , 1 : Lcd Green
Wait 3


'add you'r code here
' Tcs3471 Vars value
'Light (clear)
'Red
'Green
'Blue
Loop


End

'Datasheet
'Table 1. Register Address
'Table 2. Command Register
'Table 3. Command Register
'init TCS3471
Sub Rgb_init()
I2cstart
I2cwbyte Tcs3471w
I2cwbyte &B10100000
I2cstop
Waitms 10
I2cstart
I2cwbyte Tcs3471w
I2cwbyte 0
I2cwbyte &B00001001
I2cstop
Waitms 10
I2cstart
I2cwbyte Tcs3471w
I2cwbyte 0
I2cwbyte &B00001011
I2cstop
Waitms 10
End Sub

'Datasheet Table 12. ADC Channel Data Registers
Sub Rgbc_read()
I2cstart
I2cwbyte Tcs3471w
I2cwbyte &H14
I2cstart
I2cwbyte Tcs3471r
I2crbyte Clear_l , Ack 'Clear low
I2crbyte Clear_h , Ack 'Clear high
I2crbyte Red_l , Ack 'red high
I2crbyte Red_h , Ack 'red low
I2crbyte Green_l , Ack 'green high
I2crbyte Green_h , Ack 'green low
I2crbyte Blue_l , Ack 'blue high
I2crbyte Blue_h , Nack 'blue low
I2cstop

Light = Makeint(clear_l , Clear_h) ' make word from low - high
Red = Makeint(red_l , Red_h)
Green = Makeint(green_l , Green_h)
Blue = Makeint(blue_l , Blue_h)
End Sub

_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Mon Feb 04, 2013 6:51 am    Post subject: Reply with quote

Hi
dont know chip model
they use 2 address

try
Const Tcs3471w = &H72
Const Tcs3471r = &H73

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Tue Feb 05, 2013 12:50 am    Post subject: Reply with quote

i also tried it but nothing happen Sad in the datasheet i found address, attached in this thread to help you sir).
i also found an interrupt pin.. whats the use of this sir??

_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Feb 05, 2013 3:14 am    Post subject: Reply with quote

Hi,
we can add read Chip ID for a test
then you know if I2C is working
and of cause you run 8051 at 3.3V max

Code:

$large
$crystal = 11059200
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = P0.5 , Db5 = P0.4 , Db6 = P0.3 , Db7 = P0.2
Config Lcdpin = Pin , Rs = P0.0 , E = P0.1
'LCD INITIALIZATIONS
Lcdinit
Wait 2
Display On
' config I2C bus
Config Scl = P2.0
' I2C Clock
Config Sda = P2.1
' I2C Data
Config I2cdelay = 20
Const Tcs3471w = &H52
Const Tcs3471r = &H53

Declare Sub Id()
Dim Id_chip As Byte

' check chip ID   0x14 = TCS34711 & TCS34715  0x1D = TCS34713 & TCS34717
Do
Call Id
Locate 1 , 1
Lcd Id_chip

Locate 2 , 1
If Id_chip = &H14 Then
   Lcd "TCS34711/15"
Elseif Id_chip = &H1D Then
   Lcd "TCS34713/17"
Else
   Lcd "ERROR READ"
End If
Wait 2
Cls
Loop
End

Sub Id()
I2cstart
I2cwbyte Tcs3471w
I2cwbyte &H12
I2cstart
I2cwbyte Tcs3471r
I2crbyte Id_chip , 9
End Sub

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Tue Feb 05, 2013 4:22 am    Post subject: Reply with quote

THIS IS THE DISPLAY SIR:



'--------------------------
18
ERROR READ
'---------------------------


tHANKS FOR THE HELP

_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Feb 05, 2013 5:11 pm    Post subject: Reply with quote

try change Config I2cdelay = 1
chip can handle 400khz

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
danilomayojr

Bascom Member



Joined: 17 Feb 2010
Posts: 36
Location: San Fernando City

philippines.gif
PostPosted: Fri Feb 08, 2013 3:03 am    Post subject: Reply with quote

Sir,

After changing Config I2cdelay = 1


display is this

---------------------------
79
error read
--------------------------

_________________
Danilo Mayo Jr.
Back to top
View user's profile Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum