Hooking up Pixy to a Microcontroller like an Arduino

Version 4 (Rich LeGrand, 02/19/2014 05:57 pm)

1 1 Rich LeGrand
h1. Hooking up Pixy to a Microcontroller like an Arduino
2 1 Rich LeGrand
3 3 Rich LeGrand
Pixy is meant to talk to a microcontroller, and Pixy comes out of the box ready to talk to an Arduino.  Use the supplied Arduino cable to connect Pixy to your Arduino.  
4 1 Rich LeGrand
5 1 Rich LeGrand
**
6 1 Rich LeGrand
7 4 Rich LeGrand
Download the Arduino library "Pixy.zip" "here":http://cmucam.org/projects/cmucam5/files. 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.  
8 1 Rich LeGrand
9 1 Rich LeGrand
Next, load the "hello_world" 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:
10 1 Rich LeGrand
11 2 Rich LeGrand
<pre>
12 1 Rich LeGrand
Detected 1:
13 1 Rich LeGrand
  block 0: sig: 1 x: 159 y: 109 width: 61 height: 61
14 1 Rich LeGrand
Detected 1:
15 1 Rich LeGrand
  block 0: sig: 1 x: 173 y: 114 width: 60 height: 61
16 1 Rich LeGrand
Detected 1:
17 1 Rich LeGrand
  block 0: sig: 1 x: 146 y: 111 width: 70 height: 65
18 4 Rich LeGrand
... 
19 1 Rich LeGrand
</pre>
20 3 Rich LeGrand
21 3 Rich LeGrand
Note, the example will only print messages if Pixy is running the "default program" and an object that matches one of its color signatures is visible. 
22 1 Rich LeGrand
23 3 Rich LeGrand
h3. Other Microcontrollers
24 3 Rich LeGrand
25 4 Rich LeGrand
Pixy will output objects that it detects through one of several interfaces that you choose.  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 determines the output port.  
26 3 Rich LeGrand
27 1 Rich LeGrand
**
28 1 Rich LeGrand
29 1 Rich LeGrand
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.  
30 3 Rich LeGrand
31 4 Rich LeGrand
* SPI - this is the default port that uses 3 wires (pins 1, 3, and 4 of the I/O connector) and is used to communicate with Arduino
32 4 Rich LeGrand
* I2C - this is a multi-drop 2-wire port (pins 5 and 9 of the I/O connector) that allows a single master to communicate with up to 127 slaves (up to 127 Pixys).  
33 4 Rich LeGrand
* analog/digital x - this will output the x value of the largest detected object as an analog value between 0 and 3.3V (pin 3). It also outputs whether an object is detected or not as a digital signal (pin 1 of the I/O connector).
34 4 Rich LeGrand
* analog/digital y - this will output the y value of the largest detected object as an analog value between 0 and 3.3V (pin 3). It also outputs whether an object is detected or not as a digital signal (pin 1 of the I/O connector).
35 4 Rich LeGrand
36 4 Rich LeGrand
** port picture