1 .TH "GPIO" "21st October 2012" "Command-Line access to Raspberry Pi and PiFace GPIO"
4 gpio \- Command-line access to Raspberry Pi and PiFace GPIO
12 .B read/write/wb/pwm/mode ...
23 .B unexportall/exports
26 .B export/edge/unexport
54 is a swiss army knife of a command line tool to allow the user easy
55 access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
56 converters on the Gertboard. It's designed for simple testing and
57 diagnostic purposes, but can be used in shell scripts for general if
58 somewhat slow control of the GPIO pins.
60 It can also control the IO's on the PiFace IO board and load the SPI and I2C
61 kernel modules if required.
63 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
64 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
65 interface without needing to be run as root.
71 Output the current version including the board revision of the Raspberry Pi.
75 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
76 \fINOTE:\fR The BCM_GPIO pin numbers are always used with the
77 export and edge commands.
81 Use the PiFace interface board and its corresponding pin numbers.
85 Read the digital value of the given pin and print 0 or 1 to represent the
86 respective logic levels.
89 .B write <pin> <value>
90 Write the given value (0 or 1) to the pin. You need to set the pin
95 Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
96 to specify a hexadecimal number. You need to set pins to output mode
101 Output a table of all GPIO pins values. The values represent the actual values read
102 if the pin is in input mode, or the last value written if the pin is in output
107 Write a PWM value (0-1023) to the given pin.
111 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
112 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
113 pull-up, pull-down or tristate (off) controls.
117 Un-Export all the GPIO pins in the /sys/class/gpio directory.
121 Print a list (if any) of all the exported GPIO pins and their current values.
125 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
126 mode command above however only \fIin\fR and \fIout\fR are supported at
127 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
128 not the wiringPi number.
130 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
131 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
132 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
133 that of the user running the \fBgpio\fR program. This means that you
134 can have a small script of gpio exports to setup the gpio pins as your
135 program requires without the need to run anything as root, or with the
140 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
141 the 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
143 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
146 Like the export commands above, ownership is set to that of the
147 calling user, allowing subsequent access from user programs without
152 Un-Export a GPIO pin in the /sys/class/gpio directory.
158 Change the pad driver value for the given pad group to the supplied drive
159 value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
160 absolutely sure you know what you're doing.
164 Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
168 Change the PWM range register. The default is 1024.
172 This loads the i2c or the spi drivers into the system and changes the permissions on
173 the associated /dev/ entries so that the current user has access to them.
179 This reads the analog to digital converter on the Gertboard on the given
180 channel. The board jumpers need to be in-place to do this operation.
186 This writes the supplied value to the output channel on the Gertboards
187 SPI digital to analogue converter.
188 The board jumpers need to be in-place to do this operation.
191 .SH "WiringPi vs. BCM_GPIO Pin numbering"
196 WiringPi GPIO-r1 GPIO-r2 Function
221 Note that "r1" and "r2" above refers to the board revision. Normally
222 wiringPi detects the correct board revision with use for it's own
223 numbering scheme, but if you are using a Revision 2 board with some
224 of the pins which change numbers between revisions you will need
225 to alter your software.
235 gpio mode 4 output # Set pin 4 to output
237 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
239 gpio mode 1 pwm # Set pin 1 to PWM mode
241 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
243 gpio export 17 out # Set GPIO Pin 17 to output
245 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
247 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
251 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
252 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
260 https://projects.drogon.net/raspberry-pi/wiringpi/
268 Please report bugs to <projects@drogon.net>
272 Copyright (c) 2012 Gordon Henderson
273 This is free software; see the source for copying conditions. There is NO
274 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
276 .SH TRADEMARKS AND ACKNOWLEDGEMENTS
278 Raspberry Pi is a trademark of the Raspberry Pi Foundation.