Building libpixyusb as a Python module on Linux

Version 6 (Jesse French, 02/13/2015 02:24 pm)

1 5 Rich LeGrand
h1. Using the Python API on Linux
2 1 John Leimon
3 1 John Leimon
h1. Introduction
4 1 John Leimon
5 6 Jesse French
Pixy now has a Python wrapper for libpixyusb.  For now, this is only available for Linux-based controllers (e.g. Raspberry Pi, BeagleBone).  The [[Building the libpixyusb example on Linux|libpixyusb]] library provides a software application programming interface (API) for communicating with Pixy over USB. The following procedure will outline the steps to build libpixyusb as a Python module.
6 1 John Leimon
7 1 John Leimon
This procedure assumes the following:
8 1 John Leimon
9 1 John Leimon
* Your system is Linux (with Debian package manager)
10 6 Jesse French
* Pixy firmware has been updated to 1.0.2 or higher
11 2 Rich LeGrand
* Your system is connected to the internet (for getting packages)
12 1 John Leimon
13 1 John Leimon
Instructions for updating the Pixy firmware are here: [[Uploading New Firmware]]
14 1 John Leimon
15 1 John Leimon
h1. 2. Procedure
16 1 John Leimon
17 1 John Leimon
h2. 2.1. Install dependencies for building Python SWIG module
18 1 John Leimon
19 1 John Leimon
Start a terminal application.
20 1 John Leimon
21 1 John Leimon
h3. 2.1.1. Install SWIG
22 1 John Leimon
23 1 John Leimon
In a terminal window type:
24 1 John Leimon
25 1 John Leimon
@# sudo apt-get install swig@
26 1 John Leimon
27 1 John Leimon
h3. 2.1.2. Install libusb-1.0-0-dev
28 1 John Leimon
29 1 John Leimon
In the terminal window type:
30 1 John Leimon
31 1 John Leimon
@sudo apt-get install libusb-1.0-0-dev@
32 1 John Leimon
33 1 John Leimon
h3. 2.1.3. Install g++ (compiler)
34 1 John Leimon
35 1 John Leimon
In the terminal window type:
36 1 John Leimon
37 1 John Leimon
@sudo apt-get install g++@
38 1 John Leimon
39 1 John Leimon
h3. 2.1.4. Install libboost
40 1 John Leimon
41 1 John Leimon
In the terminal window type:
42 1 John Leimon
43 1 John Leimon
@sudo apt-get install libboost-all-dev@
44 1 John Leimon
45 1 John Leimon
h2. 2.2. Build the libpixyusb Python module
46 1 John Leimon
47 1 John Leimon
h3. 2.2.1 Download Pixy source code
48 1 John Leimon
49 1 John Leimon
In the terminal window type:
50 1 John Leimon
51 1 John Leimon
@git clone https://github.com/charmedlabs/pixy.git@
52 1 John Leimon
53 1 John Leimon
h3. 2.2.2. Build the Python module
54 1 John Leimon
55 1 John Leimon
In the terminal window type:
56 1 John Leimon
57 1 John Leimon
@cd pixy/scripts@
58 1 John Leimon
@./build_libpixyusb_swig.sh@
59 1 John Leimon
60 1 John Leimon
h2. 2.3. Try it out!
61 1 John Leimon
62 1 John Leimon
Make sure your Pixy is connected to a USB port on your computer. Then in the terminal window type:
63 1 John Leimon
64 1 John Leimon
@cd ../build/libpixyusb_swig@
65 1 John Leimon
@python get_blocks.py@
66 1 John Leimon
67 1 John Leimon
If all goes well, you should see blocks:
68 1 John Leimon
69 1 John Leimon
@Pixy Python SWIG Example -- Get Blocks@
70 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 17 WIDTH= 43 HEIGHT= 35]@
71 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]@
72 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]@
73 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]@
74 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 46]@
75 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 45 HEIGHT= 46]@
76 1 John Leimon
@[BLOCK_TYPE=0 SIG=1 X=219 Y= 23 WIDTH= 43 HEIGHT= 46]@