blob: d3bb11b75553e900d47646b321b8553e015412bc [file] [log] [blame]
Philip Howard567ee002013-03-27 22:22:00 +00001
2WiringPi: An implementation of most of the Arduino Wiring
3 functions for the Raspberry Pi
4
5Prerequisites:
6 You must have python-dev and python-setuptools installed
7 If you manually rebuild the bindings with swig -python wiringpi.i
8 then cat wiringpi_class.py >> wiringpi.py to get the class-based wrapper
9
10Get/setup repo:
11 git clone https://github.com/WiringPi/WiringPi-Python.git
12 cd WiringPi-Python
13 git submodule update --init
14
15Build & install with:
16 sudo python setup.py install
17
18Class-based Usage:
19 import wiringpi
20 io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
21 io.pinMode(1,io.OUTPUT)
22 io.digitalWrite(1,io.HIGH)
23
24 GPIO with /sys/class/gpio (You must first export the interfaces):
25 import wiringpi
26 io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
27 io.pinMode(1,io.OUTPUT)
28 io.digitalWrite(1,io.HIGH)
29
30 Serial:
31 serial = wiringpi.Serial('/dev/ttyAMA0',9600)
32 serial.puts("hello")
33 serial.close()
34
35Usage:
36 import wiringpi
37 wiringpi.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions
38 OR
39 wiringpi.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering
40 OR
41 wiringpi.wiringPiSetupGpio // For GPIO pin numbering
42
43 General IO:
44 wiringpi.pinMode(1,1) // Set pin 1 to output
45 wiringpi.digitalWrite(1,1) // Write 1 HIGH to pin 1
46 wiringpi.digitalRead(1) // Read pin 1
47
48 Bit shifting:
49 wiringpi.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
50
51 Serial:
52 serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID
53 wiringpi.serialPuts(serial,"hello")
54 wiringpi.serialClose(serial) // Pass in ID
55
56Full details at:
57 https://projects.drogon.net/raspberry-pi/wiringpi/
58