Shop OBEX P1 Docs P2 Docs Learn Events
TCS3200-DB Color Sensor with Prop — Parallax Forums

TCS3200-DB Color Sensor with Prop

John BoardJohn Board Posts: 371
edited 2012-02-11 13:53 in Accessories
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:
' =========================================================================
'
'   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

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-02 08:58
    John,

    You also need to connect +3.3V to Vdd on the TCS3200 board. The +5V powers only the LEDs.

    -Phil
  • John BoardJohn Board Posts: 371
    edited 2012-02-02 14:30
    Heh, funny design, oh well, will hook up a 3.3v to it. Will keep you posted,

    John
  • John BoardJohn Board Posts: 371
    edited 2012-02-02 14:33
    Tried that too, no change, what does V+ connect to, or is it left NC?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-02 14:47
    John Board wrote:
    Heh, funny design, ...
    Nothing was done without a reason. The white LED circuit requires +5V to regulate properly. The sensor, however, is compatible with both 5V and 3.3V logic, so it needs to be powered in a way that's compatible with the micro connected to it.

    V+ is a no-connect. BTW, there's a complete schematic on the last page of the TCS3200-DB documentation.

    -Phil
  • John BoardJohn Board Posts: 371
    edited 2012-02-02 14:58
    Never the less, it still doesn't work with my Prop chip.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-02 19:16
    I'll give it a try later. Where did you get the "Jaws" objects?

    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
  • John BoardJohn Board Posts: 371
    edited 2012-02-02 21:12
    Copied or wrote the "Jaws objects", here is a zip with all the code in it.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-02 21:47
    John,

    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
  • John BoardJohn Board Posts: 371
    edited 2012-02-08 00:11
    Thanks, I will do all of this, but as since I'm not to great with SPIN yet, would you be able to write up an example of the counting thing? If you don't have time, that is fine, also if you think I should figure it out, just say so, I just like using other's code as referece for my own code and learn off other people's code.

    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
  • John BoardJohn Board Posts: 371
    edited 2012-02-08 01:01
    Also, what refresh rate can the sensor work at?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-08 09:05
    John,

    '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
  • John BoardJohn Board Posts: 371
    edited 2012-02-08 21:57
    BTW, I have yet to see an app that measures period, since the time resolution would have to be so short.

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-09 10:01
    By "period" I didn't mean the time taken to read the color, but a color reading method that measures the time between edges in the frequency output, rather than counting pulses over a fixed time interval. At 100 kHz, this interval is only 10 usec. One 1/256 step higher in frequency is 100.39 kHz, where the interval is 9.961 usec, so a difference of only 39 nsec to achieve 8-bit resolution. That's not impossible in PASM, of course, but AFAIK, no one's tried it that way. The other problem with period measurement occurs when there's very little light, and the interval between edges becomes very long.

    -Phil
  • John BoardJohn Board Posts: 371
    edited 2012-02-09 22:03
    Ahh, okay, well, I'll leave it to the "techsperts" then. Thanks for your help, you'll see another post getting posted by me in the next few days too...
  • John BoardJohn Board Posts: 371
    edited 2012-02-11 13:53
    Hi,

    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
Sign In or Register to comment.