blob: 730046669391da7bc7fb5bd63c119c8266599133 [file] [log] [blame]
Gordon Hendersonda384432013-05-13 19:43:26 +01001.TH "GPIO" "March 2013" "Command-Line access to Raspberry Pi's GPIO"
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01002
3.SH NAME
Gordon Hendersonda384432013-05-13 19:43:26 +01004gpio \- Command-line access to Raspberry Pi's GPIO
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01005
6.SH SYNOPSIS
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01007.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +01008.B \-v
9.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010010.B gpio
Gordon Hendersonda384432013-05-13 19:43:26 +010011.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 ...
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010017.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010018.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010019.B [ \-p ]
Gordon Henderson25e4ec52012-12-06 21:49:41 +000020.B read/write/wb
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010021.B ...
22.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010023.B gpio
Gordon Hendersonda384432013-05-13 19:43:26 +010024.B readall/reset
Gordon Henderson183c5a62012-10-21 15:25:16 +010025.PP
26.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010027.B unexportall/exports
28.PP
29.B gpio
30.B export/edge/unexport
31.B ...
32.PP
33.B gpio
Gordon Hendersonda384432013-05-13 19:43:26 +010034.B wfi
35.B ...
36.PP
37.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010038.B drive
39group value
40.PP
41.B gpio
42.B pwm-bal/pwm-ms
43.PP
44.B gpio
45.B pwmr
46range
47.PP
48.B gpio
Gordon Hendersone8f62582013-01-28 13:00:47 +000049.B load \ i2c/spi ...
Gordon Henderson99095e32012-08-27 20:56:14 +010050.PP
51.B gpio
52.B gbr
53channel
54.PP
55.B gpio
56.B gbw
57channel value
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010058
59.SH DESCRIPTION
60
61.B GPIO
Gordon Henderson86a5c682012-10-02 14:32:12 +010062is a swiss army knife of a command line tool to allow the user easy
Gordon Henderson99095e32012-08-27 20:56:14 +010063access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
Gordon Henderson86a5c682012-10-02 14:32:12 +010064converters on the Gertboard. It's designed for simple testing and
Gordon Henderson99095e32012-08-27 20:56:14 +010065diagnostic purposes, but can be used in shell scripts for general if
66somewhat slow control of the GPIO pins.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010067
Gordon Henderson13bbba72013-01-14 11:31:56 +000068It can also control the IO's on the PiFace IO board and load the SPI and I2C
69kernel modules if required.
70
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010071Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
72system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
73interface without needing to be run as root.
74
75.SH OPTIONS
76
77.TP
78.B \-v
Gordon Henderson183c5a62012-10-21 15:25:16 +010079Output the current version including the board revision of the Raspberry Pi.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010080
81.TP
82.B \-g
83Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
Gordon Hendersonda384432013-05-13 19:43:26 +010084\fINote:\fR The BCM_GPIO pin numbers are always used with the
Gordon Henderson13bbba72013-01-14 11:31:56 +000085export and edge commands.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010086
87.TP
Gordon Hendersonda384432013-05-13 19:43:26 +010088.B \-1
89Use 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
91use pins on the Revision 2 P5 connector this way, and as with \-g the
92BCM_GPIO pin numbers are always used with the export and edge commands.
93
94.TP
95.B \-x extension
96This causes the named extension to be initialised. Extensions
97comprise of a name (e.g. mcp23017) followed by a colon, then the
98pin-base, then more optional parameters depending on the extension type.
99See the web page on http://wiringpi.com/the-gpio-utility/
100
101.TP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100102.B \-p
Gordon Hendersonda384432013-05-13 19:43:26 +0100103Use the PiFace interface board and its corresponding pin numbers. The PiFace
104will always appear at pin number 200 in the gpio command. You can assign any
105pin numbers you like in your own programs though.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100106
107.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100108.B read <pin>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100109Read the digital value of the given pin and print 0 or 1 to represent the
110respective logic levels.
111
112.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100113.B write <pin> <value>
Gordon Henderson25e4ec52012-12-06 21:49:41 +0000114Write the given value (0 or 1) to the pin. You need to set the pin
115to output mode first.
116
117.TP
Gordon Henderson05e2f672014-05-20 11:43:07 +0100118.B aread <pin>
119Read the analog value of the given pin. This needs to be uses in
120conjunction with a -x flag to add in an extension that handles analog
121inputs. respective logic levels.
122
123e.g. gpio -x mcp3002:200:0 aread 200
124
125will read the first analog input on an mcp3002 SPI ADC chip.
126
127.TP
128.B awrite <pin> <value>
129Write the analog value to the given pin. This needs to be used in
130conjunction with a -x flag to add in an extension that handles analog
131inputs. respective logic levels.
132
133e.g. gpio -x mcp4802:200:0 awrite 200 128
134
135will write the value 128 to the first DAC port on an mcp4802 chip on
136the Pi's SPI bus 0.
137
138
139.TP
Gordon Henderson25e4ec52012-12-06 21:49:41 +0000140.B wb <value>
141Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
142to specify a hexadecimal number. You need to set pins to output mode
143first.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100144
145.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100146.B readall
147Output a table of all GPIO pins values. The values represent the actual values read
148if the pin is in input mode, or the last value written if the pin is in output
149mode.
150
Gordon Henderson348bc732013-05-25 13:02:02 +0100151The readall command is usable with an extension module (via the -x parameter),
152but it's unable to determine pin modes or states, so will perform both a
153digital and analog read on each pin in-turn.
154
Gordon Henderson183c5a62012-10-21 15:25:16 +0100155.TP
Gordon Hendersonda384432013-05-13 19:43:26 +0100156.B reset
Gordon Henderson05e2f672014-05-20 11:43:07 +0100157Resets the GPIO - As much as it's possible to do. All pins are set to
158input mode and all the internal pull-up/down resistors are disconnected
159(tristate mode).
Gordon Hendersonda384432013-05-13 19:43:26 +0100160
Gordon Henderson348bc732013-05-25 13:02:02 +0100161The reset command is usable with an extension module (via the -x parameter),
162but it's limited to turning the pin into input mode (if applicable) and
163removing any pull up/down resistor.
164
Gordon Hendersonda384432013-05-13 19:43:26 +0100165.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100166.B pwm <pin> <value>
Gordon Henderson56c77b52013-02-01 20:19:22 +0000167Write a PWM value (0-1023) to the given pin. The pin needs to be put
168into PWM mode first.
169
170.TP
171.B clock <pin> <frequency>
172Set the output frequency on the given pin. The pin needs to be put into
173clock mode first.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100174
175.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100176.B mode <pin> <mode>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100177Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
178use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
179pull-up, pull-down or tristate (off) controls.
180
181.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100182.B unexportall
183Un-Export all the GPIO pins in the /sys/class/gpio directory.
184
185.TP
186.B exports
187Print a list (if any) of all the exported GPIO pins and their current values.
188
189.TP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100190.B export
191Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
192mode command above however only \fIin\fR and \fIout\fR are supported at
193this time. Note that the pin number is the \fBBCM_GPIO\fR number and
194not the wiringPi number.
195
196Once a GPIO pin has been exported, the \fBgpio\fR program changes the
197ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
198later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
199that of the user running the \fBgpio\fR program. This means that you
200can have a small script of gpio exports to setup the gpio pins as your
201program requires without the need to run anything as root, or with the
202sudo command.
203
204.TP
205.B edge
206This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
207the 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
209above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
210numbering.
211
Gordon Henderson86a5c682012-10-02 14:32:12 +0100212Like the export commands above, ownership is set to that of the
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100213calling user, allowing subsequent access from user programs without
214requiring root/sudo.
215
216.TP
217.B unexport
218Un-Export a GPIO pin in the /sys/class/gpio directory.
219
220.TP
Gordon Hendersonda384432013-05-13 19:43:26 +0100221.B wfi <pin> <mode>
222This set the given pin to the supplied interrupt mode: rising, falling
223or both then waits for the interrupt to happen. It's a non-busy wait,
224so does not consume and CPU while it's waiting.
225
226.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100227.B drive
228group value
229
230Change the pad driver value for the given pad group to the supplied drive
231value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
232absolutely sure you know what you're doing.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100233
234.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100235.B pwm-bal/pwm-ms
236Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
237
238.TP
239.B pwmr
240Change the PWM range register. The default is 1024.
241
242.TP
Gordon Hendersone8f62582013-01-28 13:00:47 +0000243.B load i2c [baudrate]
244This loads the i2c or drivers into the kernel and changes the permissions
245on the associated /dev/ entries so that the current user has access to
Gordon Henderson348bc732013-05-25 13:02:02 +0100246them. 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.
Gordon Hendersone8f62582013-01-28 13:00:47 +0000248
249.TP
250.B load spi [buffer size in KB]
Gordon Henderson98bcb202013-02-07 21:53:49 +0000251This loads the spi drivers into the kernel and changes the permissions
Gordon Hendersone8f62582013-01-28 13:00:47 +0000252on the associated /dev/ entries so that the current user has access to
253them. Optionally it will set the SPI buffer size to that supplied. The
254default is 4KB.
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100255
Gordon Henderson99095e32012-08-27 20:56:14 +0100256.TP
257.B gbr
258channel
259
Gordon Henderson86a5c682012-10-02 14:32:12 +0100260This reads the analog to digital converter on the Gertboard on the given
Gordon Henderson99095e32012-08-27 20:56:14 +0100261channel. The board jumpers need to be in-place to do this operation.
262
263.TP
264.B gbw
265channel value
266
267This writes the supplied value to the output channel on the Gertboards
Gordon Henderson86a5c682012-10-02 14:32:12 +0100268SPI digital to analogue converter.
Gordon Henderson99095e32012-08-27 20:56:14 +0100269The board jumpers need to be in-place to do this operation.
270
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100271
Gordon Henderson13bbba72013-01-14 11:31:56 +0000272.SH "WiringPi vs. BCM_GPIO Pin numbering"
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100273
274.PP
275.TS
Gordon Hendersonda384432013-05-13 19:43:26 +0100276c c c c l.
277WiringPi GPIO-r1 GPIO-r2 P1-Phys Function
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100278_
Gordon Hendersonda384432013-05-13 19:43:26 +0100279 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
28910 8 8 24 SPI: CE0
29011 7 7 26 SPI: CE1
29112 10 10 19 SPI: MOSI
29213 9 9 21 SPI: MISO
29314 11 11 23 SPI: SCLK
29415 14 14 8 TxD
29516 15 16 10 RxD
Gordon Henderson86a5c682012-10-02 14:32:12 +010029617 - 28
29718 - 29
29819 - 30
29920 - 31
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100300.TE
301
Gordon Henderson13bbba72013-01-14 11:31:56 +0000302Note that "r1" and "r2" above refers to the board revision. Normally
303wiringPi detects the correct board revision with use for it's own
304numbering scheme, but if you are using a Revision 2 board with some
305of the pins which change numbers between revisions you will need
306to alter your software.
307
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100308.SH FILES
309
310.TP 2.2i
311.I gpio
312executable
313
314.SH EXAMPLES
315.TP 2.2i
316gpio mode 4 output # Set pin 4 to output
317.PP
318gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
319.PP
320gpio mode 1 pwm # Set pin 1 to PWM mode
321.PP
322gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
323.PP
324gpio export 17 out # Set GPIO Pin 17 to output
325.PP
326gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
327.PP
328gpio -g read 0 # Read GPIO Pin 0 (SDA0)
329
330.SH "NOTES"
331
332When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
333pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
334pin numbers.
335
336.SH "SEE ALSO"
337
338.LP
339WiringPi's home page
340.IP
Gordon Hendersonda384432013-05-13 19:43:26 +0100341http://wiringpi.com/
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100342
343.SH AUTHOR
344
345Gordon Henderson
346
347.SH "REPORTING BUGS"
348
Gordon Henderson183c5a62012-10-21 15:25:16 +0100349Please report bugs to <projects@drogon.net>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100350
351.SH COPYRIGHT
352
Gordon Hendersonda384432013-05-13 19:43:26 +0100353Copyright (c) 2012-2013 Gordon Henderson
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100354This is free software; see the source for copying conditions. There is NO
355warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Gordon Henderson183c5a62012-10-21 15:25:16 +0100356
357.SH TRADEMARKS AND ACKNOWLEDGEMENTS
358
Gordon Hendersone8f62582013-01-28 13:00:47 +0000359Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
360http://raspberrypi.org/ for full details.