gpio.1 9.2 KB

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