gpio.1 9.3 KB

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