Raspberry Pi control and program GPIO - pigpio

Raspberry Pi control and program GPIO with "pigpio" (shell / bash)
Compared to controlling and programming the GPIOs via "sysfs", "pigpio" on the command line is a simplification. The command line tool "pigs" also supports the programming of a GPIO as PWM and servo.
"pigpio" is also the preferred method for controlling and programming the GPIOs on the command line.
Install and enable "pigpio"
If not already installed, the installation of "pigpio" is done with the following command.
sudo apt-get install pigpio

The control of the GPIOs is done with the command line tool "pigs". For this to work, you must first start the pigpio daemon.
sudo systemctl start pigpiod

If you want the daemon to start automatically at system startup, then execute the following command.
sudo systemctl enable pigpiod

Then you can configure the individual GPIOs.

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.
If the GPIO 17 is to be configured as output, the following command applies.
pigs modes 17 w

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.
pigs modes 18 r

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.
pigs w 17 1

To set the state of a GPIO output to "low" the following command is sufficient.
pigs w 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.
pigs r 18

The output "1" stands for "high" or "0" for "low".

Troubleshooting
When executing the pigs commands, the error message "socket connect failed" appears. This does not mean that the pigpiod daemon is not running. You have to start it yet.

Commands to control "pigpiod"
Start pigpio daemon automatically at system startup:
sudo systemctl enable pigpiod

Disable system startup:
sudo systemctl disable pigpiod

Start pigpio daemon:
sudo systemctl start pigpiod

Stop pigpio daemon:
sudo systemctl stop pigpiod

Show status of the pigpio daemon:
sudo systemctl status pigpiod
Raspberry Pi
November 26, 2017
0

Comments

Search

Popular Posts

USB WiFi adapters that support monitor mode and wireless injection

usb wifi adapter with monitor mode and wireless injection (100% compatibl…

how to update Kali Linux and Fix update error

Kali Linux one of the best Linux distro for penetration testing it's freq…

Fix Kali Linux sources.list Repositories

Fix default repository First after installing a clean Kali Linux the sou…

Recent Comments

Contact Me