gpio.1 6.3 KB

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