After getting my BrickPi on the weekend, I’ve managed to convert my Mindstorm Ball Sorting robot from using the NXT to using the BrickPi. Everything works, controlled by a simple program written in Python.
However, I encountered a problem during the conversion trying to use the LEGO color sensor. I found a work around, but wanted to report the issue here.
I’ve recreated the issue with short Python script (embedded below). The color sensor is connected to Port 3, but when I run the script with my setup the sensor never goes into color sensing mode (I see a very brief flash of red in the sensing eye, then it all goes dark). The sensor always reports back the value 1 (which is black).
The work around I found is to also set Port 4 into color sensing mode (uncomment line 13 in the script). Now everything works as expected.
I can also recreate this on Port 1 and 2, and I have also recreated it using the C library.
Is this a known issue? Or am I simply programming the BrickPi wrongly?
#!/usr/bin/env python from BrickPi import * #import BrickPi.py file to use BrickPi operations BrickPiSetup() # setup the serial port for communication col = [ None , "Black","Blue","Green","Yellow","Red","White" ] #used for converting the color index to name # Configure BrickPi BrickPi.SensorType[PORT_3] = TYPE_SENSOR_COLOR_FULL # Need to uncomment the following line to make this work. Why? #BrickPi.SensorType[PORT_4] = TYPE_SENSOR_COLOR_FULL if BrickPiSetupSensors(): print "Failed to setup BrickPi" exit() time.sleep(.1) last_color = None while True: result = BrickPiUpdateValues() if not result : color = BrickPi.Sensor[PORT_3] if (color != last_color): print "I see %s (%d)" % (col[color], color) last_color = color time.sleep(.1) # sleep for 100 ms