Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 1 | .TH "GPIO" "21st October 2012" "Command-Line access to Raspberry Pi and PiFace GPIO" |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 2 | |
| 3 | .SH NAME |
| 4 | gpio \- Command-line access to Raspberry Pi and PiFace GPIO |
| 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 | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 11 | .B [ \-g ] |
| 12 | .B read/write/pwm/mode ... |
| 13 | .PP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 14 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 15 | .B [ \-p ] |
| 16 | .B read/write/mode |
| 17 | .B ... |
| 18 | .PP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 19 | .B gpio |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 20 | .B readall |
| 21 | .PP |
| 22 | .B gpio |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 23 | .B unexportall/exports |
| 24 | .PP |
| 25 | .B gpio |
| 26 | .B export/edge/unexport |
| 27 | .B ... |
| 28 | .PP |
| 29 | .B gpio |
| 30 | .B drive |
| 31 | group value |
| 32 | .PP |
| 33 | .B gpio |
| 34 | .B pwm-bal/pwm-ms |
| 35 | .PP |
| 36 | .B gpio |
| 37 | .B pwmr |
| 38 | range |
| 39 | .PP |
| 40 | .B gpio |
| 41 | .B load \ i2c/spi |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 42 | .PP |
| 43 | .B gpio |
| 44 | .B gbr |
| 45 | channel |
| 46 | .PP |
| 47 | .B gpio |
| 48 | .B gbw |
| 49 | channel value |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 50 | |
| 51 | .SH DESCRIPTION |
| 52 | |
| 53 | .B GPIO |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 54 | 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] | 55 | 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] | 56 | converters on the Gertboard. It's designed for simple testing and |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 57 | diagnostic purposes, but can be used in shell scripts for general if |
| 58 | somewhat slow control of the GPIO pins. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 59 | |
| 60 | Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR |
| 61 | system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR |
| 62 | interface without needing to be run as root. |
| 63 | |
| 64 | .SH OPTIONS |
| 65 | |
| 66 | .TP |
| 67 | .B \-v |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 68 | Output the current version including the board revision of the Raspberry Pi. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 69 | |
| 70 | .TP |
| 71 | .B \-g |
| 72 | Use the BCM_GPIO pins numbers rather than wiringPi pin numbers. |
| 73 | |
| 74 | .TP |
| 75 | .B \-p |
| 76 | Use the PiFace interface board and its corresponding pin numbers. |
| 77 | |
| 78 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 79 | .B read <pin> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 80 | Read the digital value of the given pin and print 0 or 1 to represent the |
| 81 | respective logic levels. |
| 82 | |
| 83 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 84 | .B write <pin> <value> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 85 | Write the given value (0 or 1) to the pin. |
| 86 | |
| 87 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 88 | .B readall |
| 89 | Output a table of all GPIO pins values. The values represent the actual values read |
| 90 | if the pin is in input mode, or the last value written if the pin is in output |
| 91 | mode. |
| 92 | |
| 93 | .TP |
| 94 | .B pwm <pin> <value> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 95 | Write a PWM value (0-1023) to the given pin. |
| 96 | |
| 97 | .TP |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 98 | .B mode <pin> <mode> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 99 | Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also |
| 100 | use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal |
| 101 | pull-up, pull-down or tristate (off) controls. |
| 102 | |
| 103 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 104 | .B unexportall |
| 105 | Un-Export all the GPIO pins in the /sys/class/gpio directory. |
| 106 | |
| 107 | .TP |
| 108 | .B exports |
| 109 | Print a list (if any) of all the exported GPIO pins and their current values. |
| 110 | |
| 111 | .TP |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 112 | .B export |
| 113 | Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the |
| 114 | mode command above however only \fIin\fR and \fIout\fR are supported at |
| 115 | this time. Note that the pin number is the \fBBCM_GPIO\fR number and |
| 116 | not the wiringPi number. |
| 117 | |
| 118 | Once a GPIO pin has been exported, the \fBgpio\fR program changes the |
| 119 | ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in |
| 120 | later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to |
| 121 | that of the user running the \fBgpio\fR program. This means that you |
| 122 | can have a small script of gpio exports to setup the gpio pins as your |
| 123 | program requires without the need to run anything as root, or with the |
| 124 | sudo command. |
| 125 | |
| 126 | .TP |
| 127 | .B edge |
| 128 | This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set |
| 129 | the direction to input and set the edge interrupt method to \fInone\fR, |
| 130 | \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command |
| 131 | above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin |
| 132 | numbering. |
| 133 | |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 134 | Like the export commands above, ownership is set to that of the |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 135 | calling user, allowing subsequent access from user programs without |
| 136 | requiring root/sudo. |
| 137 | |
| 138 | .TP |
| 139 | .B unexport |
| 140 | Un-Export a GPIO pin in the /sys/class/gpio directory. |
| 141 | |
| 142 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 143 | .B drive |
| 144 | group value |
| 145 | |
| 146 | Change the pad driver value for the given pad group to the supplied drive |
| 147 | value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are |
| 148 | absolutely sure you know what you're doing. |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 149 | |
| 150 | .TP |
Gordon Henderson | f99ffed | 2012-08-19 15:12:45 +0100 | [diff] [blame] | 151 | .B pwm-bal/pwm-ms |
| 152 | Change the PWM mode to balanced (the default) or mark:space ratio (traditional) |
| 153 | |
| 154 | .TP |
| 155 | .B pwmr |
| 156 | Change the PWM range register. The default is 1024. |
| 157 | |
| 158 | .TP |
| 159 | .B load i2c/spi |
| 160 | This loads the i2c or the spi drivers into the system and changes the permissions on |
| 161 | the associated /dev/ entries so that the current user has access to them. |
| 162 | |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 163 | .TP |
| 164 | .B gbr |
| 165 | channel |
| 166 | |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 167 | 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] | 168 | channel. The board jumpers need to be in-place to do this operation. |
| 169 | |
| 170 | .TP |
| 171 | .B gbw |
| 172 | channel value |
| 173 | |
| 174 | This writes the supplied value to the output channel on the Gertboards |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 175 | SPI digital to analogue converter. |
Gordon Henderson | 99095e3 | 2012-08-27 20:56:14 +0100 | [diff] [blame] | 176 | The board jumpers need to be in-place to do this operation. |
| 177 | |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 178 | |
| 179 | .SH "WiringPi vs. GPIO Pin numbering" |
| 180 | |
| 181 | .PP |
| 182 | .TS |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 183 | r r r l. |
| 184 | WiringPi GPIO-r1 GPIO-r2 Function |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 185 | _ |
Gordon Henderson | 86a5c68 | 2012-10-02 14:32:12 +0100 | [diff] [blame] | 186 | 0 17 17 |
| 187 | 1 18 18 (PWM) |
| 188 | 2 21 27 |
| 189 | 3 22 22 |
| 190 | 4 23 23 |
| 191 | 5 24 24 |
| 192 | 6 25 25 |
| 193 | 7 4 4 |
| 194 | 8 0 2 I2C: SDA0 |
| 195 | 9 1 3 I2C: SCL0 |
| 196 | 10 8 8 SPI: CE0 |
| 197 | 11 7 7 SPI: CE1 |
| 198 | 12 10 10 SPI: MOSI |
| 199 | 13 9 9 SPI: MISO |
| 200 | 14 11 11 SPI: SCLK |
| 201 | 15 14 14 TxD |
| 202 | 16 15 16 RxD |
| 203 | 17 - 28 |
| 204 | 18 - 29 |
| 205 | 19 - 30 |
| 206 | 20 - 31 |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 207 | .TE |
| 208 | |
| 209 | .SH FILES |
| 210 | |
| 211 | .TP 2.2i |
| 212 | .I gpio |
| 213 | executable |
| 214 | |
| 215 | .SH EXAMPLES |
| 216 | .TP 2.2i |
| 217 | gpio mode 4 output # Set pin 4 to output |
| 218 | .PP |
| 219 | gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4) |
| 220 | .PP |
| 221 | gpio mode 1 pwm # Set pin 1 to PWM mode |
| 222 | .PP |
| 223 | gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness |
| 224 | .PP |
| 225 | gpio export 17 out # Set GPIO Pin 17 to output |
| 226 | .PP |
| 227 | gpio export 0 in # Set GPIO Pin 0 (SDA0) to input. |
| 228 | .PP |
| 229 | gpio -g read 0 # Read GPIO Pin 0 (SDA0) |
| 230 | |
| 231 | .SH "NOTES" |
| 232 | |
| 233 | When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the |
| 234 | pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi |
| 235 | pin numbers. |
| 236 | |
| 237 | .SH "SEE ALSO" |
| 238 | |
| 239 | .LP |
| 240 | WiringPi's home page |
| 241 | .IP |
| 242 | https://projects.drogon.net/raspberry-pi/wiringpi/ |
| 243 | |
| 244 | .SH AUTHOR |
| 245 | |
| 246 | Gordon Henderson |
| 247 | |
| 248 | .SH "REPORTING BUGS" |
| 249 | |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 250 | Please report bugs to <projects@drogon.net> |
Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 251 | |
| 252 | .SH COPYRIGHT |
| 253 | |
| 254 | Copyright (c) 2012 Gordon Henderson |
| 255 | This is free software; see the source for copying conditions. There is NO |
| 256 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
Gordon Henderson | 183c5a6 | 2012-10-21 15:25:16 +0100 | [diff] [blame^] | 257 | |
| 258 | .SH TRADEMARKS AND ACKNOWLEDGEMENTS |
| 259 | |
| 260 | Raspberry Pi is a trademark of the Raspberry Pi Foundation. |