Interfacing Pixy2 (PixyCam) with Arduino
Out of the box, Pixy2 is ready to talk to an Arduino. It sends block information to Arduino at 1 Mbits/second, which means Pixy2 can send more than 6000 detected objects per second or 135 detected objects per frame (Pixy2 can process 50 frames per second.)
To get Pixy2 and Arduino Uno talking to each other, use the supplied Arduino cable to connect Pixy to your Arduino Uno.
Note: if you’re using Arduino Nano, the ribbon cable faces the interior of the Nano, it doesn’t exit off the side like on the Uno (pictured).
If the cable is plugged in backwards, you won’t be able to upload to the Nano, or have serial communication with it.
Next, download the latest Arduino library from here. Bring up the Arduino IDE and import the Pixy library by selecting Sketch➜Include Library➜Add .ZIP Library… (or if you’re using an older version Sketch➜Import Library) in the Arduino IDE, and then browsing to the Arduino zip file that you just downloaded.
Next, load the “ccc_hello_world” example by selecting it in File➜Examples➜Pixy2. 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 Pixy2 is running the “default program” and an object that matches one of its color signatures is visible.
PixyMon v2
PixyMon v2 is the configuration utility for Pixy2 that runs on Windows, MacOS and Linux.
- Pixymon v2 Windows version 3.0.24
- PixyMon v2 Mac version 3.0.24 (High Sierra)
- Linux Pixymon v2 is available through github
Pixy2 firmware
Pixy2 firmware is code that runs on Pixy2 itself.
This is what PixyMon looks like when Pixy2 is running the default program and it has detected objects (you can select the default mode in PixyMon under the Action menu):
Arduino API
Using Pixy2 with Arduino is really simple. You simply include the SPI and Pixy2 headers:
#include <SPI.h> #include <Pixy2.h>
And make a global instance of Pixy2 by putting this little guy outside your setup() and loop() functions:
Pixy2 pixy;
The most important method in the Arduino library is getBlocks()
, which returns the number of objects Pixy2 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 for normal signatures)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].angle
The angle of the object detected object if the detected object is a color code.pixy.blocks[i].print()
A member function that prints the detected object information to the serial port
References