Page 1 of 1

NXT 2.0 New Color Sensor Issue

Posted: 22 Sep 2011, 14:16
by obsoletepower
Hello everybody.
I am having an issue with the new colour sensor. I am trying to program it so that it stops the robot when bright light is detected yet I cannot seem to do this. When I use the brick to View the ambient / reflected light values from the sensor they stay at 100% no matter what I do. I tried calibrating it but it always displays the raw value of 1023 under any light condition. I should mention this is with LEDs off. I have scoured the internet and what I seem to come across is that the new colour sensor has slightly different programming requirements and I would be grateful if somebody pointed me in the right direction such as an updated programming guide etc. I use Bricxcc to code. Any help will be appreciated.

Re: NXT 2.0 New Color Sensor Issue

Posted: 22 Sep 2011, 15:30
by afanofosc
The first step toward resolving this problem is for you to post your non-working NXC code here. That will help us figure out what you are trying to do and how to help you successfully do what you are trying to do.

John Hansen

Re: NXT 2.0 New Color Sensor Issue

Posted: 22 Sep 2011, 22:00
by obsoletepower
Yeah that probably would have been a good idea :) I just whipped up some simple code to test out the functionality of the new sensor. Basically it is supposed to keep the robot moving until it senses bright light then it will stop and play a sound.

Code: Select all

#define THRESH 70

task main()
{
 // Initiates sensor as an ambient light sensor
 SetSensorType(IN_3,IN_TYPE_LIGHT_ACTIVE);
 SetSensorMode(IN_3,IN_MODE_PCTFULLSCALE);
 ResetSensor(IN_3);
 OnFwd(OUT_BC, 75);

 while (true) // Continue the execution of code
 {
  if (SENSOR_3 > THRESH)
  {
   Off(OUT_BC); Wait(100);
   PlayFileEx("annoy.rso", 4, 0);
   until(SENSOR_3 <= THRESH);
   OnFwd(OUT_BC, 75);
  }
 }

Re: NXT 2.0 New Color Sensor Issue

Posted: 23 Sep 2011, 04:03
by afanofosc
So, you can't use the old light sensor types/modes with the NXT 2.0 color sensor.

Search the NXC help for SetSensorColor. You'll see a few API functions for configuring the NXT 2.0 color sensor. If you want to turn off the LED so that it does not shine red, blue, or green then use SetSensorColorNone.

Another thing to mention is that the IN_ constants from NBCCommon.h are meant for use in NBC code and it is generally recommended that you use the SENSOR_TYPE_*, SENSOR_MODE_*, and S1..S4 constants from NXCDefs.h instead.

Once you have configured the color sensor using SetSensorColorNone you should be able to read the sensor value using SENSOR_3.

John Hansen

Re: NXT 2.0 New Color Sensor Issue

Posted: 26 Sep 2011, 13:54
by obsoletepower
Thanks a lot. I found the API's that worked with the new colour sensor. Much appreciated!

Re: NXT 2.0 New Color Sensor Issue

Posted: 23 Oct 2011, 18:08
by roxindrang
Hi, me too, I have a problem with the new light sensor. I would like to access it from the normal lego provided software. It seems that the sensor reads 1023 both in dark, both in direct light (tried with embedded try me software and a custom one). There is an other way to test it?

Re: NXT 2.0 New Color Sensor Issue

Posted: 25 Oct 2011, 13:18
by hassenplug
roxindrang wrote:Hi, me too, I have a problem with the new light sensor. I would like to access it from the normal lego provided software. It seems that the sensor reads 1023 both in dark, both in direct light (tried with embedded try me software and a custom one). There is an other way to test it?
...as john just wrote:So, you can't use the old light sensor types/modes (and blocks) with the NXT 2.0 color sensor.