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