chiark / gitweb /
changed to pin mode to support softPwm.
[wiringPi.git] / gpio / gpio.1
1 .TH "GPIO" "March 2013" "Command-Line access to Raspberry Pi's GPIO"
2
3 .SH NAME
4 gpio \- Command-line access to Raspberry Pi's GPIO
5
6 .SH SYNOPSIS
7 .B gpio
8 .B \-v
9 .PP
10 .B gpio
11 .B [ \-g | \-1 ]
12 .B mode/read/write/aread/awrite/wb/pwm/clock ...
13 .PP
14 .B gpio
15 .B [ \-x extension:params ]
16 .B mode/read/write/aread/awrite/pwm ...
17 .PP
18 .B gpio
19 .B [ \-p ]
20 .B read/write/wb
21 .B ...
22 .PP
23 .B gpio
24 .B readall/reset
25 .PP
26 .B gpio
27 .B unexportall/exports
28 .PP
29 .B gpio
30 .B export/edge/unexport
31 .B ...
32 .PP
33 .B gpio
34 .B wfi
35 .B ...
36 .PP
37 .B gpio
38 .B drive
39 group value
40 .PP
41 .B gpio
42 .B pwm-bal/pwm-ms
43 .PP
44 .B gpio
45 .B pwmr
46 range
47 .PP
48 .B gpio
49 .B load \ i2c/spi ...
50 .PP
51 .B gpio
52 .B gbr
53 channel
54 .PP
55 .B gpio
56 .B gbw
57 channel value
58
59 .SH DESCRIPTION
60
61 .B GPIO
62 is a swiss army knife of a command line tool to allow the user easy
63 access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
64 converters on the Gertboard. It's designed for simple testing and
65 diagnostic purposes, but can be used in shell scripts for general if
66 somewhat slow control of the GPIO pins.
67
68 It can also control the IO's on the PiFace IO board and load the SPI and I2C
69 kernel modules if required.
70
71 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
72 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
73 interface without needing to be run as root.
74
75 .SH OPTIONS
76
77 .TP
78 .B \-v
79 Output the current version including the board revision of the Raspberry Pi.
80
81 .TP
82 .B \-g
83 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
84 \fINote:\fR The BCM_GPIO pin numbers are always used with the 
85 export and edge commands.
86
87 .TP
88 .B \-1
89 Use the physical pin numbers rather than wiringPi pin numbers.
90 \fINote:\fR that this applies to the P1 connector only. It is not possible to
91 use pins on the Revision 2 P5 connector this way, and as with \-g the
92 BCM_GPIO pin numbers are always used with the export and edge commands.
93
94 .TP
95 .B \-x extension
96 This causes the named extension to be initialised. Extensions
97 comprise of a name (e.g. mcp23017) followed by a colon, then the
98 pin-base, then more optional parameters depending on the extension type.
99 See the web page on http://wiringpi.com/the-gpio-utility/
100
101 .TP
102 .B \-p
103 Use the PiFace interface board and its corresponding pin numbers. The PiFace
104 will always appear at pin number 200 in the gpio command. You can assign any
105 pin numbers you like in your own programs though.
106
107 .TP
108 .B read <pin>
109 Read the digital value of the given pin and print 0 or 1 to represent the
110 respective logic levels.
111
112 .TP
113 .B write <pin> <value>
114 Write the given value (0 or 1) to the pin. You need to set the pin
115 to output mode first.
116
117 .TP
118 .B aread <pin>
119 Read the analog value of the given pin. This needs to be uses in
120 conjunction with a -x flag to add in an extension that handles analog
121 inputs.  respective logic levels.
122
123 e.g. gpio -x mcp3002:200:0 aread 200
124
125 will read the first analog input on an mcp3002 SPI ADC chip.
126
127 .TP
128 .B awrite <pin> <value>
129 Write the analog value to the given pin. This needs to be used in
130 conjunction with a -x flag to add in an extension that handles analog
131 inputs.  respective logic levels.
132
133 e.g. gpio -x mcp4802:200:0 awrite 200 128
134
135 will write the value 128 to the first DAC port on an mcp4802 chip on
136 the Pi's SPI bus 0.
137
138
139 .TP
140 .B wb <value>
141 Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
142 to specify a hexadecimal number. You need to set pins to output mode
143 first.
144
145 .TP
146 .B readall
147 Output a table of all GPIO pins values. The values represent the actual values read
148 if the pin is in input mode, or the last value written if the pin is in output
149 mode.
150
151 The readall command is usable with an extension module (via the -x parameter),
152 but it's unable to determine pin modes or states, so will perform both a
153 digital and analog read on each pin in-turn.
154
155 .TP
156 .B reset
157 Resets the GPIO - As much as it's possible to do. All pins are set to
158 input mode and all the internal pull-up/down resistors are disconnected
159 (tristate mode).
160
161 The reset command is usable with an extension module (via the -x parameter),
162 but it's limited to turning the pin into input mode (if applicable) and
163 removing any pull up/down resistor.
164
165 .TP
166 .B pwm <pin> <value>
167 Write a PWM value (0-1023) to the given pin. The pin needs to be put
168 into PWM mode first.
169
170 .TP
171 .B clock <pin> <frequency>
172 Set the output frequency on the given pin. The pin needs to be put into
173 clock mode first.
174
175 .TP
176 .B mode <pin> <mode>
177 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
178 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
179 pull-up, pull-down or tristate (off) controls.
180
181 .TP
182 .B unexportall
183 Un-Export all the GPIO pins in the /sys/class/gpio directory.
184
185 .TP
186 .B exports
187 Print a list (if any) of all the exported GPIO pins and their current values.
188
189 .TP
190 .B export
191 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
192 mode command above however only \fIin\fR and \fIout\fR are supported at
193 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
194 not the wiringPi number.
195
196 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
197 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
198 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
199 that of the user running the \fBgpio\fR program. This means that you
200 can have a small script of gpio exports to setup the gpio pins as your
201 program requires without the need to run anything as root, or with the
202 sudo command.
203
204 .TP
205 .B edge
206 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
207 the direction to input and set the edge interrupt method to \fInone\fR,
208 \fIrising\fR, \fIfalling\fR or \fIboth\fR.  Use like the export command
209 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
210 numbering.
211
212 Like the export commands above, ownership is set to that of the 
213 calling user, allowing subsequent access from user programs without
214 requiring root/sudo.
215
216 .TP
217 .B unexport
218 Un-Export a GPIO pin in the /sys/class/gpio directory.
219
220 .TP
221 .B wfi <pin> <mode>
222 This set the given pin to the supplied interrupt mode: rising, falling
223 or both then waits for the interrupt to happen. It's a non-busy wait,
224 so does not consume and CPU while it's waiting.
225
226 .TP
227 .B drive
228 group value
229
230 Change the pad driver value for the given pad group to the supplied drive
231 value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
232 absolutely sure you know what you're doing.
233
234 .TP
235 .B pwm-bal/pwm-ms 
236 Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
237
238 .TP
239 .B pwmr
240 Change the PWM range register. The default is 1024.
241
242 .TP
243 .B load i2c [baudrate]
244 This loads the i2c or drivers into the kernel and changes the permissions
245 on the associated /dev/ entries so that the current user has access to
246 them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
247 (or as close as the Pi can manage) The default speed is 100Kb/sec.
248
249 .TP
250 .B load spi [buffer size in KB]
251 This loads the spi drivers into the kernel and changes the permissions
252 on the associated /dev/ entries so that the current user has access to
253 them. Optionally it will set the SPI buffer size to that supplied. The
254 default is 4KB.
255
256 .TP
257 .B gbr
258 channel
259
260 This reads the analog to digital converter on the Gertboard on the given
261 channel. The board jumpers need to be in-place to do this operation.
262
263 .TP
264 .B gbw
265 channel value
266
267 This writes the supplied value to the output channel on the Gertboards
268 SPI digital to analogue converter.
269 The board jumpers need to be in-place to do this operation.
270
271
272 .SH "WiringPi vs. BCM_GPIO Pin numbering"
273
274 .PP
275 .TS
276 c c c c l.
277 WiringPi        GPIO-r1 GPIO-r2 P1-Phys Function
278 _
279  0      17      17      11      
280  1      18      18      12      (PWM)
281  2      21      27      13
282  3      22      22      15
283  4      23      23      16
284  5      24      24      18
285  6      25      25      22
286  7      4       4       7
287  8      0       2       3       I2C: SDA0
288  9      1       3       5       I2C: SCL0
289 10      8       8       24      SPI: CE0
290 11      7       7       26      SPI: CE1
291 12      10      10      19      SPI: MOSI
292 13      9       9       21      SPI: MISO
293 14      11      11      23      SPI: SCLK
294 15      14      14      8       TxD
295 16      15      16      10      RxD
296 17      -       28
297 18      -       29
298 19      -       30
299 20      -       31
300 .TE
301
302 Note that "r1" and "r2" above refers to the board revision. Normally
303 wiringPi detects the correct board revision with use for it's own
304 numbering scheme, but if you are using a Revision 2 board with some
305 of the pins which change numbers between revisions you will need
306 to alter your software.
307
308 .SH FILES
309
310 .TP 2.2i
311 .I gpio
312 executable
313
314 .SH EXAMPLES
315 .TP 2.2i
316 gpio mode 4 output # Set pin 4 to output
317 .PP
318 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
319 .PP
320 gpio mode 1 pwm # Set pin 1 to PWM mode
321 .PP
322 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
323 .PP
324 gpio export 17 out # Set GPIO Pin 17 to output
325 .PP
326 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
327 .PP
328 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
329
330 .SH "NOTES"
331
332 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
333 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
334 pin numbers.
335
336 .SH "SEE ALSO"
337
338 .LP
339 WiringPi's home page
340 .IP
341 http://wiringpi.com/
342
343 .SH AUTHOR
344
345 Gordon Henderson
346
347 .SH "REPORTING BUGS"
348
349 Please report bugs to <projects@drogon.net>
350
351 .SH COPYRIGHT
352
353 Copyright (c) 2012-2013 Gordon Henderson
354 This is free software; see the source for copying conditions. There is NO
355 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
356
357 .SH TRADEMARKS AND ACKNOWLEDGEMENTS
358
359 Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
360 http://raspberrypi.org/ for full details.