Camera Module

Note on the types of cameras

There are two primary types of cameras available for LEGO. The first is the PixyCam and the second is the NXTCam (which can be used for both NXT and EV3). The PixyCam has two very different versions — the original Pixy and the Pixy for LEGO. Mindsensors produces a adapter that allows the original Pixy to be used with LEGO and programmed like a NXTCam. This recap content applies to the Pixy original with the Mindsensors adapter, however the programming section likely also works for the NXTCam and the setup portion will apply mostly to the Pixy for LEGO. A brief addition regarding Pixy for LEGO will be in the recap for reference.

PixyCam Setup

  1. Download and install the PixyMon configuration software from
  2. Focus the camera. Turn the lens until the image becomes clear.
  3. Plug in the PixyCam. The camera feed should begin streaming. Make sure the option for cooked video is set (the chef button on the top bar, next to the raw meat symbol and setting).
  4. Configure the communication interface. Note this is different for PixyCam for LEGO. See Dennis’ post.  (Configure -> Interface. Set data out protocol to UART and baud rate to 115200).
  5. Configure the colors. Point your camera at a color you wish to detect. Action -> set signature x. Drag the area of the color on the now frozen image. You can set one color per signature.

RobotC Drivers

Go to, click clone or download and download as zip. Extract the contents into the directory of your RobotC project. The relevant header is mindsensors-nxtcam.h. To include the driver, use “#include “robotcdriversuite-master/include/mindsensors-nxtcam.h””, which points to the path of the file.


See the sample code located in robotcdriversuite-master/examples/mindsensors-nxtcam-test1.c.

First, include the library, from there you must initialize the camera. Define a camera object of type tSensors and the value being the sensor port. For example, “tSensors cam = S1;”. From there simply call “NXTCAMinit(cam);”.

To get the blobs, you must first declare a variable of type blob_array (“blob_array blobs;”), which you pass to the function “nblobs = NXTCAMgetBlobs(cam, blobs, condensed);”, where if condenser is true then the colliding blobs will be combined.

Each element in a blob_array is of type blob, and has the following variables: x1 (the left bound), y1 (the upper bound), x2 (the right bound), y2 (the bottom bound), colour (the signature number), and size.

There are also a number of auxiliary functions that can help with blob analysis, such as NXTCAMgetAverageCenter, which can be found in the header file that was included.

A brief sample code has been provided below that initializes a camera and continually grabs the blobs and prints out the location and size of the biggest blob.

#include “robotcdriversuite-master/include/mindsensors-nxtcam.h”

task main()
   tSensors cam = S1;
   blob_array blobs;
   bool condensed = true;
   while (true)
       short nblobs = NXTCAMgetBlobs(cam, blobs, condensed);
       if (nblobs > 0)
           _sortBlobs(nblobs, blobs);
           // blobs[0] is now the largest blob.
           displayTextLine(1, “Number of blobs: %d”, nblobs);
           displayTextLine(3, “Top left: (%d, %d)”, blobs[0].x1, blobs[0].y1);
           displayTextLine(5, “Bottom right: (%d, %d)”, blobs[0].x2, blobs[0].y2);
           displayTextLine(7, “Colour: %d”, blobs[0].colour);
           displayTextLine(9, “Size: %d”, blobs[0].size);

Pixy for LEGO

Firstly, for setup, when configuring the interface the actions are different. Make sure the interface is set to LEGO I2C, not UART.

When programming the Pixy for LEGO, use the LEGO I2C functions. Documentation on the I2C registers can be found here: Documenation on RobotC I2C functions can be found here:

An example code is below (has not yet been tested so it may not work exactly as expected):

#include “robotcdriversuite-master/include/common.h”
tByteArray msg;
tByteArray reply;

// “port” is just the sensor port, “reg” is the register you want info for (0x50 for general, 0x51 – 0x57 for specific signatures — see documentation). The information you get back will be in the array “msg”.
bool getInfo(tSensors port, ubyte reg)
   short replyLen;
   if (reg == 0x50)
       replyLen = 6;
  else if (reg >= 0x51 && reg <= 0x57)
       replyLen = 5;
       return false;
   memset(msg, 0, sizeof(msg));
   msg[0] = reg;
   bool result = writeI2C(port, msg, reply, replyLen);
   return result;

Full Video