1 .TH "GPIO" "14 June 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/pwm/mode ...
20 .B unexportall/exports
23 .B export/edge/unexport
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.
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.
56 Output the current version
60 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
64 Use the PiFace interface board and its corresponding pin numbers.
68 Read the digital value of the given pin and print 0 or 1 to represent the
69 respective logic levels.
73 Write the given value (0 or 1) to the pin.
77 Write a PWM value (0-1023) to the given pin.
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.
87 Un-Export all the GPIO pins in the /sys/class/gpio directory.
91 Print a list (if any) of all the exported GPIO pins and their current values.
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.
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
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
116 Like the export commands abovem ownership is set to that of the
117 calling user, allowing subsequent access from user programs without
122 Un-Export a GPIO pin in the /sys/class/gpio directory.
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.
134 Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
138 Change the PWM range register. The default is 1024.
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.
146 .SH "WiringPi vs. GPIO Pin numbering"
151 WiringPi GPIO Function
180 gpio mode 4 output # Set pin 4 to output
182 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
184 gpio mode 1 pwm # Set pin 1 to PWM mode
186 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
188 gpio export 17 out # Set GPIO Pin 17 to output
190 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
192 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
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
205 https://projects.drogon.net/raspberry-pi/wiringpi/
213 Report bugs to <projects@drogon.net>
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.