TCS3200-DB Color Sensor with Prop
John Board
Posts: 371
Howdy,
Sorry if I'm becoming a pain with my continual hunger for knowledge on how to use all these devices. Heres my situation and problem.
Problem:
Using a TCS3200-DB (http://www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/SortField/0/Level/a/ProductID/429/Default.aspx) with the Gadget Gangster Prop board. I've wired everything up as per how it should be:
+5v to 5v
GND to GND
A to 0
B to 1
C to 2
D to 3
E to 4
F to 5
I've be able to turn on the in-built LEDs, however, with my little knowledge of SPIN I haven't been able to get it giving me readings on my LCD screen. Here is the BS2 Example Code:
And here is my code:
Now, I could also paste the LCD Obj and the BASIC Obj.. But I think from the function calls that they are self-explaitory.
I think that is all the info I need to provide, please get back soon!
-John
Sorry if I'm becoming a pain with my continual hunger for knowledge on how to use all these devices. Heres my situation and problem.
Problem:
Using a TCS3200-DB (http://www.parallax.com/Store/Sensors/ColorLight/tabid/175/CategoryID/50/List/0/SortField/0/Level/a/ProductID/429/Default.aspx) with the Gadget Gangster Prop board. I've wired everything up as per how it should be:
+5v to 5v
GND to GND
A to 0
B to 1
C to 2
D to 3
E to 4
F to 5
I've be able to turn on the in-built LEDs, however, with my little knowledge of SPIN I haven't been able to get it giving me readings on my LCD screen. Here is the BS2 Example Code:
' ========================================================================= ' ' File...... TCS3200-DB_demo(DB-Expander).bs2 ' Purpose... To extract color data from the TCS230-DB via the DB-Expander ' Author.... Parallax, Inc. ' E-mail.... support@parallax.com ' Started... 21 January 2010 ' Updated... ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' This program is used to get and output color data from the TCS230-DB ' color sensor daughterboard when connected to a BS2 via the DB-Expander. ' -----[ I/O Definitions ]------------------------------------------------- ' Change the "BS2" pin designators as needed. ' Sig BS2 DB-Expander ' --- --- ----------- S0 PIN 0 ' A S1 PIN 1 ' B OUT PIN 2 ' C LED PIN 3 ' D S2 PIN 4 ' E S3 PIN 5 ' F ' -----[ Constants ]------------------------------------------------------- ' Define count periods for each color. Adjust these for readings just under ' 255 for a white sheet of paper. pRED CON 13 'Red reading period. pGREEN CON 12 'Green reading period. pBLUE CON 11 'Blue reading period. ' -----[ Variables ]------------------------------------------------------- RED VAR Word 'Red color reading. GREEN VAR Word 'Green color reading. BLUE VAR Word 'Blue color reading. ' -----[ Initialization ]-------------------------------------------------- HIGH S0 'Maximum output rate. HIGH S1 ' " HIGH LED 'Turn on LED. ' -----[ Program Code ]---------------------------------------------------- DO GOSUB Color 'Get the color data, and output to DEBUG. DEBUG "R", DEC3 RED DEBUG " G", DEC3 GREEN DEBUG " B", DEC3 BLUE DEBUG CR LOOP ' -----[ Subroutines ]----------------------------------------------------- ' Color: Read all three color components. Color: LOW S2 'Address the red output. LOW S3 COUNT OUT, pRED, RED 'Read the red component. HIGH S3 'Address the blue output. COUNT OUT, pBLUE, BLUE 'Read the blue component. HIGH S2 'Address the green output. COUNT OUT, pGREEN, GREEN 'Read the green component. RETURN
And here is my code:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 S0 = 0 S1 = 1 OUT = 2 LED = 3 S2 = 4 S3 = 5 pRED = 13 pGREEN = 12 pBLUE = 11 OBJ LCD: "JawsLCD.spin" BASIC: "JawsBASIC.spin" VAR long RED long GREEN long BLUE long counter PUB Main LCD.start(9,1,0) init repeat read BASIC.sleep(1) PUB init BASIC.high(S0) BASIC.high(S1) BASIC.high(LED) PUB read BASIC.low(S2) 'Red section BASIC.low(S3) BASIC.count(OUT, pRED, RED) BASIC.high(S3) BASIC.count(OUT, pBLUE, BLUE) 'Blue section BASIC.high(S2) BASIC.count(OUT, pGREEN, GREEN) 'Green section LCD.CLS LCD.str(string("Red: ")) LCD.dec(RED) LCD.CR LCD.str(string("Green: ")) LCD.dec(GREEN) LCD.CR LCD.str(string("Blue: ")) LCD.dec(BLUE)
Now, I could also paste the LCD Obj and the BASIC Obj.. But I think from the function calls that they are self-explaitory.
I think that is all the info I need to provide, please get back soon!
-John
Comments
You also need to connect +3.3V to Vdd on the TCS3200 board. The +5V powers only the LEDs.
-Phil
John
V+ is a no-connect. BTW, there's a complete schematic on the last page of the TCS3200-DB documentation.
-Phil
BTW, I received a BS2px today from Parallax, so I might be able to provide more help with your ColorPAL issue, if you're still having trouble with it.
-Phil
I think the problem may lie in JawsBASIC.Count. The effective units it uses for the time interval are much shorter than they are in PBASIC. Plus, it doesn't even do what it says it does: it counts highs, not pulses. Just ditch that object altogether, since it doesn't really provide any utility for you. Instead, set your pins high and low directly with dira and outa, and use a counter in edge mode to count the sensor's output over a period defined by waitcnt.
-Phil
Thanks,
-John
[EDIT] Don't worry, I figured it out, check out this link:
http://reibot.org/2011/07/06/tcs3200/
-Thanks for all your help
P.S. I got the ColorPAL working with BS2px, I think it was just make-sure-program-pins-are-matching-the-one-the-sensor-is-on problem
'Interesting link! Thanks for citing it!
As to the refresh rate, that depends. Since the output is a frequency, the more light the sensor sees or the longer the integration time, the more cycles that can be counted and the more accurate your results. OTOH, if you could measure the period extremely accurately, you would need only one cycle to determine the response. So it all boils down to how much light is available to measure, how accurate you want your results, and what method you're using to measure the frequency or period. BTW, I have yet to see an app that measures period, since the time resolution would have to be so short.
-Phil
Well, that is an interesting comment, I have been developing software in python so I can visually see the color of what the sensor can see, if you wish I can make it a long term goal to make some software that not only see's what the sensor can see, but also other information, such as the time taken to read the color, and whatever else I can think of.
-John
-Phil
I've now been writing an OBJ for these sensors, I don't know if anyone else has, but I'm almost finished the basic version, I am going to post it up on the OBX in a bit.
-John