Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:00 23 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : TCS3472

Author Message
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 06:53am 17 Aug 2015
Copy link to clipboard 
Print this post

Has anyone ever made a uM talk to a TCS3472 or TCS3490 light sensor? I have been trying the whole day, but the damn thing always returns 0 on the i2c bus no matter what I try (ah, my favourite old enemy - the i2c bus...). The hardware is fairly standard, and yes, I do have pull-ups on the i2c lines :)
I think I am not doing something right on the software side.
Thanks for any help!
Edited by kiiid 2015-08-18
http://rittle.org

--------------
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6274
Posted: 01:23pm 17 Aug 2015
Copy link to clipboard 
Print this post

It's 18 months since I played with a similar unit:

'TCS3414CS digital color sensor

COLOR_SENSOR_ADDR = &h39'the I2C address for the color sensor
REG_CTL= &h80
REG_TIMING= &h81
REG_INT= &h82
REG_INT_SOURCE= &h83
REG_ID= &h84
REG_GAIN= &h87
REG_LOW_THRESH_LOW_BYTE= &h88
REG_LOW_THRESH_HIGH_BYTE= &h89
REG_HIGH_THRESH_LOW_BYTE= &h8A
REG_HIGH_THRESH_HIGH_BYTE= &h8B
REG_BLOCK_READ= &hCF
REG_GREEN_LOW= &hD0
REG_GREEN_HIGH= &hD1
REG_RED_LOW= &hD2
REG_RED_HIGH= &hD3
REG_BLUE_LOW= &hD4
REG_BLUE_HIGH= &hD5
REG_CLEAR_LOW= &hD6
REG_CLEAR_HIGH= &hD7
CTL_DAT_INIITIATE= &h03
CLR_INT= &hE0
'Timing Register
SYNC_EDGE= &h40
INTEG_MODE_FREE= &h00
INTEG_MODE_MANUAL= &h10
INTEG_MODE_SYN_SINGLE= &h20
INTEG_MODE_SYN_MULTI= &h30

INTEG_PARAM_PULSE_COUNT1= &h00
INTEG_PARAM_PULSE_COUNT2= &h01
INTEG_PARAM_PULSE_COUNT4= &h02
INTEG_PARAM_PULSE_COUNT8= &h03
'Interrupt Control Register
INTR_STOP = 40
INTR_DISABLE= &h00
INTR_LEVEL= &h10
INTR_PERSIST_EVERY= &h00
INTR_PERSIST_SINGLE= &h01
'Interrupt Souce Register
INT_SOURCE_GREEN= &h00
INT_SOURCE_RED= &h01
INT_SOURCE_BLUE= &h10
INT_SOURCE_CLEAR= &h03
'Gain Register
GAIN_1= &h00
GAIN_4= &h10
GAIN_16= &h20
GANI_64= &h30
PRESCALER_1= &h00
PRESCALER_2= &h01
PRESCALER_4= &h02
PRESCALER_8= &h03
PRESCALER_16= &h04
PRESCALER_32= &h05
PRESCALER_64= &h06

dim readingdata(20)
I2C open 400, 200
r=setTimingReg(INTEG_MODE_FREE) 'Set trigger mode.Including free mode,manually mode,single synchronizition mode or so.
r=setInterruptSourceReg(INT_SOURCE_GREEN) 'Set interrupt source
r=setInterruptControlReg(INTR_LEVEL or INTR_PERSIST_EVERY) 'Set interrupt mode
r=setGain(GAIN_4 or PRESCALER_1) 'Set gain value and prescaler value
r=setEnableADC() 'Start ADC of the color sensor

mainLoop:
do
r= readRGB()
r =calculateCoordinate()
pause(5000)
r=clearInterrupt()
loop
end

function setTimingReg(x)
I2C write COLOR_SENSOR_ADDR, 0, 2, REG_TIMING, x
pause(100)
end function

function setInterruptSourceReg(x)
I2C write COLOR_SENSOR_ADDR, 0, 2, REG_INT_SOURCE, x
pause(100)
end function

function setInterruptControlReg(x)
I2C write COLOR_SENSOR_ADDR, 0, 2, REG_INT, x
pause(100)
end function

function setGain(x)
I2C write COLOR_SENSOR_ADDR, 0, 2, REG_GAIN, x
end function

function setEnableADC()
I2C write COLOR_SENSOR_ADDR, 0, 2, REG_CTL, CTL_DAT_INIITIATE
pause(100)
end function

function clearInterrupt()
I2C write COLOR_SENSOR_ADDR, 0, 1, CLR_INT
end function

function readRGB()
I2C write COLOR_SENSOR_ADDR, 0, 1, REG_BLOCK_READ
pause(500)
I2C read COLOR_SENSOR_ADDR, 0, 8, readingdata(0)
green=readingdata(1)*256+readingdata(0)
red=readingdata(3)*256+readingdata(2)
blue=readingdata(5)*256+readingdata(4)
clr=readingdata(7)*256+readingdata(6)
print "The RGB value and Clear channel value are"
print red
print green
print blue
print clr
end function

function calculateCoordinate()
X=(-0.14282)*red+(1.54924)*green+(-0.95641)*blue
Y=(-0.32466)*red+(1.57837)*green+(-0.73191)*blue
Z=(-0.68202)*red+(0.77073)*green+(0.56332)*blue
xa=X/(X+Y+Z)
ya=Y/(X+Y+Z)
if((X>0)and(Y>0) and (Z>0)) then
print "The x,y value is"
print "("+str$(xa,0,2)+ " , "+str$(ya,0,2)+")"
print "Please reference the figure(Chromaticity Diagram) in the wiki "
print "so as to get the recommended color."
else
print "Error,the values overflow"
endif
end function


It might be of help.

Jim
VK7JH
MMedit
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 08:40pm 17 Aug 2015
Copy link to clipboard 
Print this post

Thanks Jim, I will have a look at your code.


http://rittle.org

--------------
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025