====== Using the Python API on Linux ====== ====== Introduction ====== Pixy now has a Python wrapper for libpixyusb. For now, this is only available for Linux-based controllers (e.g. Raspberry Pi, BeagleBone). The [[wiki:v1: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. This procedure assumes the following: * Your system is Linux (with Debian package manager) * Pixy firmware has been updated to 1.0.2 or higher * Your system is connected to the internet (for getting packages) Instructions for updating the Pixy firmware are here: [[wiki:v1:Uploading_New_Firmware|Uploading New Firmware]] ====== 2. Procedure ====== ===== 2.1. Install dependencies for building Python SWIG module ===== Start a terminal application. ==== 2.1.1. Install SWIG ==== In a terminal window type: ''%%# sudo apt-get install swig%%'' ==== 2.1.2. Install libusb-1.0-0-dev ==== In the terminal window type: ''%%sudo apt-get install libusb-1.0-0-dev%%'' ==== 2.1.3. Install g++ (compiler) ==== In the terminal window type: ''%%sudo apt-get install g++%%'' ==== 2.1.4. Install libboost ==== In the terminal window type: ''%%sudo apt-get install libboost-all-dev%%'' ===== 2.2. Build the libpixyusb Python module ===== ==== 2.2.1 Download Pixy source code ==== In the terminal window type: ''%%git clone https://github.com/charmedlabs/pixy.git%%'' ==== 2.2.2. Build the Python module ==== In the terminal window type: ''%%cd pixy/scripts%%''\\ ''%%./build_libpixyusb_swig.sh%%'' ===== 2.3. Try it out! ===== Make sure your Pixy is connected to a USB port on your computer. Then in the terminal window type: ''%%cd ../build/libpixyusb_swig%%''\\ ''%%python get_blocks.py%%'' If all goes well, you should see blocks: ''%%Pixy Python SWIG Example -- Get Blocks%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 17 WIDTH= 43 HEIGHT= 35]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 47]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 42 HEIGHT= 46]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=220 Y= 23 WIDTH= 45 HEIGHT= 46]%%''\\ ''%%[BLOCK_TYPE=0 SIG=1 X=219 Y= 23 WIDTH= 43 HEIGHT= 46]%%'' If you don't see any block information, try running as superuser: ''%%sudo python get_blocks.py%%''