TCS34725 RGB Sensor

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
BMXerDan
 
Posts: 3
Joined: Sat Aug 02, 2014 11:20 am

TCS34725 RGB Sensor

Post by BMXerDan »

I have 2 of these RGB sensors, one of which I am using for a project using a Renesas M16C/62P microcontroller and one which I have connected to an Arduino UNO for reference and to make sure I'm getting the same/similar values

I've not really had a problem beginning to program with it until now which is related to the colour registers.

I have both of the devices set with the same settings for testing purposes
Integration time: 700ms
Gain: x1

Whilst retrieving the colour values from the CDATAL, RDATAL, GDATAL, BDATAL registers (0x14, 0x16, 0x18, 0x1A respectively) I seem to be getting a significant discrepancy with the data returned.

The two sensors are right next to each other on a breadboard so their environment is almost exactly the same, so similar values are expected however this isn't quite the case.

The values from the UNO I am comparing my values with are as follows

Arduino UNO
Clear: 960
Red:335
Green: 370
Blue: 342

The values retrieved by my M16C at the same point in time as the UNO:

My Values
Clear: 328
Red: 951
Green: 320
Blue: 345

With my project, the RED values are matching the UNO's CLEAR values and viceversa with every light/colour test I have carried out with it. I am referencing the correct data registers with my code, I made sure I didn't have the CDATAL register in my code reading the red value etc but don't understand why this is happening.

Am I missing something that the Arduino is doing with the values because looking at the code I'm doing the same thing to read the registers


Any help with this issue would be greatly appreciated

Thanks

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: TCS34725 RGB Sensor

Post by adafruit_support_mike »

Let's start with a sanity test: what happens if you swap TCS34725s between the two microcontrollers? Are the differences associated with a specific sensor or a specific platform?

BMXerDan
 
Posts: 3
Joined: Sat Aug 02, 2014 11:20 am

Re: TCS34725 RGB Sensor

Post by BMXerDan »

adafruit_support_mike wrote:Let's start with a sanity test: what happens if you swap TCS34725s between the two microcontrollers? Are the differences associated with a specific sensor or a specific platform?
Ha, yea it does seem a bit insane but swapping the sensors between the microcontrollers has no effect. I tried this before coming here just incase there was anything wrong with one of the sensors, I achieve the same results on both platforms.

However after doing a bit more testing it seems that I'm not getting correct values from the registers.

I am calling 4 separate functions to read the 4 colour registers and from what I understand reading the datasheet and the TCS34725 example project code I need to initiate a write transaction with the command bit (0x80) OR'd with the colour register followed by a 2 byte read transaction of the colour register

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: TCS34725 RGB Sensor

Post by adafruit_support_mike »

BMXerDan wrote:swapping the sensors between the microcontrollers has no effect.
That's a good thing.. it means the basic hardware is okay and we're looking at a software issue.

Your description of the read process seems to be correct. Post the code you're using for the non-Arduino device and we'll see if that gives us any clues.

BMXerDan
 
Posts: 3
Joined: Sat Aug 02, 2014 11:20 am

Re: TCS34725 RGB Sensor

Post by BMXerDan »

This is my function to return the Red Low Register Value

Code: Select all

int getRedLow(void)
{
	slaveAddress.address = (TCS34725_WRITE_ADDRESS >> 1);		// Copy the slave address of TCS34725 into slaveAddress.address variable
	slaveAddress.rw = 0;										         // set 'Read/Write' bit as '0' to write to the TCS34725
	I2C_Write(TCS34725_COMMAND_BIT | TCS34725_RDATAL, 1);      // 0x80 | 0x16
	
	slaveAddress.address = (TCS34725_READ_ADDRESS >> 1);       // Copy the slave-address of TCS34725 into slaveAddress.address variable
	slaveAddress.rw = 1;                                       // set 'Read/Write' bit as '1' to read the TCS34725
	I2C_Read(TCS34725_COMMAND_BIT | TCS34725_RDATAL, 2);		 // 0x80 | 0x16
	RedData1 = ReadData[0];										      // Byte 1
	RedData2 = ReadData[1];										      // Byte 2
	
	Red = ((RedData2 << 8)| RedData1);					          // Shift byte 2 left 8 bits OR the 2 bytes together to make 16 bit value
	
	return Red;													         // Return value of Red Register
}
Each of the other Low Register functions are the same accept for the obvious register values

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: TCS34725 RGB Sensor

Post by zener »

I am suspicious that your green and blue are reversed also. I assume you read the colors in some order. You might try changing that order and see what happens.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”