BrickPi Colour Sensor

ok, so for those who have read loads of my previous posts, I am kind off a noob at brickPi. I am going to explain a project I am working on, and some problems I am having with it. I am trying to make goal-line technology, in which I decided to use BrickPi to program it. I am trying to use the NXT light sensors, to sense when the goal goes in, and then the LED’s will flash. The competition I am entering is in 6 days, and I am sturggling with the programming aspect of things. i run the command, sudo python LEGO-Color_Sensor_Test.py the plugged in sensor on Port 1 turns on. But on the screen it just repetitivly spams,
black
black
black
black

now i know I am rather a noob, but when I trype sudo python LED.py the LED’s work a treat. When i have programmed the light sensor to sense the colour, I need to put the projects together.

i am very sorry that I couldn’t do this myself, if anyone has any questions, or answers, please, please reply

Sam

Hey Sam,

No worries, we’re all noobs with this. Let me see if I can help a bit.

Glad to know the LED’s are working. Can you try running a motor or a touch sensor example first and make sure that it works?

Also, which version of Raspberry Pi are you using? Raspbian with the necessary changes, our own BrickPi image, or other?

The color sensor is not working entirely reliably right now, and before we conclude that’s the problem, I just want to make sure the software is installed correctly on the BrickPi.

John

I am using the DexterInd 2014 image.

Basically I am trying to code a goal-line technology that the LED’s go of for five seconds after the ball has passed through the light snesor

That’s good, everything is probably installed correctly.

Did you try running the color sensor over different colors? The example program repeats the color the sensor is reading over and over. So if it’s not reading a color, it should be showing black. I would also move the color sensor around a bit, and at different distances from the surface color your reading.

Also, I asked in the first post: Can you try running a motor or a touch sensor example first and make sure that it works? Just want to know if the communications between the BrickPi and the RPi are working.

Hi BrickPi coders,

When trying to run LEGO-Color_Sensor_Test.py I constantly get 0 as result (on normal day-lighted room), does this mean no color can be clearly recognized? When printing out the values for BrickPi.Sensor[PORT_1] I receive values in the range of 0…1000, yellow seems in the 2xx and blue in the 8xx range. Can someone please enlight :slight_smile: me about where to find more details about the color values? Would an extra battery help here (I don’t have one to hand)?

  • Powered by USB (no extra battery)
  • Updated (apt-get update/upgrade) Dexter image (2013.07)
  • Only NXT 2.0 Color Sensor connected to BrickPi (Port S1)
  • Added BrickPi.SensorType[PORT_2] = TYPE_SENSOR_COLOR_FULL to also initialize S1 (as proposed in this thread)

Thanks,
Niko

ok, sorry for not replying in weeks, i have been at the event, and then on holiday. So, I have run the code, and neither the touch sensor, or the light sensors work. But the LED works

Ok. This is a bug I have found as well. For my project, blue was great, but It can be a problem. The problem is that you don’t have enough power going to the BrickPi with the USB. You need the batteries. :confused:

Also Adding

BrickPi.SensorType[Port_1] = TYPE_SENSOR_COLOR_FULL
BrickPi.SensorType[Port_2] = TYPE_SENSOR_COLOR_FULL

Makes the code fully functional.

Which color sensor are you using?

I picked up the HT (HiTechnic) Color Sensor for LEGO Mindstorms NXT and have been unable to get it to work so far. The color sensor python test code just returns “None”.

It would be great to know if anyone has gotten this one working with the BrickPi.

I’m not finding this problem to be related to power. I’ve tried multiple configurations and none of them work. The other motors and sensors work, just not the color one.

About your code, how does looking for the color sensor on a port you aren’t using make it fully functional?

I have a similar problem here. Again, using the standard RPi image, and trying the python colour sensor program, I see nothing but black, even when pointing the sensor directly at a light source (like my screen). Ran up against it while trying to test the Ruby gem we’re working on…

Nothing has helped thus far, I’m not sure what to do

Sam, and all: I just wanted to let everyone know we haven’t forgotten about this. To date, we haven’t been able to re-create the problem or see a problem with the color sensor when using the latest image.

We’re a little baffled, but we suspect it might be a problem with the type of color sensor used. A week ago we bought every type we could find, including the HiTechnic version and the old LEGO version and we’ll try to find out if that makes a difference. I’m sorry for the delay in solving this problem, I know it must be frustrating.

Just wanted to let you know we haven’t forgotten about it.

thanks, at the moment i am using a UltraSonic Sensor, and it is working very well. I am just fiddling around with the code, and have nearly completed my project. Thank you for responding, and sorry for not being the most on the ball myself (I havnt had interent for the last 2 weeks).

Hey Folks,
So we went ahead and ordered a few color sensors from Amazon and LEGO. We’re talking about LEGO Color Sensor 9694 (http://peeron.com/inv/parts/64892).

I’ve run the two color sensors we have on every port, and been able to get the test program to work for each one. Here are some possible issues:

  • Use the latest image. You can download it here, from sourceforge. http://www.dexterindustries.com/BrickPi/getting-started/pi-prep/ This is especially important if you’ve last used an image titled anything with “2013” in it. At the beginning of the year, we did a really big update. Later updates are just minor improvements.

  • Power doesn’t seem to matter. I tried it both using a battery registering 10 V, and using the USB power. Both configurations seemed to work well.

  • Ensure that another sensor is working properly. If you can run a touch sensor on another port and see successful results, it’s working properly (for example). Running one of the LED examples just blinks the LED, it doesn’t interact with the BrickPi sensors or motors. A working LED example is not proof positive of a proper setup. If you can’t get a response using the Ultrasonic, Touch, or motors, you may have damaged / defective hardware. Contact us about this through our website.

  • If you’re using the Hitechnic color sensor, bear with us. We just received one and we’ll try to write and test some software for it. This operates differently than the NXT Color Sensor.

Hey - I’m also having some trouble with just the colour sensor. Getting the repeated [black, black, black…] reading when running the python test.

  • Using LEGO Color Sensor - 9694
  • Latest BrickPi Image - June 2014
  • Touch & Ultrasonic sensors behave as expected in all four sensor ports

I’m not sure what is up. I get no response at all, not even the LEDs within the sensor. Is there a routine to flash the internal RGB LEDs to see if there is life in the sensor? I’m stumped otherwise for ideas and no Mindstorms brick to test it out on.

Cheers

Edit 2 : It Works !!! with red, blue, green, yellow ball from nxt set !!!

Hello,

I have this bug too.
But Activating a second sensor on port 4 doesn’t work !

I Search why since 3 days, I have compared with Bricktronics Shield ans lejos source.

I try something which seems to work “a little”.
I add DigitalWriteFast.h from Bricktronics shield to the project.
Then in BrickCS.cpp I replace the inline uint16_t CS_READ_DATA() function by :

inline uint16_t CS_READ_DATA(){
pinMode(A0, INPUT);
digitalWriteFast2(A0, LOW);
uint16_t value = analogRead(A0);
return value*50/33;
}

I know this is not well done but i’m a beginner with avr programming so I use digitalWriteFast.h !

Compiled and flashed this new firmware with my color senosr plugged in port 1 on atmega 2 ( port 3 ).
With that, I can get some result instead of always black but not accurate at all.

So the problem is there, in Analog reading but why ???

Is there some news on this bug ?

Edit : I use Firmware 1.7.4

Edit 2 : It Works !!! with red, blue, green, yellow ball from nxt set !!!

NB : I must add the second line of initialisation ( BrickPi.SensorType[Port_(+1)] = TYPE_SENSOR_COLOR_FULL ) for this workaround to work !

Full modified working Function :
( if someone can rewrite properly this, i would be pleased ! )
I think this is a timing issue, DigitalWriteFast is less fast than direct AVR adressing, perhaps this is the trick ??

inline uint16_t CS_READ_DATA(){
    uint8_t tmpPORT;
	if (CS_PORT==PORT_1) tmpPORT=A0;
	if (CS_PORT==PORT_2) tmpPORT=A1;
	pinMode(tmpPORT, INPUT);
    digitalWriteFast2(tmpPORT, LOW);
    uint16_t value = analogRead(tmpPORT);
    return value*50/33;
 // CS_SET_DATA_INPUT;
 // PORTC &= (~(0x01 << CS_PORT));
 // uint16_t value = A_ReadRawCh(CS_PORT);
 // value *= 50;                           // Convert the 5v readings
 // return (value / 33);                   // to 3.3v readings
}

Colour Sensor not working for me.

First:

  • Touch sensor on port 3 is fine, controlling it via Python.
  • NXT Colour sensor checked out fine when used with the NXT Brick itself.

I noticed that, when used with the NXT brick, the colour sensor turns a light on to detect colour. No light comes on when used with the BrickPi. It only detects black. (well, that makes sense if there’s no light).

I’ve tried with Port 1 and Port 2. I have the last version on the Pi, as I installed everything this week for the first time.

I also have the same problem if going through Scratch btw.