TCS230 TCS3200 sensor dont work on Specifiy Library, just on an example?

First of all, Hi and thanks for all the insights.

A frien of mine neeed to activate a relay, on a color change on a monitor, no porblem there, there are 3 mayor colors; green for pass, black for wait (non activate) and red (non active).

Im trying to use an TCS230 sensor for the color readings.

At first when on:

This simple example, and the sensor star to works, read some values and stuff.
when I tried to read some specific color, the fun begun, and shortly I realize I migth need a very good Lib for the Job.

Fortunately, I fount this one:

It has many interesting features, like the fact for start, that has a “calibration”, for read more accurately.
And the capacity for read color and label them for the use in the program.

An here is were I need some of you help.

I tried to wire like the previous example, and in the begging I was very unsure, because in the first example of circuit today they use 6 wire, and in the library code they only mention 3 wires.

Long story short:

The sensor has to be wired correctly, and the sensor has a hardware problem.

This are the tips I can found use the web:

1.- In the use of the library, the sensor might be modify, (There is a PDF on the Library download folder, more details in there).

2.- This is a library uses another, called FreqCounter, more on this on This thread and for the use of this library, you have to check the rigth hardware pin to be used (as not all of them are usable for this purpose). There is a

I pin the sensor as follows:
S0 - VCC
S1 - VCC
OUT - PIN 5
S3 - pin 10
s4 - pin 11
vcc - vcc
gnd -gnd

I tried the calibration, and I get color is RGB[0,0,0]

So, I modify the sensor, tried again and still get the same error.

I search and some people were correcting they errors by choosing the rigth output pin, in this case the 5, (Im using arduino UNO).

this is the code;

// 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  11
#define  S3_OUT  10
#define  OE_OUT  5    // 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
  }
}

But I cant figure out, were is the error.

Any help will be appreciated.
-Alex.

The library needs a minimum of 3 signal wires to work - S2, S3 and the frequency (pin 5 on Uno) - plus Vcc & GND

 MD_TCS230(uint8_t s2, uint8_t s3);

The library does not care which pins are S2, S3, as long as you tell the object constructor what they are.

If you leave the other pins out then they will be set as 'tri-state' high impendance inputs by the hardware and they default to safe values (ie, they are not required). The more wires the more control you have, but for simple applications, and in your code to debug the problem, I would suggest that you try with the minimum number of wires first to minimise the potentia lproblem.

All rigth, I will try this and come back with some results. -Alex.

Hi Marco, Al ready make the test, I cant make this work,
these are the two test I make alredy.

Im using Arduino Uno, dowload FreqCounter and install the library from 0.
SENSOR - Arduino
s2 - Pin 10
s3 - Pin 11
out - Pin 5
VCC - VCC
GND - GND

SENSOR - Arduino
s2 - Pin 10
s3 - Pin 11
OE - Pin 5
VCC - VCC
GND - GND

The test value comes witj RGB(0,0,0) always.

Any idea for make this works? Thanks.

The sensor was modify beacuse have the bridge between gnd and OE as the manual says.

This is the code:

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

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

// Pin definitions
#define  S2_OUT  10
#define  S3_OUT  11
#define  OE_OUT  5    // 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
  }
}

SENSOR - Arduino
s2 - Pin 10
s3 - Pin 11
out - Pin 5
VCC - VCC
GND - GND

SENSOR - Arduino
s2 - Pin 10
s3 - Pin 11
OE - Pin 5
VCC - VCC
GND - GND

Which one is it? You should not be connecting OE to pin 5 if that is the frequency count input.
Leave OE disconnected or connect it to ground.

Hi Marco, I make another test using an Arduino Mega as Baseboard, this are the conections:

Sensor Arduino Pins
S2_OUT 43
S3_OUT 41
OE_OUT 47 // LOW = ENABLED whath is this for?
VCC VCC
GND GND

This is the Page where I find the Pin for Freq Counter for the Mega and the Arduino Uno, plus some other boards:

https://www.pjrc.com/teensy/td_libs_FreqCount.html

As you pointed i make a test with the OE pin Connected to ground, the results were the same.

And this is the code:

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

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

// Pin definitions
#define  S2_OUT  43
#define  S3_OUT  41
#define  OE_OUT  47    // 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
  }
}

OE stands for OUTPUT ENABLE, it is the pin that starts and stops the sensor IC from counting frequency. This is an output from the Arduino and an input to the sensor. The Frequency output from the sensor is an input to the Arduino. These are NOT the same thing.

Pin 47 on the Mega is the pin that the frequency counter uses to count frequency so you CANNOT connect it to OE. This will never work and you may damage the sensor (maybe this has already happened).

Hi Marco, I whent to make a basic test, using the basic code like this;

https://hetpro-store.com/TUTORIALES/sensor-de-color-tcs3200-con-arduino/

And the sensor reads 0, 0, 0.

This test make me wonder if the cut on the OE pin dont affect of somehow the sensor ability to be read. Tomorrow I wled the brindge and tes the same come, hopefully I will come bak with some results.

Thanks a Lot.

Just read you response, Yes most likley the sensor was damage, tomorrow Will test another sensor.

-Alex.

This test make me wonder if the cut on the OE pin dont affect of somehow the sensor ability to be read. Tomorrow I wled the brindge and tes the same come, hopefully I will come bak with some results.

What cut? is his the cut to remove the internal OE to ground connection? In this case you always need to connect the OE pin to ground as there is no internal connection on the sensor board. If you are just using one sensor board, yo can leave the OE internal connection BUT you must not connect the OE pin to the Arduino pin as this will short the power supply if the Arduino sets the pin high to disable OE.

You may also have cut the wrong trace, of course.:-)

Hi again Marco, I come this time with a nice huge trouble. Tomorrow we test 2 new sensors, on the arduino Uno and Arduino Mega as the previus attemp.

Just connecting 3 wire as you suggested:

Sensor--- arduino VCC - VCC GND - GND OUT - PIN 47 S2 - PIN 41 S3 - PIN 43

On the mega and in the Uno the results were all the same, the program come back with RGB ( 0, 0, 0).

We test the following code, on the same settings as the above, on arduino mega, and we have some response:

The code: https://hetpro-store.com/TUTORIALES/sensor-de-color-tcs3200-con-arduino/

The output:

28   43   40   Rojo
   26   43   40   Rojo
   22   44   41   Rojo
   28   44   41   Rojo
   28   44   41   Rojo
   28   44   41   Rojo
   28   46   43   Rojo
   29   47   43   Rojo
   29   47   43   Rojo
   31   50   46   Rojo
   31   52   47   Rojo
   32   50   47   Rojo
   32   50   44   Rojo
   29   46   43   Rojo
   28   44   41   Rojo
   28   47   43   Rojo
   29   49   44   Rojo
   35   43   35  
   23   26   23  
   26   26   26  
   28   32   29   Rojo
   26   31   28   Rojo
   26   31   29   Rojo
   31   35   32   Rojo
   29   34   31   Rojo
   31   35   31  
   31   35   31

So far, neither of the sensor has been modify, we plan to use only one per arduino, so we leave alone the OE wiring.

Any idea why the library dont seem to work? any other test?

Regards. -Alex.

We are testing the sensor on arduino Mega and its responding, Im trying to use the same configuration on you eample, but no response so far, this catch my eye;

Do you have reservated works for the librarys? why they are not showing on the IDE?

may be a problem on the files?

Will come back with more information.

-Alex.

|500x281

I erase another Library, was flaged for missing a manteiner.

Know the program put the library name on orange as supposed to, but dont work either.

-Alex.

I will keep the uptdate.

I have something odd here:

In your site, clearly states the Lib for the sensor is based on FreqCount Lib.

In the FreqCount site fo the creator, clearly states the pin for freq count is the pin 5 on arduino uno.

Yet the exaple comes with 8 by default.

I havent see the FreqMeasure And clearly state the FreqMeasure pin on the Arduino uno is pin 8.

Im puzzled ???

|500x280

|500x280

I finally make this think work, here is the last settings works for me, may be download the FreqMeasure Library is not necessary, just saying.

|500x437

I start to the project, If need any help will come back for more, thanks for the Lib.

Thanks.

-Alex

In the FreqCount site fo the creator, clearly states the pin for freq count is the pin 5 on arduino uno.

Yet the exaple comes with 8 by default.

You still don't seem to understand the different between OE and the frequency input pin. OE output is pin 8 by default in the examples. Frequency pin is NOT defined in the examples because it is 'hard coded' by the FreqCount library.

Anyway, good you got it working and good luck with your project.

Hi Marco and thanks for the help, Yes, maybe in the rush I lost this.

Yet the sensor is working and the code is more than a candy, I still learning much on this.

On this stage of the project, we are using the sensor for reading raw values, then to convert them in to a HUE value for easy comparisson.

when is ready I will send you a link, bye the way the calibration makes the sensor very much precise, Once its is calibrate we have a diference between one reading and another in the same color of 0.5 of a HUE value, for our needs this is very much acurrate.

Thanks. -Alex