Philip Howard | fa09d18 | 2013-04-01 21:11:00 +0000 | [diff] [blame^] | 1 | ====== |
| 2 | WiringPi 2 for Python |
| 3 | ====== |
| 4 | |
| 5 | WARNING: This is an in-development library, it will not be bug free and fully featured. |
| 6 | ====== |
| 7 | |
| 8 | Please tweet @gadgetoid, find Gadgetoid in IRC, email Phil at Gadgetoid dot com, |
| 9 | or visit http://pi.gadgetoid.com/post/039-wiringpi-version-2-with-extra-python and |
| 10 | comment if you have any problems, suggestions, questions or words of support. |
| 11 | |
| 12 | WiringPi: An implementation of most of the Arduino Wiring |
| 13 | functions for the Raspberry Pi |
| 14 | |
| 15 | WiringPi2: WiringPi version 2 implements new functions for managing IO expanders. |
| 16 | |
| 17 | Testing: |
| 18 | ======== |
| 19 | Build with gcc version 4.6.3 (Debian 4.6.3-14+rpi1) |
| 20 | Built against Python 2.7.2, Python 3.2.3 |
| 21 | |
| 22 | Prerequisites: |
| 23 | ============== |
| 24 | You must have python-dev and python-setuptools installed |
| 25 | If you manually rebuild the bindings with swig -python wiringpi.i |
| 26 | |
| 27 | Get/setup repo: |
| 28 | =============== |
| 29 | git clone https://github.com/Gadgetoid/WiringPi2-Python.git |
| 30 | cd WiringPi2-Python |
| 31 | |
| 32 | Build & install with: |
| 33 | ===================== |
| 34 | sudo python setup.py install |
| 35 | |
| 36 | Or Python 3 |
| 37 | sudo python3 setup.py install |
| 38 | |
| 39 | Class-based Usage: |
| 40 | ================== |
| 41 | Description incoming! |
| 42 | |
| 43 | Usage: |
| 44 | ====== |
| 45 | import wiringpi2 |
| 46 | wiringpi2.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions |
| 47 | OR |
| 48 | wiringpi2.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering |
| 49 | OR |
| 50 | wiringpi2.wiringPiSetupGpio // For GPIO pin numbering |
| 51 | |
| 52 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): |
| 53 | wiringpi2.mcp23017Setup(65,0x20) |
| 54 | wiringpi2.pinMode(65,1) |
| 55 | wiringpi2.digitalWrite(65,1) |
| 56 | |
| 57 | General IO: |
| 58 | ----------- |
| 59 | wiringpi2.pinMode(1,1) // Set pin 1 to output |
| 60 | wiringpi2.digitalWrite(1,1) // Write 1 HIGH to pin 1 |
| 61 | wiringpi2.digitalRead(1) // Read pin 1 |
| 62 | |
| 63 | Bit shifting: |
| 64 | ------------- |
| 65 | wiringpi2.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 |
| 66 | |
| 67 | Serial: |
| 68 | ------- |
| 69 | serial = wiringpi2.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID |
| 70 | wiringpi2.serialPuts(serial,"hello") |
| 71 | wiringpi2.serialClose(serial) // Pass in ID |
| 72 | |
| 73 | Full details at: |
| 74 | ---------------- |
| 75 | http://www.wiringpi.com |