blob: a83cf9f864a93590116f0ef906e51f5ad39070f7 [file] [log] [blame]
Gordon Henderson183c5a62012-10-21 15:25:16 +01001.TH "GPIO" "21st October 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01002
3.SH NAME
4gpio \- Command-line access to Raspberry Pi and PiFace GPIO
5
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 Hendersonf99ffed2012-08-19 15:12:45 +010011.B [ \-g ]
Gordon Henderson25e4ec52012-12-06 21:49:41 +000012.B read/write/wb/pwm/mode ...
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010013.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010014.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010015.B [ \-p ]
Gordon Henderson25e4ec52012-12-06 21:49:41 +000016.B read/write/wb
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010017.B ...
18.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010019.B gpio
Gordon Henderson183c5a62012-10-21 15:25:16 +010020.B readall
21.PP
22.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010023.B unexportall/exports
24.PP
25.B gpio
26.B export/edge/unexport
27.B ...
28.PP
29.B gpio
30.B drive
31group value
32.PP
33.B gpio
34.B pwm-bal/pwm-ms
35.PP
36.B gpio
37.B pwmr
38range
39.PP
40.B gpio
41.B load \ i2c/spi
Gordon Henderson99095e32012-08-27 20:56:14 +010042.PP
43.B gpio
44.B gbr
45channel
46.PP
47.B gpio
48.B gbw
49channel value
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010050
51.SH DESCRIPTION
52
53.B GPIO
Gordon Henderson86a5c682012-10-02 14:32:12 +010054is a swiss army knife of a command line tool to allow the user easy
Gordon Henderson99095e32012-08-27 20:56:14 +010055access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
Gordon Henderson86a5c682012-10-02 14:32:12 +010056converters on the Gertboard. It's designed for simple testing and
Gordon Henderson99095e32012-08-27 20:56:14 +010057diagnostic purposes, but can be used in shell scripts for general if
58somewhat slow control of the GPIO pins.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010059
Gordon Henderson13bbba72013-01-14 11:31:56 +000060It can also control the IO's on the PiFace IO board and load the SPI and I2C
61kernel modules if required.
62
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010063Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
64system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
65interface without needing to be run as root.
66
67.SH OPTIONS
68
69.TP
70.B \-v
Gordon Henderson183c5a62012-10-21 15:25:16 +010071Output the current version including the board revision of the Raspberry Pi.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010072
73.TP
74.B \-g
75Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
Gordon Henderson13bbba72013-01-14 11:31:56 +000076\fINOTE:\fR The BCM_GPIO pin numbers are always used with the
77export and edge commands.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010078
79.TP
80.B \-p
81Use the PiFace interface board and its corresponding pin numbers.
82
83.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +010084.B read <pin>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010085Read the digital value of the given pin and print 0 or 1 to represent the
86respective logic levels.
87
88.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +010089.B write <pin> <value>
Gordon Henderson25e4ec52012-12-06 21:49:41 +000090Write the given value (0 or 1) to the pin. You need to set the pin
91to output mode first.
92
93.TP
94.B wb <value>
95Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
96to specify a hexadecimal number. You need to set pins to output mode
97first.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010098
99.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100100.B readall
101Output a table of all GPIO pins values. The values represent the actual values read
102if the pin is in input mode, or the last value written if the pin is in output
103mode.
104
105.TP
106.B pwm <pin> <value>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100107Write a PWM value (0-1023) to the given pin.
108
109.TP
Gordon Henderson183c5a62012-10-21 15:25:16 +0100110.B mode <pin> <mode>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100111Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
112use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
113pull-up, pull-down or tristate (off) controls.
114
115.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100116.B unexportall
117Un-Export all the GPIO pins in the /sys/class/gpio directory.
118
119.TP
120.B exports
121Print a list (if any) of all the exported GPIO pins and their current values.
122
123.TP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100124.B export
125Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
126mode command above however only \fIin\fR and \fIout\fR are supported at
127this time. Note that the pin number is the \fBBCM_GPIO\fR number and
128not the wiringPi number.
129
130Once a GPIO pin has been exported, the \fBgpio\fR program changes the
131ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
132later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
133that of the user running the \fBgpio\fR program. This means that you
134can have a small script of gpio exports to setup the gpio pins as your
135program requires without the need to run anything as root, or with the
136sudo command.
137
138.TP
139.B edge
140This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
141the direction to input and set the edge interrupt method to \fInone\fR,
142\fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
143above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
144numbering.
145
Gordon Henderson86a5c682012-10-02 14:32:12 +0100146Like the export commands above, ownership is set to that of the
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100147calling user, allowing subsequent access from user programs without
148requiring root/sudo.
149
150.TP
151.B unexport
152Un-Export a GPIO pin in the /sys/class/gpio directory.
153
154.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100155.B drive
156group value
157
158Change the pad driver value for the given pad group to the supplied drive
159value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
160absolutely sure you know what you're doing.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100161
162.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100163.B pwm-bal/pwm-ms
164Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
165
166.TP
167.B pwmr
168Change the PWM range register. The default is 1024.
169
170.TP
171.B load i2c/spi
172This loads the i2c or the spi drivers into the system and changes the permissions on
173the associated /dev/ entries so that the current user has access to them.
174
Gordon Henderson99095e32012-08-27 20:56:14 +0100175.TP
176.B gbr
177channel
178
Gordon Henderson86a5c682012-10-02 14:32:12 +0100179This reads the analog to digital converter on the Gertboard on the given
Gordon Henderson99095e32012-08-27 20:56:14 +0100180channel. The board jumpers need to be in-place to do this operation.
181
182.TP
183.B gbw
184channel value
185
186This writes the supplied value to the output channel on the Gertboards
Gordon Henderson86a5c682012-10-02 14:32:12 +0100187SPI digital to analogue converter.
Gordon Henderson99095e32012-08-27 20:56:14 +0100188The board jumpers need to be in-place to do this operation.
189
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100190
Gordon Henderson13bbba72013-01-14 11:31:56 +0000191.SH "WiringPi vs. BCM_GPIO Pin numbering"
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100192
193.PP
194.TS
Gordon Henderson86a5c682012-10-02 14:32:12 +0100195r r r l.
196WiringPi GPIO-r1 GPIO-r2 Function
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100197_
Gordon Henderson86a5c682012-10-02 14:32:12 +01001980 17 17
1991 18 18 (PWM)
2002 21 27
2013 22 22
2024 23 23
2035 24 24
2046 25 25
2057 4 4
2068 0 2 I2C: SDA0
2079 1 3 I2C: SCL0
20810 8 8 SPI: CE0
20911 7 7 SPI: CE1
21012 10 10 SPI: MOSI
21113 9 9 SPI: MISO
21214 11 11 SPI: SCLK
21315 14 14 TxD
21416 15 16 RxD
21517 - 28
21618 - 29
21719 - 30
21820 - 31
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100219.TE
220
Gordon Henderson13bbba72013-01-14 11:31:56 +0000221Note that "r1" and "r2" above refers to the board revision. Normally
222wiringPi detects the correct board revision with use for it's own
223numbering scheme, but if you are using a Revision 2 board with some
224of the pins which change numbers between revisions you will need
225to alter your software.
226
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100227.SH FILES
228
229.TP 2.2i
230.I gpio
231executable
232
233.SH EXAMPLES
234.TP 2.2i
235gpio mode 4 output # Set pin 4 to output
236.PP
237gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
238.PP
239gpio mode 1 pwm # Set pin 1 to PWM mode
240.PP
241gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
242.PP
243gpio export 17 out # Set GPIO Pin 17 to output
244.PP
245gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
246.PP
247gpio -g read 0 # Read GPIO Pin 0 (SDA0)
248
249.SH "NOTES"
250
251When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
252pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
253pin numbers.
254
255.SH "SEE ALSO"
256
257.LP
258WiringPi's home page
259.IP
260https://projects.drogon.net/raspberry-pi/wiringpi/
261
262.SH AUTHOR
263
264Gordon Henderson
265
266.SH "REPORTING BUGS"
267
Gordon Henderson183c5a62012-10-21 15:25:16 +0100268Please report bugs to <projects@drogon.net>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100269
270.SH COPYRIGHT
271
272Copyright (c) 2012 Gordon Henderson
273This is free software; see the source for copying conditions. There is NO
274warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Gordon Henderson183c5a62012-10-21 15:25:16 +0100275
276.SH TRADEMARKS AND ACKNOWLEDGEMENTS
277
278Raspberry Pi is a trademark of the Raspberry Pi Foundation.