CMUcam5 Pixy

Color recognizing camera with servo motor control

http://i74.photobucket.com/albums/i241/cmucam/inhand_zpsb2d6b768.jpg

Notes

This is code adapted from an Arduino library for the CMUcam5 Pixy camera. The code is working for the SPI interface, and is adaptable to other interfaces (I2C, UART) if the correct handler is written. Everything is referenced from the CMU Porting Guide.

The Pixy camera supports control for 2 Servo PWM motors. The pan axis servo attaches on the left and the tilt axis servo attaches on the right:

http://i74.photobucket.com/albums/i241/cmucam/IMG_4467_zps1d3003b9.jpg

Note: Any use for the Pixy device must have defined a color for the camera to track using the Pixymon software from the device webpage. The color will change according to different lighting. It requires a simple USB connection with the same USB cable for the mbed to run the software, after which can be driven through the microcontroller.

This guide is written for an SPI connection because we did not have a 10-line wire to connect to the Pixy to test I2C. The demo code runs the "Pan/Tilt Demo" which uses 2 servos attached to the Pixy camera to follow a set signature.

SPI Pin Connections:

http://i74.photobucket.com/albums/i241/cmucam/Image140_zps87c8d289.jpg

mbedPixyExternal
5 (mosi)1 (mosi)
6 (miso)4 (miso)
7 (sck)3 (sck)
2 (5V)+5V
5 (NC)
1 (GND)6 (GND)GND

Pins looking from back of Pixy:

LeftRight
12
34
56
78
910

API

Import programPixyCamera

A demo setup of the "Pan/Tilt Demo" code. This demo code uses the default setup of the Pixy servo motor control to follow Block 0 signature defined on the Pixy camera using the PixyMon software. Demo can be found here: https://www.youtube.com/watch?v=6D5IQyrFocU https://developer.mbed.org/users/swilkins8/notebook/cmucam5-pixy/

Import libraryTPixy-Interface

A library for interfacing with the Pixy color recognition camera

User APIs

Import library

Public Member Functions

  PixySPI (SPI *spi, Serial *serialOut=NULL, uint16_t arg=PIXY_DEFAULT_ARGVAL)
  Constructor for the PixySPI class Instantiates a Pixy object that communicates via an SPI connection.
void  printBlock ( Block &block)
  Prints the given Block out to the given serial port.
uint16_t  getBlocks (uint16_t maxBlocks=1000)
  Returns the number of Blocks found in the current view and updates all Blocks' info.
int8_t  setServos (uint16_t s0, uint16_t s1)
  Sets the PWM value of the Pixy servos.
int8_t  setBrightness (uint8_t brightness)
  Sets the brightness of the Pixy RGB LED.
int8_t  setLED (uint8_t r, uint8_t g, uint8_t b)
  Sets the color of the Pixy RGB LED.
void  init ()
  Initializes the Pixy.

Import library

Public Member Functions

  TPixy ( TPixyInterface *type, Serial *serialOut=NULL, uint16_t arg=PIXY_DEFAULT_ARGVAL)
  Creates a TPixy object with a given connection handler.
void  printBlock ( Block &block)
  Prints the given Block out to the given serial port.
uint16_t  getBlocks (uint16_t maxBlocks=1000)
  Returns the number of Blocks found in the current view and updates all Blocks' info.
int8_t  setServos (uint16_t s0, uint16_t s1)
  Sets the PWM value of the Pixy servos.
int8_t  setBrightness (uint8_t brightness)
  Sets the brightness of the Pixy RGB LED.
int8_t  setLED (uint8_t r, uint8_t g, uint8_t b)
  Sets the color of the Pixy RGB LED.
void  init ()
  Initializes the Pixy.

Import library

Public Member Functions

  TPixyInterface ()
  Creates a TPixyInterface .
virtual void  init ()=0
  Initializes a TPixyInterface .
virtual int8_t  send (uint8_t *data, uint8_t len)=0
  Sends the given data to the Pixy with a given data length.
virtual void  setArg (uint16_t arg)=0
  Sets an argument for the interface to use.
virtual uint16_t  getWord ()=0
  Reads a word from the interface.
virtual uint8_t  getByte ()=0
  Reads a byte from the interface.

Demo


Report

2 comments on CMUcam5 Pixy:

20 Apr 2016

Hello!

This is a pretty cool software, thank you for publishing it. Could it be that we detected a bug in the software? We were trying to detect multiple blocks and it did not work. After we searched in your library and debugged for hours and in the end added one code line: In TPixy.h in the line 254 "w = link->getWord();" With this line we got more than one block... ;)

Best regards, Benedikt

19 Feb 2017

nice work

Please log in to post comments.