<< return to Pixycam.com

pixython - python wrapper for libpixyusb now working

Hi,

I borrowed a pixy camera from a local maker group earlier this week with plans to integrate it with a Raspberry Pi … to my initial dismay I discovered that there were very few tools available for working on a raspberry pi with a pixy.

I’ve coded a simple python wrapper (I am calling it pixython) that has about the same functionality as the app hello_pixy at this point. I am not sure if anything like this has been done yet? If it has please let me know as I would love to move forward more quickly on this project!

I am using this wrapper on an rPi (ver B) but assume it will work easily on linux distributions and Mac … not sure about windows.

I cloned the CMUcam5 git for libpixyusb and my working branch is called ‘pixython’. The python-enabled branch is available at:
https://github.com/DarfieldChris/pixy.git (you want the pixython branch)

I wanted to make these changes available in case anybody else is keen on a python interface on the Raspberry Pi or would like to help make one?

Chris

The output from the wrapper:

2014-09-20 15:25:46,197 - INFO - pixy: initialized connection!
2014-09-20 15:25:46,238 - INFO - pixy: FIRMWARE 0.1.44
2014-09-20 15:25:46,299 - INFO - pixy: led_set_RGB - returned 0
2014-09-20 15:25:46,340 - INFO - pixy: led max current: 700
2014-09-20 15:25:46,402 - INFO - pixy: setting max current to 1400 - returned 0
2014-09-20 15:25:46,443 - INFO - pixy: led max current now reads: 1400

Using the wrapper the python code to implement ‘hello_pixy’ looks like (reading block data is not yet implemented):

pixy = PixyInterpreter()
while ( pixy.rcodeInit < 0):
    logging.warning("pixy: failed to initialize pixy connection: (%d) - %s",
                    pixy.rcodeInit, pixy.error_str(pixy.rcodeInit))
    time.sleep(5)
    pixy.init()
logging.info("pixy: initialized connection!")

version = pixy.get_firmware_version()
logging.info("pixy: FIRMWARE %u.%u.%u", version[0], version[1], version[2])

rcode = pixy.led_set_RGB(5,5,5)
logging.info("pixy: led_set_RGB - returned %d", rcode)

rcode = pixy.led_get_max_current()
logging.info("pixy: led max current: %d", rcode)
if (rcode == 0):
    rcode = 254
else:
    rcode = rcode*2
rc = pixy.led_set_max_current(rcode)
logging.info("pixy: setting max current to %d - returned %d", rcode, rc)
rcode = pixy.led_get_max_current()
logging.info("pixy: led max current now reads: %d", rcode)
rc = pixy.led_set_max_current(700)

I should add …

My initial goal is to make a functional ‘fswebcam’-like command line tool that works for a pixy.

At this point all I am missing is the code to request and transfer an image (a snapshot) from the camera … can anybody point me in the right direction as to how this is done in pixymon?

Chris