This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
wiki:v2:hooking_up_pixy_to_a_microcontroller_-28like_an_arduino-29 [2018/05/23 20:20] pixycam |
wiki:v2:hooking_up_pixy_to_a_microcontroller_-28like_an_arduino-29 [2020/02/26 19:41] jfrench [Troubleshooting] |
||
---|---|---|---|
Line 17: | Line 17: | ||
{{wiki:v2:img_5257_result.jpg?400}} | {{wiki:v2:img_5257_result.jpg?400}} | ||
- | Next, download the latest Arduino library "arduino\_pixy2-x.y.z.zip" [[wiki:v2:Latest_release|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, download the latest Arduino library "arduino\_pixy2-x.y.z.zip" [[https://pixycam.com/downloads-pixy2/|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: | + | Next, load the "ccc\_hello\_world" example by selecting it in **File➜Examples➜Pixy2**. Upload it and bring up the **Serial Monitor** which can be found in **Tools➜Serial Monitor**. Also be sure to set the Serial Monitor baud rate to 115200 baud, which is selectable at the bottom of the Serial Monitor window. |
+ | |||
+ | |||
+ | {{wiki:v2:image_521.png}} | ||
+ | |||
+ | |||
+ | You should see messages printed in the Serial Monitor window that look similar to this: | ||
<code> | <code> | ||
Line 47: | Line 53: | ||
<code> | <code> | ||
- | #include <SPI.h> | + | #include <Pixy2.h> |
- | #include <Pixy.h> | + | |
</code> | </code> | ||
And make a global instance of Pixy by putting this little guy outside your setup() and loop() functions: | And make a global instance of Pixy by putting this little guy outside your setup() and loop() functions: | ||
<code> | <code> | ||
- | Pixy pixy; | + | Pixy2 pixy; |
</code> | </code> | ||
- | The most important method in the Arduino library is ''%%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: | + | The most important method in the Arduino library is ''%%getBlocks()%%'', which returns the number of objects Pixy has detected. You can then look in the ''%%pixy.ccc.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.ccc.blocks[i].m_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.ccc.blocks[i].m_x%%'' The x location of the center of the detected object (0 to 316) |
- | * ''%%pixy.blocks[i].y%%'' The y location of the center of the detected object (0 to 199) | + | * ''%%pixy.ccc.blocks[i].m_y%%'' The y location of the center of the detected object (0 to 208) |
- | * ''%%pixy.blocks[i].width%%'' The width of the detected object (1 to 320) | + | * ''%%pixy.ccc.blocks[i].m_width%%'' The width of the detected object (1 to 316) |
- | * ''%%pixy.blocks[i].height%%'' The height of the detected object (1 to 200) | + | * ''%%pixy.ccc.blocks[i].m_height%%'' The height of the detected object (1 to 208) |
- | * ''%%pixy.blocks[i].angle%%'' The angle of the object detected object if the detected object is a [[wiki:v2:Using_Color_Codes|color code]]. | + | * ''%%pixy.ccc.blocks[i].m_angle%%'' The angle of the object detected object if the detected object is a [[wiki:v2:Using_Color_Codes|color code]] (-180 to 180). |
- | * ''%%pixy.blocks[i].print()%%'' A member function that prints the detected object information to the serial port | + | * ''%%pixy.ccc.blocks[i].m_index%%'' The [[wiki:v2:color_connected_components#Pixy2 "tracks" each object it detects|tracking index]] of the block |
+ | * ''%%pixy.ccc.blocks[i].m_age%%'' The number of frames the block has been tracked. | ||
+ | * ''%%pixy.ccc.blocks[i].print()%%'' A member function that prints the detected object information to the serial port | ||
- | So it's simple to talk to Pixy with your Arduino! For more information on the Arduino Library and API, go [[wiki:v2:Arduino_API|here]]. | + | |
+ | So it's simple to talk to Pixy2 with your Arduino! For more information on the Arduino Library and API, go [[wiki:v2:Arduino_API|here]]. | ||
Line 71: | Line 79: | ||
Before installing a new version of the Arduino Library, it's recommended that you delete the existing library. To do this, you can go into your C:\Users\<yourname>\Documents\Arduino\libraries (or similar directory, <yourname>/Documents/Arduino in OSX and Linux) and remove the Pixy2 directory. Then re-run the Arduino IDE. | Before installing a new version of the Arduino Library, it's recommended that you delete the existing library. To do this, you can go into your C:\Users\<yourname>\Documents\Arduino\libraries (or similar directory, <yourname>/Documents/Arduino in OSX and Linux) and remove the Pixy2 directory. Then re-run the Arduino IDE. | ||
+ | |||
+ | |||
+ | ==== Troubleshooting ==== | ||
+ | |||
+ | If you get the message "error: no response" from the Arduino serial monitor, first make sure your Pixy2 is running the ccc (color connected components) program from PixyMon, and that you have taught it an object as described [[wiki:v2:teach_pixy_an_object_2|here]]. | ||
+ | |||
+ | {{:wiki:v2:error_no_response.png?600|}} | ||
+ | |||
+ | === Zumo Errors === | ||
+ | If you're using Arduino Due, you may get an error like this when compiling: | ||
+ | ''libraries\Pixy2\ZumoBuzzer.cpp:90:5: error: expected constructor, destructor, or type conversion before '(' token'' | ||
+ | In that case, just go into your Pixy library and delete the following 4 files: | ||
+ | {{:wiki:v2:todelete.png}} | ||
+ | It should then compile! |