chiark / gitweb /
Updated the GPIO command to add in new features for PWM
[wiringPi.git] / gpio / gpio.1
1 .TH "GPIO" "14 June 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/pwm/mode ...
13 .PP
14 .B gpio
15 .B [ \-p ]
16 .B read/write/mode
17 .B ...
18 .PP
19 .B gpio
20 .B unexportall/exports
21 .PP
22 .B gpio
23 .B export/edge/unexport
24 .B ...
25 .PP
26 .B gpio
27 .B drive
28 group value
29 .PP
30 .B gpio
31 .B pwm-bal/pwm-ms
32 .PP
33 .B gpio
34 .B pwmr
35 range
36 .PP
37 .B gpio
38 .B load \ i2c/spi
39
40 .SH DESCRIPTION
41
42 .B GPIO
43 is a command line tool to allow the user easy access to the GPIO pins
44 on the Raspberry Pi. It's designed for simple testing and diagnostic
45 purposes, but can be used in shell scripts for general if somewhat slow
46 control of the GPIO pins.
47
48 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
49 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
50 interface without needing to be run as root.
51
52 .SH OPTIONS
53
54 .TP
55 .B \-v
56 Output the current version
57
58 .TP
59 .B \-g
60 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
61
62 .TP
63 .B \-p
64 Use the PiFace interface board and its corresponding pin numbers.
65
66 .TP
67 .B read
68 Read the digital value of the given pin and print 0 or 1 to represent the
69 respective logic levels.
70
71 .TP
72 .B write
73 Write the given value (0 or 1) to the pin.
74
75 .TP
76 .B pwm
77 Write a PWM value (0-1023) to the given pin.
78
79 .TP
80 .B mode
81 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
82 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
83 pull-up, pull-down or tristate (off) controls.
84
85 .TP
86 .B unexportall
87 Un-Export all the GPIO pins in the /sys/class/gpio directory.
88
89 .TP
90 .B exports
91 Print a list (if any) of all the exported GPIO pins and their current values.
92
93 .TP
94 .B export
95 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
96 mode command above however only \fIin\fR and \fIout\fR are supported at
97 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
98 not the wiringPi number.
99
100 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
101 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
102 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
103 that of the user running the \fBgpio\fR program. This means that you
104 can have a small script of gpio exports to setup the gpio pins as your
105 program requires without the need to run anything as root, or with the
106 sudo command.
107
108 .TP
109 .B edge
110 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
111 the direction to input and set the edge interrupt method to \fInone\fR,
112 \fIrising\fR, \fIfalling\fR or \fIboth\fR.  Use like the export command
113 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
114 numbering.
115
116 Like the export commands abovem ownership is set to that of the 
117 calling user, allowing subsequent access from user programs without
118 requiring root/sudo.
119
120 .TP
121 .B unexport
122 Un-Export a GPIO pin in the /sys/class/gpio directory.
123
124 .TP
125 .B drive
126 group value
127
128 Change the pad driver value for the given pad group to the supplied drive
129 value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
130 absolutely sure you know what you're doing.
131
132 .TP
133 .B pwm-bal/pwm-ms 
134 Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
135
136 .TP
137 .B pwmr
138 Change the PWM range register. The default is 1024.
139
140 .TP
141 .B load i2c/spi
142 This loads the i2c or the spi drivers into the system and changes the permissions on
143 the associated /dev/ entries so that the current user has access to them.
144
145
146 .SH "WiringPi vs. GPIO Pin numbering"
147
148 .PP
149 .TS
150 r r l.
151 WiringPi        GPIO    Function
152 _
153 0       17
154 1       18      (PWM)
155 2       21
156 3       22
157 4       23
158 5       24
159 6       25
160 7       4
161 8       0       SDA0
162 9       1       SCL0
163 10      8       SPI CE0
164 11      7       SPI CE1
165 12      10      SPI MOSI
166 13      9       SPI MISO
167 14      11      SPI SCLK
168 15      14      TxD
169 16      15      RxD
170 .TE
171
172 .SH FILES
173
174 .TP 2.2i
175 .I gpio
176 executable
177
178 .SH EXAMPLES
179 .TP 2.2i
180 gpio mode 4 output # Set pin 4 to output
181 .PP
182 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
183 .PP
184 gpio mode 1 pwm # Set pin 1 to PWM mode
185 .PP
186 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
187 .PP
188 gpio export 17 out # Set GPIO Pin 17 to output
189 .PP
190 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
191 .PP
192 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
193
194 .SH "NOTES"
195
196 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
197 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
198 pin numbers.
199
200 .SH "SEE ALSO"
201
202 .LP
203 WiringPi's home page
204 .IP
205 https://projects.drogon.net/raspberry-pi/wiringpi/
206
207 .SH AUTHOR
208
209 Gordon Henderson
210
211 .SH "REPORTING BUGS"
212
213 Report bugs to <projects@drogon.net>
214
215 .SH COPYRIGHT
216
217 Copyright (c) 2012 Gordon Henderson
218 This is free software; see the source for copying conditions. There is NO
219 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.