Shop OBEX P1 Docs P2 Docs Learn Events
Help with programming the TCS230-DB — Parallax Forums

Help with programming the TCS230-DB

raejjraejj Posts: 14
edited 2009-05-09 04:01 in Learn with BlocklyProp
Hi,

For my capstone project, I decided to use the TCS230-DB color sensor. The color sensor will identify the colors my client inserts into the interactive wall panel I am designing. Depending on the color of the air hockey puck, different musical patterns will be played. Due to my background in programming, I plan to have just three colors: red, green, and blue. The code I have so far is given as an attachment. The value for red is high since it was the color when I purchased the air hockey puck. I spray painted the blue and green pucks, resulting in poor results. The scan for red is R 031 G 000 B 003. The scan for blue is R 000 G 000 B 003, and the scan for green is R 001 G 000 B 003.

I have looked at the datasheet for the color sensor and read the article Color Me Tickled from Jon Williams. He has several subroutines with white balance and calibrating colors. I can follow the code and understand what he is doing, but I do not want to copy it. Rather than having a comparison between known and scanned color values, I wanted to just scan a color and depending on the highest value (red, green or blue), output a musical pattern.

Why does the green puck not register green?

Is there a simpler way to identify colors and still retain the precision?

Any suggestions would be greatly appreciated.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-04-07 18:51
    Looks like you need to get different colors of paint to get better seperation. You can go to a paint store and get samples and try some until you get what you need and then buy the paint or just glue the samples to the pucks. Also it is better if you attach the actual .bs2 file rather than a doc file, then the code can be run by the person downloading it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-08 05:32
    Given the values you're seeing, I'd say that you need to count over a much longer time interval. Are you getting these readings with the LEDs on? Have you set the subject distance correctly, so the LED beams converge to a single spot? If you're using the "Color Me Tickled" article as a reference, please be aware that the polarity of the LED gate is now the inverse of what it was in the article.

    -Phil
  • raejjraejj Posts: 14
    edited 2009-04-08 12:52
    Hi Phil,

    So, you think I should increase the duration greater than 15 ms. I'll have to try it.

    I am getting these readings with the LEDs on, but for some reason, the LEDs flash on and immediately turn off after. I tried changing the code but it still flashes.

    And how do you set the subject distance? I read the datasheet but it seems you can only adjust from the aluminum standoffs. Is that correct?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-08 20:00
    If you have another way of fixturing the module, you don't need the aluminum standoffs. You do need to maintain a consistent subject distance of about 1" from the surface of the PCB to get accurate results, however.

    It's okay if the LED flashes, since it needs to be "on" only when it's taking a reading. It helps to limit current consumption and prolongs the LEDs' useful life. Can you list your BASIC Stamp program here, please? I just want to ascertain that the LEDs are on at the right times.

    -Phil
  • raejjraejj Posts: 14
    edited 2009-04-08 21:52
    Here is my basic stamp program.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-09 00:32
    Your program looks okay. I'm quite perplexed that your readings are so low. You might want to double check your wiring to make sure the TCS230-DB is connected properly. (The fact that your green and blue outpus are always the same makes me a little suspicious.) Also, make sure that you've not jumpered S0 or S1. And, again, the subject distance is critical. If the LED spots do not converge, your readings will be low.

    Another thought: try using DEC instead of DEC3 in your DEBUG statement. You may be getting chopped-off leading digits. If you have a scope, you can look at the signal on ColorOutput to see if you're getting anything.

    BTW: It's nice to see a properly-formatted program, like yours, presented in the forum. I wish more people would follow suit. It makes the job of those trying to help so much easier!

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 4/9/2009 12:37:35 AM GMT
  • nionio Posts: 14
    edited 2009-05-09 04:01
    raejj, i download your program.and i'm confused. how come your program doesn't have a maximum scale of each color declared?
    and how you do the "white balance" routine?
    btw, i also use TCS230 for my final project. and i can't answer why i need white balance routine done. i use jon williams code with some modification, i only read color value and not save it on EEPROM.
    so i think your answer can give me enlightenment..

    thanks,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    oh no..
Sign In or Register to comment.