-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.

5
  • "But every time I restart the system ..." -- That's how it is designed to work. Sysfs is a pseudo-filesystem; sysfs is simply not a permanent filesystem, and is regenerated on each boot. Learn how to use the newer gpiolib.
    – sawdust
    Nov 24, 2021 at 10:02
  • @sawdust thanks for your answer. I'm not using any libraries currently to enable these pins and I don't prefer installing any new libraries onto the system I'm working on. Can you please suggest any other way to permanently enable these pins? Nov 24, 2021 at 11:34
  • @sawdust why not make that an answer?
    – joan
    Nov 24, 2021 at 11:35
  • create a systemd service
    – Bravo
    Nov 24, 2021 at 11:36
  • 1
    @Droidverine Arch is intended for experts. You might be better off using the standard Raspberry OS.
    – joan
    Nov 24, 2021 at 11:36

2 Answers 2

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/.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.