gpio.1 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. .TH "GPIO" "14 June 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. .TP
  6. .B gpio
  7. .RB [ \-v ]
  8. .TP
  9. .B gpio
  10. .RB [ \-g ]
  11. .RB < read/write/pwm/mode ...>
  12. .TP
  13. .B gpio
  14. .RB [ \-p ]
  15. .RB < read/write/mode ...>
  16. .TP
  17. .B gpio
  18. .RB < export/edge/unexport/unexportall/exports ...>
  19. .SH DESCRIPTION
  20. .B GPIO
  21. is a command line tool to allow the user easy access to the GPIO pins
  22. on the Raspberry Pi. It's designed for simple testing and diagnostic
  23. purposes, but can be used in shell scripts for general if somewhat slow
  24. control of the GPIO pins.
  25. Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
  26. system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
  27. interface without needing to be run as root.
  28. .SH OPTIONS
  29. .TP
  30. .B \-v
  31. Output the current version
  32. .TP
  33. .B \-g
  34. Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
  35. .TP
  36. .B \-p
  37. Use the PiFace interface board and its corresponding pin numbers.
  38. .TP
  39. .B read
  40. Read the digital value of the given pin and print 0 or 1 to represent the
  41. respective logic levels.
  42. .TP
  43. .B write
  44. Write the given value (0 or 1) to the pin.
  45. .TP
  46. .B pwm
  47. Write a PWM value (0-1023) to the given pin.
  48. .TP
  49. .B mode
  50. Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
  51. use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
  52. pull-up, pull-down or tristate (off) controls.
  53. .TP
  54. .B export
  55. Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
  56. mode command above however only \fIin\fR and \fIout\fR are supported at
  57. this time. Note that the pin number is the \fBBCM_GPIO\fR number and
  58. not the wiringPi number.
  59. Once a GPIO pin has been exported, the \fBgpio\fR program changes the
  60. ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
  61. later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
  62. that of the user running the \fBgpio\fR program. This means that you
  63. can have a small script of gpio exports to setup the gpio pins as your
  64. program requires without the need to run anything as root, or with the
  65. sudo command.
  66. .TP
  67. .B edge
  68. This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
  69. the direction to input and set the edge interrupt method to \fInone\fR,
  70. \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
  71. above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
  72. numbering.
  73. Like the export commands abovem ownership is set to that of the
  74. calling user, allowing subsequent access from user programs without
  75. requiring root/sudo.
  76. .TP
  77. .B unexport
  78. Un-Export a GPIO pin in the /sys/class/gpio directory.
  79. .TP
  80. .B unexportall
  81. Un-Export all the GPIO pins in the /sys/class/gpio directory.
  82. .TP
  83. .B exports
  84. Print a list (if any) of all the exported GPIO pins and their current values.
  85. .SH "WiringPi vs. GPIO Pin numbering"
  86. .PP
  87. .TS
  88. r r l.
  89. WiringPi GPIO Function
  90. _
  91. 0 17
  92. 1 18 (PWM)
  93. 2 21
  94. 3 22
  95. 4 23
  96. 5 24
  97. 6 25
  98. 7 4
  99. 8 0 SDA0
  100. 9 1 SCL0
  101. 10 8 SPI CE0
  102. 11 7 SPI CE1
  103. 12 10 SPI MOSI
  104. 13 9 SPI MISO
  105. 14 11 SPI SCLK
  106. 15 14 TxD
  107. 16 15 RxD
  108. .TE
  109. .SH FILES
  110. .TP 2.2i
  111. .I gpio
  112. executable
  113. .SH EXAMPLES
  114. .TP 2.2i
  115. gpio mode 4 output # Set pin 4 to output
  116. .PP
  117. gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
  118. .PP
  119. gpio mode 1 pwm # Set pin 1 to PWM mode
  120. .PP
  121. gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
  122. .PP
  123. gpio export 17 out # Set GPIO Pin 17 to output
  124. .PP
  125. gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
  126. .PP
  127. gpio -g read 0 # Read GPIO Pin 0 (SDA0)
  128. .SH "NOTES"
  129. When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
  130. pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
  131. pin numbers.
  132. .SH "SEE ALSO"
  133. .LP
  134. WiringPi's home page
  135. .IP
  136. https://projects.drogon.net/raspberry-pi/wiringpi/
  137. .SH AUTHOR
  138. Gordon Henderson
  139. .SH "REPORTING BUGS"
  140. Report bugs to <gordon@drogon.net>
  141. .SH COPYRIGHT
  142. Copyright (c) 2012 Gordon Henderson
  143. This is free software; see the source for copying conditions. There is NO
  144. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.