The Lego Mindstorms NXT RGB Color Sensor v2 can be used to determine the colour of objects and may be connected to a PICAXE using an I2C bus and controlled by appropriate PICAXE I2C commands.
LEGO and MINDSTORMS are registered trademarks of the LEGO Group. I2C is a registered trademark of Philips Semiconductors Corporation.
Lego NXT RGB Color Sensor v2
Schematic
![](_/thumbnailff0e.jpg)
PCB
![](_/thumbnail3c77.jpg)
Title
This is a sample program for the Hitechnic NXT Color Sensor V2 (part MS1038) using the AXE216 i2c Explorer Kit with a PICAXE-20X2. Please note that this program will not work with Lego NXT Light Sensor or Lego NXT RGB Sensor!
- Code Example:
-
#picaxe 20x2 #no_table symbol color_number = b0 ; adjusted colour 0 to 17 symbol red_value = b1 symbol green_value = b2 symbol blue_value = b3 symbol white_value = b4 symbol color_index = b5 ; bitwise colour xxRRGGBB ; Wires on NXT jack plug. ; Wire colours may vary. Pin 1 is always end nearest latch. ; 1 White No connect ; 2 Black 0V ; 3 Red 0V ; 4 Green V+ (4.5V or 5V) ; 5 Yellow SCL ; 6 Blue SDA ; Do not use i2c pullup resistor - already provided within sensor. init: ; Slave address is $02 hi2csetup i2cmaster, $02, i2cslow, i2cbyte ; Configure sensor if required. ; All saved in EEPROM within sensor. Therefore only use once if required. ; hi2cout $41, ($00) ; set to normal measurement mode (white LED flashed) ; hi2cout $41, ($01) ; set to passive mode (white LED not flashed, raw data only) ; hi2cout $41, ($03) ; set to raw mode (LED is used, raw data only in bytes $42-49) ; hi2cout $41, ($42) ; Do Black level calibration ; hi2cout $41, ($43) ; Do White balance calibration ; hi2cout $41, ($4E) ; set to Near mode (do white/black calibration after changing) ; hi2cout $41, ($48) ; set to Far mode (do white/black calibration after changing) ; hi2cout $41, ($4C) ; set to LED low power ; hi2cout $41, ($48) ; set to LED high power ; hi2cout $41, ($35) ; set to 50Hz mode (UK, Europe, Australia) ; hi2cout $41, ($36) ; set to 60Hz mode (USA) pause 1000 ; do a delay main: ; read values hi2cin $42,(color_number, red_value, green_value, blue_value, white_value, color_index) debug ; debug display pause 1000 ; wait 1 second then loop goto main
Copy Code Submit an Example
Create Module
![](../../../thumbnail48bc.jpg)
Lego Mindstorm NXT sensors can be connected using two generic terminal block create modules to carry the SDA and SCL signals of the I2C bus.
Bill of Materials
Description | Code | Qty | |
---|---|---|---|
Lego NXT Compatible socket | CON070 | 1 | Buy Now |
Simulation
Submit Your Own Code!
You must be logged in to submit code examples. Login now.
Share