blob: ba0183f63c61a04fccd180f8894719ef2655c797 [file] [log] [blame]
Gordon Hendersonbf0ad862012-08-16 15:04:43 +01001.TH "GPIO" "14 June 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
2
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 ]
12.B read/write/pwm/mode ...
13.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010014.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010015.B [ \-p ]
16.B read/write/mode
17.B ...
18.PP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010019.B gpio
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010020.B unexportall/exports
21.PP
22.B gpio
23.B export/edge/unexport
24.B ...
25.PP
26.B gpio
27.B drive
28group value
29.PP
30.B gpio
31.B pwm-bal/pwm-ms
32.PP
33.B gpio
34.B pwmr
35range
36.PP
37.B gpio
38.B load \ i2c/spi
Gordon Henderson99095e32012-08-27 20:56:14 +010039.PP
40.B gpio
41.B gbr
42channel
43.PP
44.B gpio
45.B gbw
46channel value
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010047
48.SH DESCRIPTION
49
50.B GPIO
Gordon Henderson86a5c682012-10-02 14:32:12 +010051is a swiss army knife of a command line tool to allow the user easy
Gordon Henderson99095e32012-08-27 20:56:14 +010052access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
Gordon Henderson86a5c682012-10-02 14:32:12 +010053converters on the Gertboard. It's designed for simple testing and
Gordon Henderson99095e32012-08-27 20:56:14 +010054diagnostic purposes, but can be used in shell scripts for general if
55somewhat slow control of the GPIO pins.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +010056
57Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
58system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
59interface without needing to be run as root.
60
61.SH OPTIONS
62
63.TP
64.B \-v
65Output the current version
66
67.TP
68.B \-g
69Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
70
71.TP
72.B \-p
73Use the PiFace interface board and its corresponding pin numbers.
74
75.TP
76.B read
77Read the digital value of the given pin and print 0 or 1 to represent the
78respective logic levels.
79
80.TP
81.B write
82Write the given value (0 or 1) to the pin.
83
84.TP
85.B pwm
86Write a PWM value (0-1023) to the given pin.
87
88.TP
89.B mode
90Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
91use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
92pull-up, pull-down or tristate (off) controls.
93
94.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +010095.B unexportall
96Un-Export all the GPIO pins in the /sys/class/gpio directory.
97
98.TP
99.B exports
100Print a list (if any) of all the exported GPIO pins and their current values.
101
102.TP
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100103.B export
104Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
105mode command above however only \fIin\fR and \fIout\fR are supported at
106this time. Note that the pin number is the \fBBCM_GPIO\fR number and
107not the wiringPi number.
108
109Once a GPIO pin has been exported, the \fBgpio\fR program changes the
110ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
111later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
112that of the user running the \fBgpio\fR program. This means that you
113can have a small script of gpio exports to setup the gpio pins as your
114program requires without the need to run anything as root, or with the
115sudo command.
116
117.TP
118.B edge
119This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
120the direction to input and set the edge interrupt method to \fInone\fR,
121\fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
122above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
123numbering.
124
Gordon Henderson86a5c682012-10-02 14:32:12 +0100125Like the export commands above, ownership is set to that of the
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100126calling user, allowing subsequent access from user programs without
127requiring root/sudo.
128
129.TP
130.B unexport
131Un-Export a GPIO pin in the /sys/class/gpio directory.
132
133.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100134.B drive
135group value
136
137Change the pad driver value for the given pad group to the supplied drive
138value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
139absolutely sure you know what you're doing.
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100140
141.TP
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100142.B pwm-bal/pwm-ms
143Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
144
145.TP
146.B pwmr
147Change the PWM range register. The default is 1024.
148
149.TP
150.B load i2c/spi
151This loads the i2c or the spi drivers into the system and changes the permissions on
152the associated /dev/ entries so that the current user has access to them.
153
Gordon Henderson99095e32012-08-27 20:56:14 +0100154.TP
155.B gbr
156channel
157
Gordon Henderson86a5c682012-10-02 14:32:12 +0100158This reads the analog to digital converter on the Gertboard on the given
Gordon Henderson99095e32012-08-27 20:56:14 +0100159channel. The board jumpers need to be in-place to do this operation.
160
161.TP
162.B gbw
163channel value
164
165This writes the supplied value to the output channel on the Gertboards
Gordon Henderson86a5c682012-10-02 14:32:12 +0100166SPI digital to analogue converter.
Gordon Henderson99095e32012-08-27 20:56:14 +0100167The board jumpers need to be in-place to do this operation.
168
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100169
170.SH "WiringPi vs. GPIO Pin numbering"
171
172.PP
173.TS
Gordon Henderson86a5c682012-10-02 14:32:12 +0100174r r r l.
175WiringPi GPIO-r1 GPIO-r2 Function
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100176_
Gordon Henderson86a5c682012-10-02 14:32:12 +01001770 17 17
1781 18 18 (PWM)
1792 21 27
1803 22 22
1814 23 23
1825 24 24
1836 25 25
1847 4 4
1858 0 2 I2C: SDA0
1869 1 3 I2C: SCL0
18710 8 8 SPI: CE0
18811 7 7 SPI: CE1
18912 10 10 SPI: MOSI
19013 9 9 SPI: MISO
19114 11 11 SPI: SCLK
19215 14 14 TxD
19316 15 16 RxD
19417 - 28
19518 - 29
19619 - 30
19720 - 31
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100198.TE
199
200.SH FILES
201
202.TP 2.2i
203.I gpio
204executable
205
206.SH EXAMPLES
207.TP 2.2i
208gpio mode 4 output # Set pin 4 to output
209.PP
210gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
211.PP
212gpio mode 1 pwm # Set pin 1 to PWM mode
213.PP
214gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
215.PP
216gpio export 17 out # Set GPIO Pin 17 to output
217.PP
218gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
219.PP
220gpio -g read 0 # Read GPIO Pin 0 (SDA0)
221
222.SH "NOTES"
223
224When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
225pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
226pin numbers.
227
228.SH "SEE ALSO"
229
230.LP
231WiringPi's home page
232.IP
233https://projects.drogon.net/raspberry-pi/wiringpi/
234
235.SH AUTHOR
236
237Gordon Henderson
238
239.SH "REPORTING BUGS"
240
Gordon Hendersonf99ffed2012-08-19 15:12:45 +0100241Report bugs to <projects@drogon.net>
Gordon Hendersonbf0ad862012-08-16 15:04:43 +0100242
243.SH COPYRIGHT
244
245Copyright (c) 2012 Gordon Henderson
246This is free software; see the source for copying conditions. There is NO
247warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.