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