-1

I'm trying to create gpio22 and gpio27 in sys/class/gpio/ and enable them, I'm using following command for the same:

echo "22" | sudo tee /sys/class/gpio/export
echo "27" | sudo tee /sys/class/gpio/export

Using the above commands I'm able to add/configure the pins, But every time I restart the system Gpio22 and Gpio27 disappear from the directory.

2 Answers2

0

The easiest way to run a program at boot is to edit the file rc.local. This is a file which contains lines of code to be run at boot time. Run sudo nano /etc/rc.local. Right before the line exit 0 in the file paste your code:

echo "22" | sudo tee /sys/class/gpio/export
echo "27" | sudo tee /sys/class/gpio/export

Save the file by pressing Ctrl-x then Y. Finally press Enter. Your lines of code will run every time at boot. If for some reason this does not work, here are a few other ways of doing it: https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/.

Quizzer515SY
  • 109
  • 4
0

The gpio directive allows GPIO pins to be set to specific modes and values at boot time. See https://www.raspberrypi.com/documentation/computers/config_txt.html#gpio

NOTE this is not using the deprecated sysfs interface, so if you want to subsequently change pins you will need another method.

https://raspberrypi.stackexchange.com/a/133252/8697 shows options

Milliways
  • 62,573
  • 32
  • 113
  • 225