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
13 .RB < read/write/pwm/mode ...>
17 .RB < read/write/mode ...>
20 .RB < export/edge/unexport/unexportall/exports ...>
25 is a command line tool to allow the user easy access to the GPIO pins
26 on the Raspberry Pi. It's designed for simple testing and diagnostic
27 purposes, but can be used in shell scripts for general if somewhat slow
28 control of the GPIO pins.
30 Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
31 system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
32 interface without needing to be run as root.
38 Output the current version
42 Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
46 Use the PiFace interface board and its corresponding pin numbers.
50 Read the digital value of the given pin and print 0 or 1 to represent the
51 respective logic levels.
55 Write the given value (0 or 1) to the pin.
59 Write a PWM value (0-1023) to the given pin.
63 Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
64 use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
65 pull-up, pull-down or tristate (off) controls.
69 Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
70 mode command above however only \fIin\fR and \fIout\fR are supported at
71 this time. Note that the pin number is the \fBBCM_GPIO\fR number and
72 not the wiringPi number.
74 Once a GPIO pin has been exported, the \fBgpio\fR program changes the
75 ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
76 later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
77 that of the user running the \fBgpio\fR program. This means that you
78 can have a small script of gpio exports to setup the gpio pins as your
79 program requires without the need to run anything as root, or with the
84 This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
85 the direction to input and set the edge interrupt method to \fInone\fR,
86 \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
87 above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
90 Like the export commands abovem ownership is set to that of the
91 calling user, allowing subsequent access from user programs without
96 Un-Export a GPIO pin in the /sys/class/gpio directory.
100 Un-Export all the GPIO pins in the /sys/class/gpio directory.
104 Print a list (if any) of all the exported GPIO pins and their current values.
106 .SH "WiringPi vs. GPIO Pin numbering"
111 WiringPi GPIO Function
140 gpio mode 4 output # Set pin 4 to output
142 gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
144 gpio mode 1 pwm # Set pin 1 to PWM mode
146 gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
148 gpio export 17 out # Set GPIO Pin 17 to output
150 gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
152 gpio -g read 0 # Read GPIO Pin 0 (SDA0)
156 When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
157 pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
165 https://projects.drogon.net/raspberry-pi/wiringpi/
173 Report bugs to <gordon@drogon.net>
177 Copyright (c) 2012 Gordon Henderson
178 This is free software; see the source for copying conditions. There is NO
179 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.