Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 1 | |
| 2 | WiringPi: An implementation of most of the Arduino Wiring |
| 3 | functions for the Raspberry Pi |
| 4 | |
Philip Howard | 0429f1f | 2013-03-27 22:26:03 +0000 | [diff] [blame^] | 5 | WiringPi2: WiringPi version 2 implements new functions for managing IO expanders. |
| 6 | |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 7 | Prerequisites: |
| 8 | You must have python-dev and python-setuptools installed |
| 9 | If you manually rebuild the bindings with swig -python wiringpi.i |
| 10 | then cat wiringpi_class.py >> wiringpi.py to get the class-based wrapper |
| 11 | |
| 12 | Get/setup repo: |
Philip Howard | 0429f1f | 2013-03-27 22:26:03 +0000 | [diff] [blame^] | 13 | git clone https://github.com/Gadgetoid/WiringPi2-Python.git |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 14 | cd WiringPi-Python |
| 15 | git submodule update --init |
| 16 | |
| 17 | Build & install with: |
| 18 | sudo python setup.py install |
| 19 | |
| 20 | Class-based Usage: |
Philip Howard | 0429f1f | 2013-03-27 22:26:03 +0000 | [diff] [blame^] | 21 | No classes have been created for this version yet. |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 22 | |
| 23 | Usage: |
| 24 | import wiringpi |
| 25 | wiringpi.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions |
| 26 | OR |
| 27 | wiringpi.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering |
| 28 | OR |
| 29 | wiringpi.wiringPiSetupGpio // For GPIO pin numbering |
| 30 | |
Philip Howard | 0429f1f | 2013-03-27 22:26:03 +0000 | [diff] [blame^] | 31 | Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C): |
| 32 | wiringpi.mcp23017Setup(65,0x20) |
| 33 | wiringpi.pinMode(65,1) |
| 34 | wiringpi.digitalWrite(65,1) |
| 35 | |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 36 | General IO: |
| 37 | wiringpi.pinMode(1,1) // Set pin 1 to output |
| 38 | wiringpi.digitalWrite(1,1) // Write 1 HIGH to pin 1 |
| 39 | wiringpi.digitalRead(1) // Read pin 1 |
| 40 | |
| 41 | Bit shifting: |
| 42 | wiringpi.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2 |
| 43 | |
| 44 | Serial: |
| 45 | serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID |
| 46 | wiringpi.serialPuts(serial,"hello") |
| 47 | wiringpi.serialClose(serial) // Pass in ID |
| 48 | |
| 49 | Full details at: |
Philip Howard | 0429f1f | 2013-03-27 22:26:03 +0000 | [diff] [blame^] | 50 | http://www.wiringpi.com |