Python is a popular programming language, written on top of C. Its syntax allows programmers to write in fewer lines of code, and is easy for new programmers to learn.
Table of Contents
1. Download and install Python. Python 2.7+ and Python 3.3+ are supported.
LINUX USERS ONLY:
- You will need to install libusb-1.0. To do so, run sudo apt-get install libusb-1.0-0-dev in any terminal window.
- You will need to run a script prior to running the Hummingbird for the first time. Make it executable by typing chmod +x Configure and then run sudo ./Configure in the top level directory of the HummingbirdPython package.
2. Compiling Python Programs
Documentation of the Python Hummingbird API can be found here.
Option 1: Use IDLE to run python
Open up IDLE (Python GUI), which should be installed on your computer after installing python and open one of the example files.
Option 2: Use Terminal/Command Line to run python
- Windows: Navigate to where the python file is stored, and type your program's name with the extension (.py).
- Mac: Navigate to where the python file is stored, and type python followed by your program's name (including .py).
- Linux: Navigate to where the python file is stored, and type python followed by your program's name (including .py).
Option 3: Use interactive mode to send commands to the Hummingbird
Open Terminal/Command Prompt, navigate to the location of hummingbird.py, and type python.
Something like Python 3.3.0 (v3.3.0:, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> should pop up.
Note: If "'python' is not recognized as an internal or external command, operable program or batch file." appears, then follow the directions here to correct the PATH.
Now type the following commands: from hummingbird import Hummingbird humm = Hummingbird()
Now to access any function in the API, simply type humm.functionName()
3. Important Files and Folders
The following files and folders are common to all Hummingbird Python downloads:
hummingbird.py - The Hummingbird API source file.
hummingbirdconnection.py - Contains low level functions for sending and receiving data over USB, used by hummingbird.py
hidapi32/64.dll (Windows), libhidapi.dylib (Mac), libhidapi32/64.so (Linux) - Compiled C libraries used by hummingbirdconnection.py to scan for USB devices (specifically, the Hummingbird) and open a connection. dll files are for Windows, dylib is for OSX, and so is for Linux.
Various example programs written in python using pyhumm.py:
- cricketexample.py - Chirps with vibration motor based on the temperature
- driverexample.py - Spins the motors, speed depending on how far an object is from the distance sensor
- LEDexample.py - Adjusts the brightness of the LEDs depending on background sound levels
- hummingbirdTester.py - Tests all of the hummingbird API functions.
These lessons will introduce you to the basics of using Hummingbird lights, motors, and sensors in Python. They assume that you have some knowledge of Python, including how to use while loops, for loops, and if-else statements.
5. OS Support
The Hummingbird Python library has been tested on Windows XP 32-bit Windows 7/8 64-bit, Mac OS 10.6, and Ubuntu 12.04 with Python 2.6, 2.7, and 3.3.
6. Known Issues
We have not included 32-bit support for Mac.
We do not support XP 64-bit, but you can use the library on 64-bit XP so long as you install a 32-bit version of Python.
On a Mac, you must search for the libhidapi64.dylib and libhidapi32.dylib libraries and copy them into the Mac's /usr/local/lib directory. To find this directory, select Go/Go to Folder in the Finder. If the directory does not exist, you can create it in Terminal with the following command: sudo mkdir /usr/local/lib