You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpio.1 8.5 KiB

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