๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ using the raspberry pi โ€บ beginners
using the GPIO command - Raspberry Pi Forums
pi@raspiJamesA8Gb ~ $ gpio readall +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | | | 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO.
๐ŸŒ
Stack Exchange
raspberrypi.stackexchange.com โ€บ questions โ€บ 149521 โ€บ how-to-manage-gpios-on-the-raspberry-pi-using-the-command-line-and-other-clarif
pi 4 - How to manage GPIOs on the Raspberry Pi using the command line? And other clarifications - Raspberry Pi Stack Exchange
December 1, 2024 - I was using Raspbian until last week when I upgraded to the latest Raspberry Pi OS (I delayed that because I didn't have a real need to upgrade and updating always takes some time). Well now I see that the method I was using to access gpio pins and using them changed. The example below just turns on a LED attached to GPIO 13. ... echo 13 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio13/direction echo 1 > /sys/class/gpio/gpio13/value
Discussions

Beginner Pi4 GPIO CLI Control - Raspberry Pi Forums
What I did find was that the "GPIO" commands were already in the OS. So I did this.... gpio -v gpio version: 2.50 Copyright (c) 2012-2018 Gordon Henderson This is free software with ABSOLUTELY NO WARRANTY. For details type: gpio -warranty Raspberry Pi Details: Type: Unknown17, Revision: 01, Memory: 0MB, Maker: Sony * Device tree is enabled. *--> Raspberry Pi 4 ... More on raspberrypi.org
๐ŸŒ raspberrypi.org
September 19, 2019
rpi.gpio - Is the gpio readall command compatible with RPi 4? - Raspberry Pi Stack Exchange
This is simplified, and does not ... wiringpi pin numbers. ... To restore non-coloured output uncomment the 2 lines # non-coloured output and comment out # coloured output. Code can be downloaded from https://github.com/Milliways2/gpioread ... I have been playing recently with the gpiochip interface (included in recent kernels) and realised that the raspi-gpio debug tool actually has all the details needed. raspi-gpio should be included in all recent Raspberry Pi OS, but ... More on raspberrypi.stackexchange.com
๐ŸŒ raspberrypi.stackexchange.com
September 10, 2019
using the GPIO command - Raspberry Pi Forums
How would I read the diagrams of the pins? And, why is the gpio command never formally/officially discussed on the raspberrypi.org website? I have tried looking at the diagrams; looking for information on the GPIO command on the raspberrypi.org website; trying a help search in the command line ... More on raspberrypi.org
๐ŸŒ raspberrypi.org
March 10, 2018
bash - RPi - Accessing GPIO Pins with ">" Operator - Stack Overflow
As seen on the website: https://luketopia.net/2013/07/28/raspberry-pi-gpio-via-the-shell/ So if we want to be able to access pin 4, we would type echo 4 > /sys/class/gpio/export and To specify ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
SparkFun Learn
learn.sparkfun.com โ€บ tutorials โ€บ raspberry-gpio โ€บ all
Raspberry gPIo - SparkFun Learn
* --> Raspberry Pi 4 Model B Rev 1.2 * This Raspberry Pi supports user-level GPIO access. Enter the following to remove the wiringPi and configuration files. ... Then type the following for the Pi to remove all locations that remember wiringPi. ... As long as you have Git installed, these commands should be all you need to download and install Wiring Pi.
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ using the raspberry pi โ€บ beginners
Beginner Pi4 GPIO CLI Control - Raspberry Pi Forums
September 19, 2019 - Thanks guys! I did say I was a beginner.... I thought the raspi in raspi-gpio was part of the command line label on his machine. Like "root@raspberrypi:~#" Doh! So I found that this worked. raspi-gpio set 24 op pn dl raspi-gpio set 24 op pn dh Now I just have to figure out how to write python and control it from a web page and with automation....
๐ŸŒ
Embeddedpi
embeddedpi.com โ€บ documentation โ€บ gpio โ€บ mypi-industrial-raspberry-pi-using-gpio-via-command-line
Using GPIO Via Command Line or C libraries - MyPi Industrial Raspberry Pi
In the above example we're turning the green status LED on and off - note how the gpio utility ignores the 'active high/low' setting that was defined for the pin during boot so the LED only lights up when we send a 0 rather than a 1. The -g option is important as this tells the gpio program to use the actual gpio line numbers and not the Raspberry Pi plug references.
๐ŸŒ
Ubuntu
manpages.ubuntu.com โ€บ manpages โ€บ jammy โ€บ man1 โ€บ gpio.1.html
Ubuntu Manpage: gpio - Command-line access to Raspberry Pi's GPIO
The quickest way to get a list of the pin differences is to run the command gpio readall ... 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 ...
๐ŸŒ
Embedded Computing Design
embeddedcomputing.com โ€บ technology โ€บ processing โ€บ interface-io โ€บ quick-start-raspberry-pi-gpio-terminal-interface
Quick Start: Raspberry Pi GPIO Terminal Interface - Embedded Computing Design
February 17, 2022 - This allows you to read an external high/low voltage state with the raspi-gpio get 18 command. The get command works when the pins are in output mode as well, but will be dictated by how you set them.
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ hardware and peripherals โ€บ compute module
command line GPIO tool for CM4 - Raspberry Pi Forums
November 18, 2021 - Another is my pigs utility (requires ... 2:53 pm, edited 1 time in total. ... Mon Jun 28, 2021 7:49 am The associated command line utilities are gpioinfo, gpioset, gpioget etc....
Find elsewhere
๐ŸŒ
Raspberry Pi Projects
raspberry-projects.com โ€บ pi โ€บ command-line โ€บ io-pins-command-line โ€บ io-pin-control-from-the-command-line
IO pin control from the command line โ€“ Raspberry Pi Projects
There is no wiringpi, wiringPi, or wiringPI in Raspberry Pi OS 12. This post is out of date and no longer works. ... There is no need to fiddle with with /sys folder and root. You can use the `gpio` command-line utility that is available for pi-b3/pi-b3+ and newer.
๐ŸŒ
DEV Community
dev.to โ€บ tardisgallifrey โ€บ raspberry-pi-gpio-4-ways-45do
Raspberry Pi GPIO 4 Ways - DEV Community
March 22, 2020 - My observation of nim is that there are several methods to accomplish file I/O. I've chosen what is closest to what I've already written above in C and C++. nim is available in the Ubuntu Raspberry Pi repository. One word of warning. Do not use tabs in nim. It doesn't like that and will give you some error about tabulators not allowed. Took quite a bit to figure out that meaning. ... var sysfs_handle: File if open( sysfs_handle, "/sys/class/gpio/export", fmWrite): sysfs_handle.writeLine("4") echo "GPIO export set." else: echo "Problem opening File, are you root?" sysfs_handle.close() if open( sysfs_handle, "/sys/class/gpio/gpio4/direction", fmWrite): sysfs_handle.writeLine("out") echo "GPIO pin 4 assigned to be an output." else: echo "Problem opening file.
๐ŸŒ
ICS
ics.com โ€บ blog โ€บ gpio-programming-using-sysfs-interface
GPIO Programming: Using the sysfs Interface | ICS
July 10, 2019 - I'll show some examples that will work on the Raspberry Pi platform. As we'll see in future installments of this blog series, there are different ways to access GPIO hardware from programs, but sysfs is a simple one that is supported by the Linux kernel and makes the devices visible in the file system so we can experiment from the command line ...
๐ŸŒ
gpiozero
gpiozero.readthedocs.io โ€บ en โ€บ stable โ€บ cli_tools.html
8. Command-line Tools โ€” gpiozero 2.0.1 Documentation
The gpiozero package contains a database of information about the various revisions of Raspberry Pi. This is queried by the pinout command-line tool to output details of the GPIO pins available.
๐ŸŒ
Raspberrypi-aa
raspberrypi-aa.github.io โ€บ session2 โ€บ bash.html
Bash Control of GPIO Ports - Introduction to Raspberry Pi
The following commands should be run as root (type 'sudo bash' to become root). This code sets up pin 18 to be an output, sets the pin high and then sets it low. # Exports pin to userspace echo "18" > /sys/class/gpio/export # Sets pin 18 as an output echo "out" > /sys/class/gpio/gpio18/direction # Sets pin 18 to high echo "1" > /sys/class/gpio/gpio18/value # Sets pin 18 to low echo "0" > /sys/class/gpio/gpio18/value ยท This next snippet sets up pin 4 ...
๐ŸŒ
Raspberry Pi
raspberrypi.org โ€บ forums โ€บ viewtopic.php
using the GPIO command - Raspberry Pi Forums
March 10, 2018 - pi@raspiJamesA8Gb ~ $ gpio readall +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | | | 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO.
๐ŸŒ
Raspberry Pi
raspberrypi.org โ€บ documentation โ€บ usage โ€บ gpio
Raspberry Pi OS - Raspberry Pi Documentation
A bit being set indicates the following meanings: Returns the temperature of the SoC as measured by its internal temperature sensor. On Raspberry Pi 4, measure_temp pmic returns the temperature of the PMIC.
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ community โ€บ general discussion
Command to check GPIO'S? - Raspberry Pi Forums
October 11, 2021 - Fri Dec 06, 2019 7:01 am The "raspi-gpio get" command will list the status of all GPIOs (not just those available on the connector). You can limit it with "raspi-gpio get 2-27" to just list the ones available for general use. This won't show them in a pretty order with pin numbers, but it is ...
Top answer
1 of 1
4

It looks to me like there's two aspects to this question,

  1. How the redirection operator works in itself, and...
  2. How the GPIO driver works through RPi linux

I'll answer these individually below:

1. The Redirection Operator >

The > is what's known as a "redirection operator". It takes the output of a process or function, and redirects it from the terminal to somewhere else. The echo command writes output to the terminal. In this specific case, the terminal output from echo 4 (i.e. the value 4) is passed to /sys/class/gpio/export. See section 2 for more details on what that actually does.

Another common use of >, that may give a more tangible example, is to redirect the output into a file, e.g.:

$ echo "This text will go into a file." > "myfile.txt"

The file myfile.txt will be created and the line we echo'd out will be put into it, so its contents will be "This text will go into a file.".

It's not just echo either, any command's console output can be redirected, e.g.:

$ ls -la > "directoryListing.txt"

The above would do a directory listing of all files, and output the result into the text file "directoryListing.txt" as opposed to the console.

For more details on linux concepts, particularly useful ones like redirection > and pipe |, I would advise trying out the link below:

https://unix.stackexchange.com/questions/159513/what-are-the-shells-control-and-redirection-operators

2. The GPIO Driver access

From reading the description on this RPi linux site, it looks like /sys/class/gpio/export taps into the device driver for the GPIO pins and tells it you wish to use the pin provided (in this case, pin 4). You provide input to this virtual directory by redirecting it from the console (see above, section 1).

Once you've called export, you've told the driver which pin (or pins) you wish to work with and it creates something akin to a virtual filesystem to allow control.

This is where the gpio4/direction part comes in. That gpio4 folder was created when you exported pin 4 above. There are a number of (what you could think of as) virtual files in that directory, which then let you set up the pin configuration. The direction one tells the driver whether the pin is an input pin (in which case it is passed the word in), or an output pin (in which case we pass it the word out).

Again, we set this using the console redirection operator > and we can read it just like a normal file, to get the assigned value, like so:

$ cat /sys/class/gpio/gpio4/direction

To read/write values to the pin (i.e. whether it is set to on or off), one simply follows the same idea with the value file:

$ echo 1 > /sys/class/gpio/gpio4/value

Sets the value of pin 4 to 1, which means on. Equivalently, it can be turned off by doing

$ echo 0 > /sys/class/gpio/gpio4/value

Finally, if you had specified the direction of the pin as an input, by doing the following:

$ echo in > /sys/class/gpio/gpio4/direction

You could read that value thusly:

$ cat /sys/class/gpio/gpio4/value

If you wanted to store that in a variable, you might do something like:

$ myPinValue=$(cat /sys/class/gpio/gpio4/value)

Please note these examples are untested and my Linux-fu is a little rusty as I now sadly work in Windows world.