Pixy Quick Links
Basics
Connecting Pixy to…
Software and Support
Basics
Connecting Pixy to…
Software and Support
Pixy is meant to talk to a microcontroller, and Pixy comes out of the box ready to talk to an Arduino. It sends block information to Arduino at 1 Mbits/second which means Pixy can send more than 6000 detected objects per second or 135 detected objects per frame (Pixy can process 50 frames per second.)
OK, to get Pixy and Arduino talking to each other, use the supplied Arduino cable to connect Pixy to your Arduino.
Next, download the Arduino library “arduinopixy-x.y.z.zip” here. Bring up the Arduino IDE and import the Pixy library by selecting Sketch➜Import Library in the Arduino IDE, and then browsing to the Pixy.zip file that you just downloaded. Next, load the “helloworld” example by selecting it in File➜Examples➜Pixy. Upload it and bring up the Serial Monitor. You should see messages printed that look similar to this:
Detected 1: block 0: sig: 1 x: 159 y: 109 width: 61 height: 61 Detected 1: block 0: sig: 1 x: 173 y: 114 width: 60 height: 61 Detected 1: block 0: sig: 1 x: 146 y: 111 width: 70 height: 65 ...
Note, this example will only print messages if Pixy is running the “default program” and an object that matches one of its color signatures is visible.
Using Pixy with Arduino is really simple. You simply include the SPI and Pixy headers:
#include <SPI.h> #include <Pixy.h>
And make a global instance of Pixy by putting this little guy outside your setup() and loop() functions:
Pixy pixy;
The API consists of one call: getBlocks()
, which returns the number of objects Pixy has detected. You can then look in the pixy.blocks[]
array for information about each detected object (one array member for each detected object.) Each array member (i
) contains the following fields:
pixy.blocks[i].signature
The signature number of the detected object (1-7)pixy.blocks[i].x
The x location of the center of the detected object (0 to 319)pixy.blocks[i].y
The y location of the center of the detected object (0 to 199)pixy.blocks[i].width
The width of the detected object (1 to 320)pixy.blocks[i].height
The height of the detected object (1 to 200)pixy.blocks[i].print()
A member function that prints the detected object information to the serial portSo it's simple to talk to Pixy with your Arduino!
Pixy will output objects that it detects through one of several interfaces that you choose, and it will do this every 20 ms. It supports SPI, I2C, UART, and analog/digital I/O through its 10-pin I/O connector. Pixy also supports USB 2.0 through its mini-USB connector. You can configure which interface Pixy uses through the configure dialog in PixyMon. The “Data out port” parameter in the “Interface” tab determines the output port.
If you hover the mouse pointer over the “Data out port” text, a help string will be displayed that describes which value corresponds to which type of port.
All serial interfaces use the same protocol. It may be helpful the refer to the Pixy's schematic.
The SPI interface operates as an SPI slave. It is designed around the Arduino's ICSP port, which doesn't have a slave select signal. The default data rate is 1 mbits/sec, but this can be increased by modifying the Pixy.h file in the Pixy Arduino library. The protocol has checksums to deal with bit errors, but bear in mind that the ribbon cable isn't shielded!
There is an Arduino example that uses I2C. Run it by selecting File➜Examples➜i2c in the Arduino IDE. You'll also need to make a special cable that connects:
When talking to more than one Pixy, you will need to configure a different I2C address for each Pixy so they don't step on each other. You can make a “multi-crimp cable”, meaning you can take a 10-conductor ribbon cable and crimp N 10-pin IDC connectors to it and plug into to your N Pixys. That is, when selecting I2C as an interface, all signals on Pixy's I/O connector go into a high-impedance state and won't interfere with each other, waste power, etc.
There is an Arduino example that uses UART serial. Run it by selecting File➜Examples➜uart in the Arduino IDE. You'll also need to make a special cable that connects:
Pixy has a single analog (DAC) output, so there are two modes for analog/digital output. Mode 3 outputs the x value of the center of the biggest detected object to pin 3 of the I/O connector. Mode 4 outputs the y value of the biggest detected object to pin 3 of the I/O connector. Pin 1 goes high (3.3V) when an object is detected, and low (0V) when no object is detected.