blob: 5194b61857d90dc1a28d8517a2dd7bf2b9a077bd [file] [log] [blame]
Philip Howard554b5422013-03-28 00:00:18 +00001WARNING: 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 Howard567ee002013-03-27 22:22:00 +00005
6WiringPi: An implementation of most of the Arduino Wiring
7 functions for the Raspberry Pi
8
Philip Howard0429f1f2013-03-27 22:26:03 +00009WiringPi2: WiringPi version 2 implements new functions for managing IO expanders.
10
Philip Howardb1169c82013-03-27 23:08:14 +000011Testing:
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 Howard567ee002013-03-27 22:22:00 +000015Prerequisites:
16 You must have python-dev and python-setuptools installed
17 If you manually rebuild the bindings with swig -python wiringpi.i
Philip Howard567ee002013-03-27 22:22:00 +000018
19Get/setup repo:
Philip Howard0429f1f2013-03-27 22:26:03 +000020 git clone https://github.com/Gadgetoid/WiringPi2-Python.git
Philip Howardfb7c8912013-03-27 22:48:19 +000021 cd WiringPi2-Python
Philip Howard567ee002013-03-27 22:22:00 +000022
23Build & install with:
24 sudo python setup.py install
25
Philip Howardfb7c8912013-03-27 22:48:19 +000026Or Python 3
27 sudo python3 setup.py install
28
Philip Howard567ee002013-03-27 22:22:00 +000029Class-based Usage:
Philip Howard0429f1f2013-03-27 22:26:03 +000030 No classes have been created for this version yet.
Philip Howard567ee002013-03-27 22:22:00 +000031
32Usage:
Philip Howardb1169c82013-03-27 23:08:14 +000033 import wiringpi2
Philip Howarde1a81e12013-09-15 12:21:15 +010034 wiringpi2.wiringPiSetup() // For sequential pin numbering, one of these MUST be called before using IO functions
Philip Howard567ee002013-03-27 22:22:00 +000035 OR
Philip Howarde1a81e12013-09-15 12:21:15 +010036 wiringpi2.wiringPiSetupSys() // For /sys/class/gpio with GPIO pin numbering
Philip Howard567ee002013-03-27 22:22:00 +000037 OR
Philip Howarde1a81e12013-09-15 12:21:15 +010038 wiringpi2.wiringPiSetupGpio() // For GPIO pin numbering
Philip Howard567ee002013-03-27 22:22:00 +000039
Philip Howard0429f1f2013-03-27 22:26:03 +000040 Setting up IO expanders (This example was tested on a quick2wire board with one digital IO expansion board connected via I2C):
Philip Howardb1169c82013-03-27 23:08:14 +000041 wiringpi2.mcp23017Setup(65,0x20)
42 wiringpi2.pinMode(65,1)
43 wiringpi2.digitalWrite(65,1)
Philip Howard0429f1f2013-03-27 22:26:03 +000044
Philip Howard567ee002013-03-27 22:22:00 +000045 General IO:
Philip Howardb1169c82013-03-27 23:08:14 +000046 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 Howard567ee002013-03-27 22:22:00 +000049
50 Bit shifting:
Philip Howardb1169c82013-03-27 23:08:14 +000051 wiringpi2.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
Philip Howard567ee002013-03-27 22:22:00 +000052
53 Serial:
Philip Howardb1169c82013-03-27 23:08:14 +000054 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 Howard567ee002013-03-27 22:22:00 +000057
58Full details at:
Philip Howard0429f1f2013-03-27 22:26:03 +000059 http://www.wiringpi.com