Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 1 | .TH "GPIO" "March 2013" "Command-Line access to Raspberry Pi's GPIO" |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 2 | |
| 3 | .SH NAME |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 4 | gpio \- Command-line access to Raspberry Pi's GPIO |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 5 | |
| 6 | .SH SYNOPSIS |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 7 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 8 | .B \-v |
| 9 | .PP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 10 | .B gpio |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 11 | .B [ \-g | \-1 ] |
| 12 | .B mode/read/write/aread/awrite/wb/pwm/clock ... |
| 13 | .PP |
| 14 | .B gpio |
| 15 | .B [ \-x extension:params ] |
| 16 | .B mode/read/write/aread/awrite/pwm ... |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 17 | .PP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 18 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 19 | .B [ \-p ] |
Gordon Henderson | 25e4ec5 | 2012-12-06 21:49:41 +0000 | [diff] [blame] | 20 | .B read/write/wb |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 21 | .B ... |
| 22 | .PP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 23 | .B gpio |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 24 | .B readall/reset |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 25 | .PP |
| 26 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 27 | .B unexportall/exports |
| 28 | .PP |
| 29 | .B gpio |
| 30 | .B export/edge/unexport |
| 31 | .B ... |
| 32 | .PP |
| 33 | .B gpio |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 34 | .B wfi |
| 35 | .B ... |
| 36 | .PP |
| 37 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 38 | .B drive |
| 39 | group value |
| 40 | .PP |
| 41 | .B gpio |
| 42 | .B pwm-bal/pwm-ms |
| 43 | .PP |
| 44 | .B gpio |
| 45 | .B pwmr |
| 46 | range |
| 47 | .PP |
| 48 | .B gpio |
Gordon Henderson | e8f6258 | 2013-01-28 13:00:47 +0000 | [diff] [blame] | 49 | .B load \ i2c/spi ... |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 50 | .PP |
| 51 | .B gpio |
| 52 | .B gbr |
| 53 | channel |
| 54 | .PP |
| 55 | .B gpio |
| 56 | .B gbw |
| 57 | channel value |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 58 | |
| 59 | .SH DESCRIPTION |
| 60 | |
| 61 | .B GPIO |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 62 | is a swiss army knife of a command line tool to allow the user easy |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 63 | access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 64 | converters on the Gertboard. It's designed for simple testing and |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 65 | diagnostic purposes, but can be used in shell scripts for general if |
| 66 | somewhat slow control of the GPIO pins. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 67 | |
Gordon Henderson | 13bbba7 | 2013-01-14 11:31:56 +0000 | [diff] [blame] | 68 | It can also control the IO's on the PiFace IO board and load the SPI and I2C |
| 69 | kernel modules if required. |
| 70 | |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 71 | Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR |
| 72 | system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR |
| 73 | interface without needing to be run as root. |
| 74 | |
| 75 | .SH OPTIONS |
| 76 | |
| 77 | .TP |
| 78 | .B \-v |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 79 | Output the current version including the board revision of the Raspberry Pi. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 80 | |
| 81 | .TP |
| 82 | .B \-g |
| 83 | Use the BCM_GPIO pins numbers rather than wiringPi pin numbers. |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 84 | \fINote:\fR The BCM_GPIO pin numbers are always used with the |
Gordon Henderson | 13bbba7 | 2013-01-14 11:31:56 +0000 | [diff] [blame] | 85 | export and edge commands. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 86 | |
| 87 | .TP |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 88 | .B \-1 |
| 89 | Use the physical pin numbers rather than wiringPi pin numbers. |
| 90 | \fINote:\fR that this applies to the P1 connector only. It is not possible to |
| 91 | use pins on the Revision 2 P5 connector this way, and as with \-g the |
| 92 | BCM_GPIO pin numbers are always used with the export and edge commands. |
| 93 | |
| 94 | .TP |
| 95 | .B \-x extension |
| 96 | This causes the named extension to be initialised. Extensions |
| 97 | comprise of a name (e.g. mcp23017) followed by a colon, then the |
| 98 | pin-base, then more optional parameters depending on the extension type. |
| 99 | See the web page on http://wiringpi.com/the-gpio-utility/ |
| 100 | |
| 101 | .TP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 102 | .B \-p |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 103 | Use the PiFace interface board and its corresponding pin numbers. The PiFace |
| 104 | will always appear at pin number 200 in the gpio command. You can assign any |
| 105 | pin numbers you like in your own programs though. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 106 | |
| 107 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 108 | .B read <pin> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 109 | Read the digital value of the given pin and print 0 or 1 to represent the |
| 110 | respective logic levels. |
| 111 | |
| 112 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 113 | .B write <pin> <value> |
Gordon Henderson | 25e4ec5 | 2012-12-06 21:49:41 +0000 | [diff] [blame] | 114 | Write the given value (0 or 1) to the pin. You need to set the pin |
| 115 | to output mode first. |
| 116 | |
| 117 | .TP |
| 118 | .B wb <value> |
| 119 | Write the given byte to the 8 main GPIO pins. You can prefix it with 0x |
| 120 | to specify a hexadecimal number. You need to set pins to output mode |
| 121 | first. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 122 | |
| 123 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 124 | .B readall |
| 125 | Output a table of all GPIO pins values. The values represent the actual values read |
| 126 | if the pin is in input mode, or the last value written if the pin is in output |
| 127 | mode. |
| 128 | |
| 129 | .TP |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 130 | .B reset |
| 131 | Resets the GPIO - As much as it's possible to do. All pins are set to input |
| 132 | mode and all the internal pull-up/down resistors are disconnected (tristate mode). |
| 133 | |
| 134 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 135 | .B pwm <pin> <value> |
Gordon Henderson | 56c77b5 | 2013-02-01 20:19:22 +0000 | [diff] [blame] | 136 | Write a PWM value (0-1023) to the given pin. The pin needs to be put |
| 137 | into PWM mode first. |
| 138 | |
| 139 | .TP |
| 140 | .B clock <pin> <frequency> |
| 141 | Set the output frequency on the given pin. The pin needs to be put into |
| 142 | clock mode first. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 143 | |
| 144 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 145 | .B mode <pin> <mode> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 146 | Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also |
| 147 | use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal |
| 148 | pull-up, pull-down or tristate (off) controls. |
| 149 | |
| 150 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 151 | .B unexportall |
| 152 | Un-Export all the GPIO pins in the /sys/class/gpio directory. |
| 153 | |
| 154 | .TP |
| 155 | .B exports |
| 156 | Print a list (if any) of all the exported GPIO pins and their current values. |
| 157 | |
| 158 | .TP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 159 | .B export |
| 160 | Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the |
| 161 | mode command above however only \fIin\fR and \fIout\fR are supported at |
| 162 | this time. Note that the pin number is the \fBBCM_GPIO\fR number and |
| 163 | not the wiringPi number. |
| 164 | |
| 165 | Once a GPIO pin has been exported, the \fBgpio\fR program changes the |
| 166 | ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in |
| 167 | later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to |
| 168 | that of the user running the \fBgpio\fR program. This means that you |
| 169 | can have a small script of gpio exports to setup the gpio pins as your |
| 170 | program requires without the need to run anything as root, or with the |
| 171 | sudo command. |
| 172 | |
| 173 | .TP |
| 174 | .B edge |
| 175 | This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set |
| 176 | the direction to input and set the edge interrupt method to \fInone\fR, |
| 177 | \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command |
| 178 | above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin |
| 179 | numbering. |
| 180 | |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 181 | Like the export commands above, ownership is set to that of the |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 182 | calling user, allowing subsequent access from user programs without |
| 183 | requiring root/sudo. |
| 184 | |
| 185 | .TP |
| 186 | .B unexport |
| 187 | Un-Export a GPIO pin in the /sys/class/gpio directory. |
| 188 | |
| 189 | .TP |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 190 | .B wfi <pin> <mode> |
| 191 | This set the given pin to the supplied interrupt mode: rising, falling |
| 192 | or both then waits for the interrupt to happen. It's a non-busy wait, |
| 193 | so does not consume and CPU while it's waiting. |
| 194 | |
| 195 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 196 | .B drive |
| 197 | group value |
| 198 | |
| 199 | Change the pad driver value for the given pad group to the supplied drive |
| 200 | value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are |
| 201 | absolutely sure you know what you're doing. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 202 | |
| 203 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 204 | .B pwm-bal/pwm-ms |
| 205 | Change the PWM mode to balanced (the default) or mark:space ratio (traditional) |
| 206 | |
| 207 | .TP |
| 208 | .B pwmr |
| 209 | Change the PWM range register. The default is 1024. |
| 210 | |
| 211 | .TP |
Gordon Henderson | e8f6258 | 2013-01-28 13:00:47 +0000 | [diff] [blame] | 212 | .B load i2c [baudrate] |
| 213 | This loads the i2c or drivers into the kernel and changes the permissions |
| 214 | on the associated /dev/ entries so that the current user has access to |
| 215 | them. Optionally it will set the I2C baudrate to that supplied (or as |
| 216 | close as the Pi can manage) The default speed is 100Kb/sec. |
| 217 | |
| 218 | .TP |
| 219 | .B load spi [buffer size in KB] |
Gordon Henderson | 98bcb20 | 2013-02-07 21:53:49 +0000 | [diff] [blame] | 220 | This loads the spi drivers into the kernel and changes the permissions |
Gordon Henderson | e8f6258 | 2013-01-28 13:00:47 +0000 | [diff] [blame] | 221 | on the associated /dev/ entries so that the current user has access to |
| 222 | them. Optionally it will set the SPI buffer size to that supplied. The |
| 223 | default is 4KB. |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 224 | |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 225 | .TP |
| 226 | .B gbr |
| 227 | channel |
| 228 | |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 229 | This reads the analog to digital converter on the Gertboard on the given |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 230 | channel. The board jumpers need to be in-place to do this operation. |
| 231 | |
| 232 | .TP |
| 233 | .B gbw |
| 234 | channel value |
| 235 | |
| 236 | This writes the supplied value to the output channel on the Gertboards |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 237 | SPI digital to analogue converter. |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 238 | The board jumpers need to be in-place to do this operation. |
| 239 | |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 240 | |
Gordon Henderson | 13bbba7 | 2013-01-14 11:31:56 +0000 | [diff] [blame] | 241 | .SH "WiringPi vs. BCM_GPIO Pin numbering" |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 242 | |
| 243 | .PP |
| 244 | .TS |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 245 | c c c c l. |
| 246 | WiringPi GPIO-r1 GPIO-r2 P1-Phys Function |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 247 | _ |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 248 | 0 17 17 11 |
| 249 | 1 18 18 12 (PWM) |
| 250 | 2 21 27 13 |
| 251 | 3 22 22 15 |
| 252 | 4 23 23 16 |
| 253 | 5 24 24 18 |
| 254 | 6 25 25 22 |
| 255 | 7 4 4 7 |
| 256 | 8 0 2 3 I2C: SDA0 |
| 257 | 9 1 3 5 I2C: SCL0 |
| 258 | 10 8 8 24 SPI: CE0 |
| 259 | 11 7 7 26 SPI: CE1 |
| 260 | 12 10 10 19 SPI: MOSI |
| 261 | 13 9 9 21 SPI: MISO |
| 262 | 14 11 11 23 SPI: SCLK |
| 263 | 15 14 14 8 TxD |
| 264 | 16 15 16 10 RxD |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 265 | 17 - 28 |
| 266 | 18 - 29 |
| 267 | 19 - 30 |
| 268 | 20 - 31 |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 269 | .TE |
| 270 | |
Gordon Henderson | 13bbba7 | 2013-01-14 11:31:56 +0000 | [diff] [blame] | 271 | Note that "r1" and "r2" above refers to the board revision. Normally |
| 272 | wiringPi detects the correct board revision with use for it's own |
| 273 | numbering scheme, but if you are using a Revision 2 board with some |
| 274 | of the pins which change numbers between revisions you will need |
| 275 | to alter your software. |
| 276 | |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 277 | .SH FILES |
| 278 | |
| 279 | .TP 2.2i |
| 280 | .I gpio |
| 281 | executable |
| 282 | |
| 283 | .SH EXAMPLES |
| 284 | .TP 2.2i |
| 285 | gpio mode 4 output # Set pin 4 to output |
| 286 | .PP |
| 287 | gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4) |
| 288 | .PP |
| 289 | gpio mode 1 pwm # Set pin 1 to PWM mode |
| 290 | .PP |
| 291 | gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness |
| 292 | .PP |
| 293 | gpio export 17 out # Set GPIO Pin 17 to output |
| 294 | .PP |
| 295 | gpio export 0 in # Set GPIO Pin 0 (SDA0) to input. |
| 296 | .PP |
| 297 | gpio -g read 0 # Read GPIO Pin 0 (SDA0) |
| 298 | |
| 299 | .SH "NOTES" |
| 300 | |
| 301 | When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the |
| 302 | pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi |
| 303 | pin numbers. |
| 304 | |
| 305 | .SH "SEE ALSO" |
| 306 | |
| 307 | .LP |
| 308 | WiringPi's home page |
| 309 | .IP |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 310 | http://wiringpi.com/ |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 311 | |
| 312 | .SH AUTHOR |
| 313 | |
| 314 | Gordon Henderson |
| 315 | |
| 316 | .SH "REPORTING BUGS" |
| 317 | |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 318 | Please report bugs to <projects@drogon.net> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 319 | |
| 320 | .SH COPYRIGHT |
| 321 | |
Gordon Henderson | da38443 | 2013-05-13 19:43:26 +0100 | [diff] [blame^] | 322 | Copyright (c) 2012-2013 Gordon Henderson |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 323 | This is free software; see the source for copying conditions. There is NO |
| 324 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame] | 325 | |
| 326 | .SH TRADEMARKS AND ACKNOWLEDGEMENTS |
| 327 | |
Gordon Henderson | e8f6258 | 2013-01-28 13:00:47 +0000 | [diff] [blame] | 328 | Raspberry Pi is a trademark of the Raspberry Pi Foundation. See |
| 329 | http://raspberrypi.org/ for full details. |