Tutorial: Pixy (CMUcam5)

This tutorial will focus on the correct way to set up and receive information from a Pixy using an Arduino Uno.  Please note that cmucam.org also provides instructions for the Pixy in the Pixy Quick Start Guide on their WIKI.


Powering the Pixy


Pixy can be powered through the Arduino cable provided, just plug in the cable and your pixy should be good to go!


If, for some reason you decide to power the Pixy through the Vin and GND pins, be careful, these are not reverse polarity protected so you can kill the Pixy if you get the pins backwards.

Other options for powering Pixy are detailed here.

Starting up the Pixy

Apply power to Pixy to start it up.  After this one two things will happen:

If the pixy is configured to “recognize” an object, it will flash red every time that object is recognized and the pixy will send this data to the Arduino.

If the pixy wasn’t configured to recognize any object it will just go into an idle state. If you want to set a new signature, see “Programming” the Pixy.

“Programming” the Pixy


Unless you’re trying to recognize extremely complex objects and patterns, I recommend just configuring the pixy without the use of a computer.

Once the pixy is on, press and hold the button until the RGB led starts blinking in different colors. Once the seizure session stops, place the object that you want the pixy to recognize right in front of the camera (the led should be the color of the object at this point) and press the button (don’t hold it down). If the LED stops flashing, pixy has recognized your object and is now configured to recognize that object! If not, try again.


The pixy can also be loaded with signatures to recognize using the CMUcam5 software. This method may or may not work properly, depending on the firmware you have installed on the pixy. Open up pixymon, plug in the pixy, and highlight the object you want your pixy to recognize. If you want to clear or set new signatures, you can do this all through pixymon.

Configuring the Arduino

Once you have hooked up the pixy to the Arduino and configured the pixy to recognize an object, all you have to do is write the proper code to interpret the data from the pixy.

Install the Pixy Library

Download the pixy library from this link:


In the Arduino IDE, import the newly downloaded library from Sketch->Import Library.

Writing Code

We will be using the pixy API to work with the data sent over from the pixy. The pixy API makes it extremely convenient to parse the data sent over from the pixy to the Arduino.

Data is received in “blocks”, where each block represents properties of an object that was detected. Blocks can tell you how big the object is on the screen, where it is and other useful information.

Here’s a quick guide to get you started:

Start by including the headers for pixy and SPI libraries:

#include <SPI.h>

#include <Pixy.h>

Declare a pixy global like so:

Pixy pixy;

In your setup function, initialize the pixy global:


In your loop function you’re going to want to poll the pixy for recognized objects like so:

  uint16_t blocks; //size of array pixy sends

  blocks = pixy.getBlocks();

  if (blocks) // if there were any recognized objects


    //finds the largest object that fits the signature

    for (j = 0; j < blocks; j++){

      prod = pixy.blocks[j].width * pixy.blocks[j].height;

      if (prod > maxProd) //save the new largest obj

          maxJ = j;


This sample code goes through all the “blocks” (which represent objects that are found) and finds the largest block that fits the signature. This is done by checking the blocks area by multiplying the width and height. Blocks also hold more information that you can check, here’s a full list:

  • pixy.blocks[i].signature
    • signature of the object, from 1 to 7
  • pixy.blocks[i].x
    • x coordinate of the object, from 0 to 319
  • pixy.blocks[i].y
    • y coordinate of the object, from 0 to 199
  • pixy.blocks[i].width
    • width of the object, from 1 to 320
  • pixy.blocks[i].height
    • height of the object, from 1 to 200
  • pixy.blocks[i].print()
    • prints the objects received, to the serial port makes debugging easy

If all went well, your arduino should be correctly finding the proper largest object that was picked up by the pixy. To investigate code that was written for Bull, just go to the link: