• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
kalitut

kalitut

KaliTut Where you learn about Kali Linux tips and Linux system

  • Home
  • Raspberry Pi
  • WRITE FOR US
  • Privacy Policy
  • About us

Configure Raspberry Pi GPIO at system startup

November 26, 2017 by Kalitut Leave a Comment

Raspberry Pi configure GPIO at system startup

Configure Raspberry Pi GPIO

Before you can use a GPIO as input or output, it must be configured or set. Unfortunately,  Raspberry Pi does not remember this setting. Therefore, the setting must be executed again each time the system is restarted.

Note
There are several ways to program and configure GPIOs. For example via “sysfs”, “wiringPi” or “pigpio”. We use “pigpio” here. This requires that the pigpio daemon be installed and enabled at system startup.

  • Control and program GPIO with “pigpio”

Solution: GPIO configuration in the file “/etc/rc.local”
The file “/etc/rc.local” is automatically loaded at system startup. Therefore, it is very well suited for configuring GPIOs at system startup.

For configuration we open the file “/etc/rc.local” and configure the configuration of the GPIOs.

sudo nano /etc/rc.local

Here we enter the following line before “exit 0” if we want the GPIO 17 (pin 11) to be configured as an output with the default state “low” (0).

pigs modes 17 w

Or we enter here the following lines before “exit 0”, if we want to have the GPIO 17 (pin 11) configured as output with the basic state “high” (1).

pigs modes 17 w
pigs w 17 1

Or we enter the following lines before “exit 0”, if we want the GPIO 17 to be configured as an input.

pigs modes 17 r

Then save and close: Ctrl + O, Return, Ctrl + X.

To try a restart is necessary.

sudo reboot

The file “/etc/rc.local” is executed relatively late. To be precise, just before the login request appears. This may be too late for one application or another. The question is, what state do the GPIOs have before running the file “/etc/rc.local”?

Raspberry Pi GPIO configuration via a Bash script

Typically, a script will be started at each boot to set the function of the required GPIO pins. This has the advantage that you can change the file without any root rights at any time.

First we create a script file:

sudo nano /home/pi/gpio.sh

In principle, we enter the same command in the script file as in the file “/etc/rc.local”.

#! /Bin/bash
{COMMAND}
exit 0

Then save and close: Ctrl + O, Return, Ctrl + X.

The file should then still be executable.

chmod + x /home/pi/gpio.sh

The call to the script is then entered in the file “/etc/rc.local”, if you want it to be executed automatically at boot time.

...
# Run a script for setting up GPIO pins
/home/pi/gpio.sh> /dev/null 2> & 1
exit 0

Then save and close: Ctrl + O, Return, Ctrl + X.

To test if this really works a reboot is necessary.

Filed Under: Raspberry Pi Tagged With: Raspberry Pi GPIO

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow us

  • Facebook
  • Twitter
  • YouTube

Write for us

  • WRITE FOR US

Categories

  • Android pentesting tools
  • Arduino
  • Books
  • Darknet
  • database
  • General
  • Github Tools
  • Kali Linux
  • Linux
  • Linux Commands
  • Network Administrator
  • Penetration Testing
  • Penetration Testing Tools
  • Raspberry Pi
  • resources
  • Review
  • Termux
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Video Tutorials
  • vmware
  • WiFi Adapter
  • WiFi Pentesting
  • Wireless Router
  • Wireshark

Recent Posts

  • Best hacking gadgets for security researchers
  • ntds-analyzer hashes analyzer
  • Scilla – Information Gathering tool
  • how to install google chrome in Kali Linux
  • Introduction to Security Penetration using Linux
  • Home
  • About us
  • Privacy Policy
  • Affiliate disclaimer

Copyright © 2021