1 .TH "GPIO" "January 2015" "Command-Line access to Raspberry Pi's GPIO"
4 gpio \- Command-line access to Raspberry Pi's GPIO
12 .B mode/read/write/aread/awrite/wb/pwm/clock ...
15 .B [ \-x extension:params ]
16 .B mode/read/write/aread/awrite/pwm/pwmTone ...
20 .B read/write/toggle/wb
27 .B unexportall/exports
30 .B export/edge/unexport
66 is a swiss army knife of a command line tool to allow the user easy
67 access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
68 converters on the Gertboard. It's designed for simple testing and
69 diagnostic purposes, but can be used in shell scripts for general if
70 somewhat slow control of the GPIO pins.
72 It can also control the IO's on the PiFace IO board and load the SPI and I2C
73 kernel modules if required.
75 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
76 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
77 interface without needing to be run as root.
83 Output the current version including the board revision of the Raspberry Pi.
87 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
88 \fINote:\fR The BCM_GPIO pin numbers are always used with the
89 export and edge commands.
93 Use the physical pin numbers rather than wiringPi pin numbers.
94 \fINote:\fR that this applies to the P1 connector only. It is not possible to
95 use pins on the Revision 2 P5 connector this way, and as with \-g the
96 BCM_GPIO pin numbers are always used with the export and edge commands.
100 This causes the named extension to be initialised. Extensions
101 comprise of a name (e.g. mcp23017) followed by a colon, then the
102 pin-base, then more optional parameters depending on the extension type.
103 See the web page on http://wiringpi.com/the-gpio-utility/
107 Use the PiFace interface board and its corresponding pin numbers. The PiFace
108 will always appear at pin number 200 in the gpio command. You can assign any
109 pin numbers you like in your own programs though.
113 Read the digital value of the given pin and print 0 or 1 to represent the
114 respective logic levels.
117 .B write <pin> <value>
118 Write the given value (0 or 1) to the pin. You need to set the pin
119 to output mode first.
123 Read the analog value of the given pin. This needs to be uses in
124 conjunction with a -x flag to add in an extension that handles analog
125 inputs. respective logic levels.
127 e.g. gpio -x mcp3002:200:0 aread 200
129 will read the first analog input on an mcp3002 SPI ADC chip.
132 .B awrite <pin> <value>
133 Write the analog value to the given pin. This needs to be used in
134 conjunction with a -x flag to add in an extension that handles analog
135 inputs. respective logic levels.
137 e.g. gpio -x mcp4802:200:0 awrite 200 128
139 will write the value 128 to the first DAC port on an mcp4802 chip on
145 Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
146 to specify a hexadecimal number. You need to set pins to output mode
151 Output a table of all GPIO pins values. The values represent the actual values read
152 if the pin is in input mode, or the last value written if the pin is in output
155 The readall command is usable with an extension module (via the -x parameter),
156 but it's unable to determine pin modes or states, so will perform both a
157 digital and analog read on each pin in-turn.
161 Write a PWM value (0-1023) to the given pin. The pin needs to be put
165 .B clock <pin> <frequency>
166 Set the output frequency on the given pin. The pin needs to be put into
171 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
172 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
173 pull-up, pull-down or tristate (off) controls.
175 The ALT modes can also be set using \fIalt0\fR, \fIalt1\fR, ... \fIalt5\fR.
179 Un-Export all the GPIO pins in the /sys/class/gpio directory.
183 Print a list (if any) of all the exported GPIO pins and their current values.
187 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
188 mode command above however only \fIin\fR and \fIout\fR are supported at
189 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
190 not the wiringPi number.
192 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
193 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
194 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
195 that of the user running the \fBgpio\fR program. This means that you
196 can have a small script of gpio exports to setup the gpio pins as your
197 program requires without the need to run anything as root, or with the
202 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
203 the direction to input and set the edge interrupt method to \fInone\fR,
204 \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
205 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
208 Like the export commands above, ownership is set to that of the
209 calling user, allowing subsequent access from user programs without
214 Un-Export a GPIO pin in the /sys/class/gpio directory.
218 This set the given pin to the supplied interrupt mode: rising, falling
219 or both then waits for the interrupt to happen. It's a non-busy wait,
220 so does not consume and CPU while it's waiting.
226 Change the pad driver value for the given pad group to the supplied drive
227 value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
228 absolutely sure you know what you're doing.
234 Change the USB current limiter to high (1.2 amps) or low (the default, 600mA)
235 This is only applicable to the model B+
239 Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
243 Change the PWM range register. The default is 1024.
246 .B load i2c [baudrate]
247 This loads the i2c or drivers into the kernel and changes the permissions
248 on the associated /dev/ entries so that the current user has access to
249 them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
250 (or as close as the Pi can manage) The default speed is 100Kb/sec.
252 Note that on a Pi with a recent 3.18 kernel with the device-tree structure
253 enable, the load may fail until you add:
257 into \fB/boot/config.txt\fR to allow user use of the I2C bus.
261 This loads the spi drivers into the kernel and changes the permissions
262 on the associated /dev/ entries so that the current user has access to
263 them. It used to have the ability to change the buffer size from the
264 default of 4096 bytes to an arbitary value, however for some time the
265 Pi Foundation have compiled the SPI device driver into the kernel and
266 this has fixed the buffer size. The way to change it now is to edit
267 the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
268 e.g. 8192 bytes then reboot.
270 Note that on a Pi with a recent 3.18 kernel with the device-tree structure
271 enable, the load may fail until you add:
275 into \fB/boot/config.txt\fR to allow user use of the I2C bus.
281 This reads the analog to digital converter on the Gertboard on the given
282 channel. The board jumpers need to be in-place to do this operation.
288 This writes the supplied value to the output channel on the Gertboards
289 SPI digital to analogue converter.
290 The board jumpers need to be in-place to do this operation.
293 .SH "WiringPi vs. BCM_GPIO Pin numbering vs. Physical pin numbering"
296 The quickest way to get a list of the pin differences is to run the command
308 gpio mode 4 output # Set pin 4 to output
310 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
312 gpio mode 1 pwm # Set pin 1 to PWM mode
314 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
316 gpio export 17 out # Set GPIO Pin 17 to output
318 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
320 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
324 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
325 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
341 Please report bugs to <projects@drogon.net>
345 Copyright (c) 2012-2015 Gordon Henderson
346 This is free software; see the source for copying conditions. There is NO
347 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
349 .SH TRADEMARKS AND ACKNOWLEDGEMENTS
351 Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
352 http://raspberrypi.org/ for full details.