GPIO(1)
π GPIO β Command-Line access to Raspberry Pi's GPIO π
okay bestie, welcome to gpio(1), the section-1 manual page for the little command that talks to your Pi's pins. sit down, grab a strawberry π, and let's go.
β¨ NAME β¨
gpio β Command-line access to Raspberry Pi's GPIO
π¦ SYNOPSIS π¦
like, here's every single way you can call her:
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
π DESCRIPTION π
so GPIO is genuinely the swiss army knife of command line tools π₯ β it lets you get easy access to the GPIO pins on the Raspberry Pi, plus the SPI A/D and D/A converters on the Gertboard. it's built for simple testing and diagnostic purposes, but you can absolutely use it in shell scripts for general β if somewhat slow β control of the GPIO pins. slow and steady, still slays π
it can also control the IO's on the PiFace IO board and load the SPI and I2C kernel modules if you need that.
and additionally β yes there's more, she contains multitudes β¨ β it can set the exports in the /sys/class/gpio system directory, so that subsequent programs can use the /sys/class/gpio interface without needing to be run as root. no sudo, no drama, we love to see it.
π OPTIONS π
-vβ outputs the current version, including the board revision of the Raspberry Pi.-gβ use theBCM_GPIOpin numbers instead of wiringPi pin numbers. Note: theBCM_GPIOpin numbers are always used with theexportandedgecommands.-1β use the physical pin numbers instead of wiringPi pin numbers. Note: this applies to the P1 connector only. it is not possible to use pins on the Revision 2 P5 connector this way, and β same as with-gβ theBCM_GPIOpin numbers are always used with theexportandedgecommands.-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/-pβ use the PiFace interface board and its corresponding pin numbers. the PiFace will always appear at pin number200in thegpiocommand. you can assign any pin numbers you like in your own programs though π«Άread <pin>β read the digital value of the given pin and print0or1to represent the respective logic levels.write <pin> <value>β write the given value (0or1) to the pin. you need to set the pin to output mode first.toggle <pin>β changes the state of a GPIO pin;0to1, or1to0.
Note: unlike the blink command, the pin must be in output mode first.
blink <pin>β blinks the given pin on/off. press Control-C to exit.
Note: this command explicitly sets the pin to output mode.
aread <pin>β read the analog value of the given pin. this needs to be used in conjunction with a-xflag to add in an extension that handles analog inputs.
e.g.
gpio -x mcp3002:200:0 aread 200
will read the first analog input on an mcp3002 SPI ADC chip.
awrite <pin> <value>β write the analog value to the given pin. this needs to be used in conjunction with a-xflag to add in an extension that handles analog inputs.
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.
wb <value>β write the given byte to the 8 main GPIO pins. you can prefix it with0xto specify a hexadecimal number. you need to set pins to output mode first.readallβ output a table of all GPIO pin 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.
pwm <pin> <value>β write a PWM value (0-1023) to the given pin. the pin needs to be put into PWM mode first.clock <pin> <frequency>β set the output frequency on the given pin. the pin needs to be put into clock mode first.mode <pin> <mode>β set a pin into input, output or pwm mode. can also use the literalsup,downortrito set the internal pull-up, pull-down or tristate (off) controls.
the ALT modes can also be set using alt0, alt1, ... alt5.
unexportallβ un-export all the GPIO pins in the/sys/class/gpiodirectory.exportsβ print a list (if any) of all the exported GPIO pins and their current values.exportβ export a GPIO pin in the/sys/class/gpiodirectory. use like themodecommand above, however onlyin,out,highandloware supported at this time. Note that the pin number is theBCM_GPIOnumber and not the wiringPi number. thehighandlowcommands pre-set the output value at the same time as the export to output mode.
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 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. iconic behaviour honestly π
edgeβ this exports a GPIO pin in the/sys/class/gpiodirectory, sets the direction to input and sets the edge interrupt method tonone,rising,fallingorboth. use like theexportcommand above and note that theBCM_GPIOpin 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.
unexportβ un-export a GPIO pin in the/sys/class/gpiodirectory.wfi <pin> <mode>β this sets the given pin to the supplied interrupt mode:rising,fallingorboth, then waits for the interrupt to happen. it's a non-busy wait, so does not consume any CPU while it's waiting. she just waits, patiently, no spin-looping, main character energy β¨drivegroup valueβ change the pad driver value for the given pad group to the supplied drive value.groupis0,1or2andvalueis0-7.
do not use unless you are absolutely sure you know what you're doing. fr fr π
usbphigh | lowβ change the USB current limiter tohigh(1.2 amps) orlow(the default, 600mA). this is only applicable to the Model B+ and the Model B, v2.pwm-bal/pwm-msβ change the PWM mode to balanced (the default) or mark:space ratio (traditional).pwmrβ change the PWM range register. the default is1024.gbrchannelβ 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.gbwchannel 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.
π WiringPi vs. BCM_GPIO Pin numbering vs. Physical pin numbering π
the quickest way to get a list of the pin differences is to run the command
gpio readall
π§ FILES π§
gpioβ executable
π EXAMPLES π
gpio mode 4 output # Set pin 4 to output
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)
π NOTES π
when using the export, edge or unexport commands, the pin numbers are always native BCM_GPIO numbers and never wiringPi pin numbers. no exceptions bestie.
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.
π₯ SEE ALSO π₯
WiringPi's home page
πΈ AUTHOR πΈ
Gordon Henderson
π REPORTING BUGS π
please report bugs to <projects@drogon.net>
β COPYRIGHT β
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.
π¦ TRADEMARKS AND ACKNOWLEDGEMENTS π¦
Raspberry Pi is a trademark of the Raspberry Pi Foundation. see http://raspberrypi.org/ for full details.
and that's the whole page, periodt π
this was wiringPi, March 2018, GPIO(1) β love u, go blink a pin responsibly π«Άβ¨
π¦ where this page comes from
- ubuntu jammy: wiringpi 2.50-0ubuntu2 Β· LGPL-3.0-or-later
- ubuntu noble: wiringpi 2.50-0ubuntu3 Β· LGPL-3.0-or-later
- ubuntu questing: wiringpi 2.50-0ubuntu3
- ubuntu resolute: wiringpi 2.50-0ubuntu4 Β· LGPL-3.0-or-later
- ubuntu stonking: wiringpi 2.50-0ubuntu4 Β· LGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms