|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- .TH gpio 1 "January 2015" wiringPi "Command-Line access to Raspberry Pi's GPIO"
-
- .SH NAME
- gpio \- Command-line access to Raspberry Pi's GPIO
-
- .SH SYNOPSIS
- .B gpio
- .B \-v
- .PP
- .B gpio
- .B [ \-g | \-1 ]
- .B mode/read/write/aread/awrite/wb/pwm/clock ...
- .PP
- .B gpio
- .B [ \-x extension:params ]
- .B mode/read/write/aread/awrite/pwm/pwmTone ...
- .PP
- .B gpio
- .B [ \-p ]
- .B read/write/toggle/wb
- .B ...
- .PP
- .B gpio
- .B readall
- .PP
- .B gpio
- .B unexportall/exports
- .PP
- .B gpio
- .B export/edge/unexport
- .B ...
- .PP
- .B gpio
- .B wfi
- .B ...
- .PP
- .B gpio
- .B drive
- group value
- .PP
- .B gpio
- .B usbp
- high | low
- .PP
- .B gpio
- .B pwm-bal/pwm-ms
- .PP
- .B gpio
- .B pwmr
- range
- .PP
- .B gpio
- .B load \ i2c/spi ...
- .PP
- .B gpio
- .B gbr
- channel
- .PP
- .B gpio
- .B gbw
- channel value
-
- .SH DESCRIPTION
-
- .B GPIO
- is a swiss army knife of a command line tool to allow the user easy
- access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
- converters on the Gertboard. It's designed for simple testing and
- diagnostic purposes, but can be used in shell scripts for general if
- somewhat slow control of the GPIO pins.
-
- It can also control the IO's on the PiFace IO board and load the SPI and I2C
- kernel modules if required.
-
- Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
- system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
- interface without needing to be run as root.
-
- .SH OPTIONS
-
- .TP
- .B \-v
- Output the current version including the board revision of the Raspberry Pi.
-
- .TP
- .B \-g
- Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
- \fINote:\fR The BCM_GPIO pin numbers are always used with the
- export and edge commands.
-
- .TP
- .B \-1
- Use the physical pin numbers rather than wiringPi pin numbers.
- \fINote:\fR that this applies to the P1 connector only. It is not possible to
- use pins on the Revision 2 P5 connector this way, and as with \-g the
- BCM_GPIO pin numbers are always used with the export and edge commands.
-
- .TP
- .B \-x extension
- This causes the named extension to be initialised. Extensions
- comprise of a name (e.g. mcp23017) followed by a colon, then the
- pin-base, then more optional parameters depending on the extension type.
- See the web page on http://wiringpi.com/the-gpio-utility/
-
- .TP
- .B \-p
- Use the PiFace interface board and its corresponding pin numbers. The PiFace
- will always appear at pin number 200 in the gpio command. You can assign any
- pin numbers you like in your own programs though.
-
- .TP
- .B read <pin>
- Read the digital value of the given pin and print 0 or 1 to represent the
- respective logic levels.
-
- .TP
- .B write <pin> <value>
- Write the given value (0 or 1) to the pin. You need to set the pin
- to output mode first.
-
- .TP
- .B aread <pin>
- Read the analog value of the given pin. This needs to be uses in
- conjunction with a -x flag to add in an extension that handles analog
- inputs. respective logic levels.
-
- e.g. gpio -x mcp3002:200:0 aread 200
-
- will read the first analog input on an mcp3002 SPI ADC chip.
-
- .TP
- .B awrite <pin> <value>
- Write the analog value to the given pin. This needs to be used in
- conjunction with a -x flag to add in an extension that handles analog
- inputs. respective logic levels.
-
- e.g. gpio -x mcp4802:200:0 awrite 200 128
-
- will write the value 128 to the first DAC port on an mcp4802 chip on
- the Pi's SPI bus 0.
-
-
- .TP
- .B wb <value>
- Write the given byte to the 8 main GPIO pins. You can prefix it with 0x
- to specify a hexadecimal number. You need to set pins to output mode
- first.
-
- .TP
- .B readall
- Output a table of all GPIO pins values. The values represent the actual values read
- if the pin is in input mode, or the last value written if the pin is in output
- mode.
-
- The readall command is usable with an extension module (via the -x parameter),
- but it's unable to determine pin modes or states, so will perform both a
- digital and analog read on each pin in-turn.
-
- .TP
- .B pwm <pin> <value>
- Write a PWM value (0-1023) to the given pin. The pin needs to be put
- into PWM mode first.
-
- .TP
- .B clock <pin> <frequency>
- Set the output frequency on the given pin. The pin needs to be put into
- clock mode first.
-
- .TP
- .B mode <pin> <mode>
- Set a pin into \fIinput\fR, \fIoutput\fR or \fIpwm\fR mode. Can also
- use the literals \fIup\fR, \fIdown\fR or \fItri\fR to set the internal
- pull-up, pull-down or tristate (off) controls.
-
- The ALT modes can also be set using \fIalt0\fR, \fIalt1\fR, ... \fIalt5\fR.
-
- .TP
- .B unexportall
- Un-Export all the GPIO pins in the /sys/class/gpio directory.
-
- .TP
- .B exports
- Print a list (if any) of all the exported GPIO pins and their current values.
-
- .TP
- .B export
- Export a GPIO pin in the \fI/sys/class/gpio\fR directory. Use like the
- mode command above however only \fIin\fR, \fIout\fR, \fIhigh\fR and
- \fRlow\fR are supported at this time. Note that the pin number is the
- \fBBCM_GPIO\fR number and not the wiringPi number. The \fIhigh\fR and
- \fIlow\fR commands pre-set the output value at the same time as the
- export to output mode.
-
- Once a GPIO pin has been exported, the \fBgpio\fR program changes the
- ownership of the \fI/sys/class/gpio/gpioX/value\fR and if present in
- later kernels, the \fI/sys/class/gpio/gpioX/edge\fR pseudo files to
- that of the user running the \fBgpio\fR program. This means that you
- can have a small script of gpio exports to setup the gpio pins as your
- program requires without the need to run anything as root, or with the
- sudo command.
-
- .TP
- .B edge
- This exports a GPIO pin in the \fI/sys/class/gpio\fR directory, set
- the direction to input and set the edge interrupt method to \fInone\fR,
- \fIrising\fR, \fIfalling\fR or \fIboth\fR. Use like the export command
- above and note that \fBBCM_GPIO\fR pin number is used not not wiringPi pin
- numbering.
-
- Like the export commands above, ownership is set to that of the
- calling user, allowing subsequent access from user programs without
- requiring root/sudo.
-
- .TP
- .B unexport
- Un-Export a GPIO pin in the /sys/class/gpio directory.
-
- .TP
- .B wfi <pin> <mode>
- This set the given pin to the supplied interrupt mode: rising, falling
- or both then waits for the interrupt to happen. It's a non-busy wait,
- so does not consume and CPU while it's waiting.
-
- .TP
- .B drive
- group value
-
- Change the pad driver value for the given pad group to the supplied drive
- value. Group is 0, 1 or 2 and value is 0-7. Do not use unless you are
- absolutely sure you know what you're doing.
-
- .TP
- .B usbp
- high | low
-
- Change the USB current limiter to high (1.2 amps) or low (the default, 600mA)
- This is only applicable to the model B+
-
- .TP
- .B pwm-bal/pwm-ms
- Change the PWM mode to balanced (the default) or mark:space ratio (traditional)
-
- .TP
- .B pwmr
- Change the PWM range register. The default is 1024.
-
- .TP
- .B load i2c [baudrate]
- This loads the i2c or drivers into the kernel and changes the permissions
- on the associated /dev/ entries so that the current user has access to
- them. Optionally it will set the I2C baudrate to that supplied in Kb/sec
- (or as close as the Pi can manage) The default speed is 100Kb/sec.
-
- Note that on a Pi with a recent 3.18 kernel with the device-tree structure
- enable, the load may fail until you add:
-
- .I dtparam=i2c=on
-
- into \fB/boot/config.txt\fR to allow user use of the I2C bus.
-
- .TP
- .B load spi
- This loads the spi drivers into the kernel and changes the permissions
- on the associated /dev/ entries so that the current user has access to
- them. It used to have the ability to change the buffer size from the
- default of 4096 bytes to an arbitary value, however for some time the
- Pi Foundation have compiled the SPI device driver into the kernel and
- this has fixed the buffer size. The way to change it now is to edit
- the /boot/cmdline.txt file and add on spdev.bufsiz=8192 to set it to
- e.g. 8192 bytes then reboot.
-
- Note that on a Pi with a recent 3.18 kernel with the device-tree structure
- enable, the load may fail until you add:
-
- .I dtparam=spi=on
-
- into \fB/boot/config.txt\fR to allow user use of the I2C bus.
-
- .TP
- .B gbr
- channel
-
- This reads the analog to digital converter on the Gertboard on the given
- channel. The board jumpers need to be in-place to do this operation.
-
- .TP
- .B gbw
- channel value
-
- This writes the supplied value to the output channel on the Gertboards
- SPI digital to analogue converter.
- The board jumpers need to be in-place to do this operation.
-
-
- .SH "WiringPi vs. BCM_GPIO Pin numbering vs. Physical pin numbering"
-
- .PP
- The quickest way to get a list of the pin differences is to run the command
- .TP
- gpio readall
-
- .SH FILES
-
- .TP 2.2i
- .I gpio
- executable
-
- .SH EXAMPLES
- .TP 2.2i
- gpio mode 4 output # Set pin 4 to output
- .PP
- gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
- .PP
- gpio mode 1 pwm # Set pin 1 to PWM mode
- .PP
- gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
- .PP
- gpio export 17 out # Set GPIO Pin 17 to output
- .PP
- gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
- .PP
- gpio -g read 0 # Read GPIO Pin 0 (SDA0)
-
- .SH "NOTES"
-
- When using the \fIexport\fR, \fIedge\fR or \fIunexport\fR commands, the
- pin numbers are \fBalways\fR native BCM_GPIO numbers and never wiringPi
- pin numbers.
-
- .SH "SEE ALSO"
-
- .LP
- WiringPi's home page
- .IP
- http://wiringpi.com/
-
- .SH AUTHOR
-
- Gordon Henderson
-
- .SH "REPORTING BUGS"
-
- Please report bugs to <projects@drogon.net>
-
- .SH COPYRIGHT
-
- Copyright (c) 2012-2015 Gordon Henderson
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- .SH TRADEMARKS AND ACKNOWLEDGEMENTS
-
- Raspberry Pi is a trademark of the Raspberry Pi Foundation. See
- http://raspberrypi.org/ for full details.
|