Pixy Quick Links
Basics
Connecting Pixy to…
Software and Support
Basics
Connecting Pixy to…
Software and Support
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.
Whether you're using SPI, I2C or UART serial, the protocol is exactly the same.
Bytes 16-bit words Description ---------------------------------------------------------------- 0, 1 0 sync (0xaa55) 2, 3 1 checksum (sum of all 16-bit words 2-6) 4, 5 2 signature number 6, 7 3 x center of object 8, 9 4 y center of object 10, 11 5 width of object 12, 13 6 height of object
So, a typical way to parse the serial stream is to wait for two sync words and then start parsing the object block, using the sync words to indicate the start of the next object block, and so on. Looking at the source code for Arduino will help – all of the parsing code is there. In particular, look at TPixy.h.
Pixy 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 processes at 50 frames per second.) But it's possible that the serial link is too slow to send back all of the objects before the next frame is processed and new objects are ready to send over serial. This can especially happen with UART serial, which is typically only 19.2 kbaud (more or less). When this happens, the unsent object blocks from the previous frame are tossed and the new object blocks from the new frame are sent instead. This way, the most recent information is prioritized. And since the objects are sorted by size, the larger the object, the more priority it gets also.
You can also control Pixy's servos over SPI by sending simple little 3-word packets. Like above, each word consists of 16 bytes, little endian.
Bytes 16-bit words Description ---------------------------------------------------------------- 0, 1 0 sync (0xff00) 2, 3 1 servo 0 (pan) position, between 0 and 1000 4, 5 2 servo 1 (tilt) position, between 0 and 1000
You repeat this pattern to update the servo positions on-the-fly.