Control and program Raspberry Pi GPIO with “wiringPi” (shell/bash)

For easy control and programming of the GPIOs oftRaspberry Pi, the command line “wiringPi” has been used for a long time. Using simple commands, the GPIOs can be controlled and programmed
Note: “wiringPi” is a bit older and there are now better libraries to control GPIOs. One can even go so far as to say that it should not be used for new projects. Therefore, the presentation of the application of “wiringPi” is omitted here. The recommendation is clearly “gpiozero” and “pigpio”.
Configure GPIO as input or output
Here we select the GPIO 17 (pin 11) and GPIO 18 (pin 12) as examples to configure them as output and input. For this the BCM numbering of the chip is used. So the number of the GPIO and not the pin.
The parameter “-g” in the following commands specifies that the GPIO numbers of the BCM chip can be used. If you prefer to use the pin number, replace “-g” with “-1” (minus one).
If the GPIO 17 is to be configured as output, the following command applies.
gpio -g mode 17 out
By default, the output gets the state “low” or “0”.
If the GPIO 18 is to be configured as an input, the following command applies.
gpio -g mode 18 in
State of a GPIO output set
Basically you can only set outputs. To set the state of a GPIO output to “high”, the following command is sufficient.
gpio -g write 17 1
To set the state of a GPIO output to “low” the following command is sufficient.
gpio -g write 17 0
Determine/read GPIO status
To determine the state, ie “high” or “low”, at a GPIO, the following command is sufficient. The GPIO can be both an input and an output.
gpio -g read 18
The output “1” stands for “high” or “0” for “low”.
The following command shows the current assignment of the GPIOs and which status they have:
gpio -g readall
Leave a Reply