GPIO(1) | Command-Line access to Raspberry Pi's GPIO | GPIO(1) |
gpio - Command-line access to Raspberry Pi's GPIO
gpio -v
gpio [ -g | -1 ] mode/read/write/aread/awrite/wb/pwm/pwnTone/clock/toggle/blink ...
gpio [ -x extension:params ] mode/read/write/aread/awrite/pwm/toggle/blink ...
gpio [ -p ] read/write/toggle/blink ...
gpio [ -p ] pwnTone pin frequency ...
gpio readall
gpio unexportall/exports
gpio export/edge/unexport ...
gpio wfi ...
gpio drive group value
gpio usbp high | low
gpio pwm-bal/pwm-ms
gpio pwmr range
gpio load i2c/spi ...
gpio gbr channel
gpio gbw channel value
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 /sys/class/gpio system directory to allow subsequent programs to use the /sys/class/gpio interface without needing to be run as root.
Note unlike the blink command, the pin must be in output mode first.
Note: This command explicitly sets the pin to output mode.
e.g. gpio -x mcp3002:200:0 aread 200
will read the first analog input on an mcp3002 SPI ADC chip.
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.
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.
The ALT modes can also be set using alt0, alt1, ... alt5.
Once a GPIO pin has been exported, the gpio program changes the ownership of the /sys/class/gpio/gpioX/value and if present in later kernels, the /sys/class/gpio/gpioX/edge pseudo files to that of the user running the gpio 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.
Like the export commands above, ownership is set to that of the calling user, allowing subsequent access from user programs without requiring root/sudo.
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.
Change the USB current limiter to high (1.2 amps) or low (the default, 600mA) This is only applicable to the Model B+ and the Model B, v2.
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.
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.
The quickest way to get a list of the pin differences is to run the command
gpio -g mode 23 output # Set GPIO pin 23 to output (same as WiringPi pin 4)
gpio mode 1 pwm # Set pin 1 to PWM mode
gpio pwm 1 512 # Set pin 1 to PWM value 512 - half brightness
gpio export 17 out # Set GPIO Pin 17 to output
gpio export 0 in # Set GPIO Pin 0 (SDA0) to input.
gpio -g read 0 # Read GPIO Pin 0 (SDA0)
When using the export, edge or unexport commands, the pin numbers are always native BCM_GPIO numbers and never wiringPi pin numbers.
As of kernels 4.1.7, a user-level GPIO access mechanism is available, however wiringPi will not use this by default - because at this time there appears to be issues when trying to program the PWM or clock output hardware. If you can live without PWM or GPIO clocks and you want to use the GPIO from a non-root program, then you need to make sure that the module bcm2835_gpiomem is loaded at boot time. This should happen automatically when you enable the device tree in raspi-config. You may also need some additional information in /etc/udev/rules.d/ to change the mode and ownership of the /dev/gpiomem file. Finally, you need to set the environment variable WIRINGPI_GPIOMEM. This will go-away in future releases once the /dev/gpiomem interface is fully operational.
WiringPi's home page
Gordon Henderson
Please report bugs to <projects@drogon.net>
Copyright (c) 2012-2018 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.
Raspberry Pi is a trademark of the Raspberry Pi Foundation. See http://raspberrypi.org/ for full details.
March 2018 | wiringPi |