TCS3200 Library usage

Good morning to you.
I've buyed few days ago a TCS3200 sensor for obtain the RGB color value from same objects.
I've tried and modified some skatches I've found on the net, but the results are so far from the reality, in particular for the yellow color (that is the most important color I must detect).
Yesterday I had notice that exist a library, here below listed:

https://arduinocode.codeplex.com/releases/view/115253

that I've downloaded.
I've two question for that:

  1. In all the sketches it's declared just S2 , S3 and OE pins.
    The S1, S0 and OUT pin not figure in any sketches?
    It's correct or I stay forgetting something?
    Infact, when I try to calibrate the sensor, the RGB value are always " 0,0,0 ". Remember the OUT pin is not connected.
    2)Could I gentle ask to you the pin configuration necessary to example sketches working?
    I just wanna play with it and try to make something different from my previously attempt. Expecially for yellow color.

Thank you so much to all in advance.

Perhaps you should not continue with this sensor.
Go to www.adafruit.com and have a look at their color sensors. The have normal sensors with i2c and libraries and tutorials. That is a good start. I think the older TCS3200 is a bad start. Is it only 4 photodiodes with frequency output ?

Thank you for your suggestion.

What do you think about sparkfun sensors?

For me is more easy to get.

Thanks.

For example this one ? SparkFun RGB Light Sensor - ISL29125 - SEN-12829 - SparkFun Electronics
I don't know if that is a common sensor, with good libraries. I think it will be okay.

I have look this one:

But don't know if is accurately enough for the price.

Anyway, from your experience, could you please suggest a accurate and precise color sensor?
I must take in consideration only the adafruit?

Thanks.

I have no experience with color sensors, but I trust Adafruit they picked a good one :stuck_out_tongue:

That one from Sparkfun is with analog outputs for R, G, B.
Those 3 analog signals are very easy to read with Arduino analog inputs. But it is less accurate and it is expensive with 24.95 dollars. It might be okay for you.

The TCS3414CS is on Ebay for 16 dollars. It has digital interface with I2C. You can't use it, if you can't find a good library for it.

Adafruit has choosen the TCS34725, it has an IR blocking filter and a high dynamic range. Adafruit added some components to make it compatible with 3.3V and 5V Arduino boards. It is obvious that the Adafruit module is the better one.

The library has a PDF document that describes the functions and how to connect the pins. Have you read this?

@Peter_h
I will try also with this sensor from adafruit and I will report the feedback. I think it can be appreciated.

@marco_c
For sure.
The PDF as I've understand, give explication referred to PIN functions, not how to wire to arduino.
Anyway, also in the "Calibrate" sketch as in the other sketches, I can't see any PIN definition about S0,S1 and OUT.
Infact, with this configuration on my arduino wired to my TSC3200:

S0 - Arduino pin 6
S1 - Ardunio pin 5
S2 - Arduino pin 4
S3 - Arduino pin 3
OUT - Arduino pin 2
LED - Arduino pin 7

I can't read. The values returned are obviously the same RGB = (0,0,0).
Here the "calibrate" sketch I've tested:

// TCS230 sensor calibration and color readings
//
// Input and output using the Serial console.
//
#include <MD_TCS230.h>
#include <FreqCount.h>

#define	BLACK_CAL	0
#define	WHITE_CAL	1
#define	READ_VAL	2

// Pin definitions
#define  S2_OUT  4
#define  S3_OUT  3
#define  OE_OUT   7    // LOW = ENABLED 

MD_TCS230	CS(S2_OUT, S3_OUT, OE_OUT);

void setup() 
{
  Serial.begin(57600);
  Serial.print(F("\n[TCS230 Calibrator Example]"));

  CS.begin();
}

char getChar()
// blocking wait for an input character from the input stream
{
	while (Serial.available() == 0)
		;
	return(toupper(Serial.read()));
}

void clearInput()
// clear all characters from the serial input
{
	while (Serial.read() != -1)
		;
}

uint8_t fsmReadValue(uint8_t state, uint8_t valType, uint8_t maxReads)
// Finite State Machine for reading a value from the sensor
// Current FSM state is passed in and returned
// Type of value being read is passed in
{
	static	uint8_t	selChannel;
	static	uint8_t	readCount;
	static	sensorData	sd;

	switch(state)
	{
	case 0:	// Prompt for the user to start
		Serial.print(F("\n\nReading value for "));
		switch(valType)
		{
		case BLACK_CAL:	Serial.print(F("BLACK calibration"));	break;
		case WHITE_CAL:	Serial.print(F("WHITE calibration"));	break;
		case READ_VAL:	Serial.print(F("DATA"));				break;
		default:		Serial.print(F("??"));					break;
		}
		
		Serial.print(F("\nPress any key to start ..."));
		state++;
		break;

	case 1:	// Wait for user input
		getChar();
		clearInput();
		state++;
		break;

	case 2:	// start the reading process
		CS.read();
		state++;
		break;

	case 3:	// wait for a read to complete
		if (CS.available()) 
		{
			sensorData	sd;
			colorData	rgb;

			switch(valType)
			{
			case BLACK_CAL:	
				CS.getRaw(&sd);	
				CS.setDarkCal(&sd);		
				break;

			case WHITE_CAL:	
				CS.getRaw(&sd);	
				CS.setWhiteCal(&sd);	
				break;

			case READ_VAL:	
				CS.getRGB(&rgb);
				Serial.print(F("\nRGB is ["));
				Serial.print(rgb.value[TCS230_RGB_R]);
				Serial.print(F(","));
				Serial.print(rgb.value[TCS230_RGB_G]);
				Serial.print(F(","));
				Serial.print(rgb.value[TCS230_RGB_B]);
				Serial.print(F("]"));
				break;
			}
			state++;
		}
		break;

	default:	// reset fsm
		state = 0;
		break;
	}

	return(state);
}


void loop() 
{
  static uint8_t	runState = 0;		
  static uint8_t	readState = 0;

  switch(runState)
  {
  case 0:	// calibrate black
	  readState = fsmReadValue(readState, BLACK_CAL, 2);
	  if (readState == 0) runState++;
	  break;

  case 1:	// calibrate white
	  readState = fsmReadValue(readState, WHITE_CAL, 2);
	  if (readState == 0) runState++;
	  break;

  case 2:	// read color
	  readState = fsmReadValue(readState, READ_VAL, 1);
	  break;

  default:
	  runState = 0;	// start again if we get here as something is wrong
  }
}

Have you some suggestion?

Thanks.

From the header file MD_TCS230.h

This library has a dependency on the FreqCount library for 
  frequency counting. FreqCount library is available at
  http://www.pjrc.com/teensy/td_libs_FreqCount.html
	
  ** IMPORTANT NOTE** 
  FreqCount imposes a limitation that the frequency can only be 
  counted on specific pins and limits the use of other pins as 
  follows:
  Board       Input Pin Pins Unusable with analogWrite()
  ----------- --------- --------------------------------  
  Arduino Uno     5      3, 9, 10, 11
  Arduino 2009    5      3, 9, 10, 11
  Arduino Mega   47      9, 10, 44, 45, 46
  Sanguino        1      12, 13, 14, 15

I do not see pin 2 listed anywhere for the frequency.

From the PDF file explaining the libraries

Initialising
MD_TCS230(uint8_t s2, uint8_t s3);
MD_TCS230(uint8_t s2, uint8_t s3, uint8_t oe);
MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1);
MD_TCS230(uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1, uint8_t oe);
Various forms of the constructor for this class. The parameters are all the Arduino pin numbers used to control the nominated pins on the TCS230. The form used will depend on the configuration of the hardware connections to the Arduino. At a minimum S2 and S3 are required for color filter selection.

Does this give you ideas?

Yes, thank you for your evidences.

Now I will try with these settings.

Only with the combination

S2_OUT, S3_OUT

give accurate results for my case.

Other ways are very far from reality.

I will take care of compare the results with adafruit sensor when I will reveice, for estabilish consistently changes.

Thank you.

guys I need your help please,
Have anyone succeed in reading colors correctly and precisely?

I am trying to read colors with TCS3200 sensor (this one exactly: Recommendations For You - DealeXtreme) with Arduino Leonardo.

It seems that any sketch I downloaded from web is either compiles with errors or complies with very weird sensor reading results.

marco_c, I tried your sketch and libraries but for some reason I get the below compilation error, any idea?

Arduino: 1.6.0 (Windows 7), Board: "Arduino Leonardo"

In file included from C:\Program Files (x86)\Arduino\libraries\FreqCount\FreqCount.cpp:27:0:
C:\Program Files (x86)\Arduino\libraries\FreqCount\util/timers.h: In function 'void timer_shutdown()':
C:\Program Files (x86)\Arduino\libraries\FreqCount\util/timers.h:453:2: error: 'TCCR2B' was not declared in this scope
TCCR2B = 0;
^
Error compiling.

many thanks for any assistance

I have no experience with Leonardo, but the web site for FreqCount seems to imply that Leonardo is supported by listing the pins needed for that Arduino variation. Maybe someone else has done this and can have more useful information.

Hello, I would like to ask and discuss something.
if you know how to solve my problem, please feel free to answer my question.

  1. I did'nt find a TCS3200 library on my internet. do you have one or know the web to download it?

  2. In my college project, i have to connect two of TCS3200 sensors to RS485 and show it on LabView. do you know how to operate that?

thx

  1. I am told my TCS230 driver works with TCS3200. Find it in my repositories site (see link below).

  2. You can connect 2 sensors but then you will need to work out how to convert the Serial from the Arduino to RS485 and how to send it to Labview in a way that it will understand. That is more a LabView question than Arduino. On the RS232 to 485 conversion, I am sure that Google will be your friend.