chiark / gitweb /
7da64b2f9c6b2408f85f9ec84431cbfd052c8429
[wiringPi.git] / gpio / gpio.1
1 .TH "GPIO" "14 June 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
2
3 .SH NAME
4 gpio \- Command-line access to Raspberry Pi and PiFace GPIO
5
6 .SH SYNOPSIS
7 .TP
8 .B gpio
9 .RB [ \-v ]
10 .TP
11 .B gpio
12 .RB [ \-g ]
13 .RB < read/write/pwm/mode ...>
14 .TP
15 .B gpio
16 .RB [ \-p ]
17 .RB < read/write/mode ...>
18 .TP
19 .B gpio
20 .RB < export/edge/unexport/unexportall/exports ...>
21
22 .SH DESCRIPTION
23
24 .B GPIO
25 is a command line tool to allow the user easy access to the GPIO pins
26 on the Raspberry Pi. It's designed for simple testing and diagnostic
27 purposes, but can be used in shell scripts for general if somewhat slow
28 control of the GPIO pins.
29
30 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
31 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
32 interface without needing to be run as root.
33
34 .SH OPTIONS
35
36 .TP
37 .B \-v
38 Output the current version
39
40 .TP
41 .B \-g
42 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
43
44 .TP
45 .B \-p
46 Use the PiFace interface board and its corresponding pin numbers.
47
48 .TP
49 .B read
50 Read the digital value of the given pin and print 0 or 1 to represent the
51 respective logic levels.
52
53 .TP
54 .B write
55 Write the given value (0 or 1) to the pin.
56
57 .TP
58 .B pwm
59 Write a PWM value (0-1023) to the given pin.
60
61 .TP
62 .B mode
63 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
64 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
65 pull-up, pull-down or tristate (off) controls.
66
67 .TP
68 .B export
69 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
70 mode command above however only \fIin\fR and \fIout\fR are supported at
71 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
72 not the wiringPi number.
73
74 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
75 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
76 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
77 that of the user running the \fBgpio\fR program. This means that you
78 can have a small script of gpio exports to setup the gpio pins as your
79 program requires without the need to run anything as root, or with the
80 sudo command.
81
82 .TP
83 .B edge
84 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
85 the direction to input and set the edge interrupt method to \fInone\fR,
86 \fIrising\fR, \fIfalling\fR or \fIboth\fR.  Use like the export command
87 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
88 numbering.
89
90 Like the export commands abovem ownership is set to that of the 
91 calling user, allowing subsequent access from user programs without
92 requiring root/sudo.
93
94 .TP
95 .B unexport
96 Un-Export a GPIO pin in the /sys/class/gpio directory.
97
98 .TP
99 .B unexportall
100 Un-Export all the GPIO pins in the /sys/class/gpio directory.
101
102 .TP
103 .B exports
104 Print a list (if any) of all the exported GPIO pins and their current values.
105
106 .SH "WiringPi vs. GPIO Pin numbering"
107
108 .PP
109 .TS
110 r r l.
111 WiringPi        GPIO    Function
112 _
113 0       17
114 1       18      (PWM)
115 2       21
116 3       22
117 4       23
118 5       24
119 6       25
120 7       4
121 8       0       SDA0
122 9       1       SCL0
123 10      8       SPI CE0
124 11      7       SPI CE1
125 12      10      SPI MOSI
126 13      9       SPI MISO
127 14      11      SPI SCLK
128 15      14      TxD
129 16      15      RxD
130 .TE
131
132 .SH FILES
133
134 .TP 2.2i
135 .I gpio
136 executable
137
138 .SH EXAMPLES
139 .TP 2.2i
140 gpio mode 4 output # Set pin 4 to output
141 .PP
142 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
143 .PP
144 gpio mode 1 pwm # Set pin 1 to PWM mode
145 .PP
146 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
147 .PP
148 gpio export 17 out # Set GPIO Pin 17 to output
149 .PP
150 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
151 .PP
152 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
153
154 .SH "NOTES"
155
156 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
157 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
158 pin numbers.
159
160 .SH "SEE ALSO"
161
162 .LP
163 WiringPi's home page
164 .IP
165 https://projects.drogon.net/raspberry-pi/wiringpi/
166
167 .SH AUTHOR
168
169 Gordon Henderson
170
171 .SH "REPORTING BUGS"
172
173 Report bugs to <gordon@drogon.net>
174
175 .SH COPYRIGHT
176
177 Copyright (c) 2012 Gordon Henderson
178 This is free software; see the source for copying conditions. There is NO
179 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.