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