IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> HiTechnic Color Sensor problem, Reads red fine, Green = 255/0, blue = 0
JKG
post Apr 10 2008, 01:45 PM
Post #1


Newbie
*

Group: Members
Posts: 2
Joined: 10-April 08
Member No.: 5,075



Hey

I recently bought a color sensor at hitechnic's. The problem, however, is that when I try to read data from it, I get some weird data.

I get color and R,G,B values alright, but both Green and Blue values seems to be wrong.

Red value is something between 0 and 255, and seems to be correct.
Green value is either 0 or 255, nothing in between
Blue value is always 0
Color value is incorrect (although it seems to be correctly calculated, as in the reason it is wrong is the incorrect Green and Blue values)

I thought the problem was my NXC code, so I downloaded the NXT-G color sensor block, and fired up NXT-G. Exactly the same problem.

What am I doing wrong? Hopefully it's not the sensor... I would hate to have to send it back from Denmark to the US for a replacement.

CODE
task main()
{
long color, r, g , b;
bool didread;

SetSensorLowspeed(S4);
SetSensorMode(S4,SENSOR_MODE_RAW);
while (true)
{
  didread = ReadSensorHTColor(S4, color, r, g, b);
  NumOut(0, LCD_LINE1, didread);
  NumOut(0, LCD_LINE2, color);
  NumOut(0, LCD_LINE3, r);
  NumOut(0, LCD_LINE4, g);
  NumOut(0, LCD_LINE5, b);
  Wait(100);
  ClearScreen();
}
}

Attached File(s)
Attached File  Colorsensor_Test.rbt ( 387.05k ) Number of downloads: 13
 
Go to the top of the page
 
+Quote Post
Anders Søborg
post Apr 11 2008, 02:24 AM
Post #2


Advanced Member
***

Group: Members
Posts: 33
Joined: 7-January 07
From: Denmark
Member No.: 933



Hi

I used the color sensor for my image scanner - and I must say that the readings was not as accurate as I would have hoped. In order to get the best result the sensor must be kept at a fixed distance of about 1 cm from the object that you are trying to measure. I haven't tested your code (since I don't have a NXT in sight), but below I have posted the code I used for the scanner.

CODE
#define SCAN_SENSOR_PORT IN_2

byte rt_bytes=6;//Read 6 registers
byte answer[6];
byte request[] = {0x02, 0x46}; //I2C address 0x02 and read from register 0x46 (RAW 10 bit value) http://www.hitechnic.com/

struct RGB_color{
  unsigned char red;
  unsigned char green;
  unsigned char blue;
};


void get_color(RGB_color &color){
    I2CBytes(SCAN_SENSOR_PORT, request, rt_bytes , answer);
    color.red = ((0xff & answer[1]) | ((0xff & answer[0]) << 8));
    color.green = ((0xff & answer[3]) | ((0xff & answer[2]) << 8));
    color.blue = ((0xff & answer[5]) | ((0xff & answer[4]) << 8));

}

Let me know how it works out. (I used firmware version 1.06a - download it at the NXC website)
Anders
Go to the top of the page
 
+Quote Post
JKG
post Aug 13 2008, 05:35 AM
Post #3


Newbie
*

Group: Members
Posts: 2
Joined: 10-April 08
Member No.: 5,075



I know this is an old topic, just wanted to tell that the solution was to calibrate the sensor every time it's used (as the first thing in your program, not for every reading).

(this was done in LeJOS)
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



Lo-Fi Version Time is now: 2nd September 2010 - 03:57 PM