How to enable GPIO pins permanently

In my work, I enabled two pins in the J21 connector as output.
This is my script:

sudo -s
echo 255 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio255/direction
chmod +w /sys/class/gpio/gpio255/value


  1. I cannot just run this script in the terminal. The system is showing “… Permission denied” for each line.
    But everything works well if I run each command separately.
  2. When I restart my Tegra I should always run these commands again. How can I enable this pins constantly?

Thank you

hello igor.fedorov,

may I know which GPIO pin you would like to control.
please access Jetson TX2 Platform Adaptation and Bring-Up Guide via download center.
you should check [GPIO Changes] session for the formula of the gpio number calculation,
you might also checking kernel message about the allocation range.

please also refer to documentation, Jetson TX2 Pinmux and GPIO Configuration.
we usually have customize pinmux spreadsheet to have pinmux and gpio configuration.

I would like to control gpio255 (GPIO_GEN3) according to this NVIDIA Jetson TX2 J21 Header Pinout
This pin I can enable or unenable when my program is running. The problem when I reboot Tegra this pin configuration is not saved.


I think I solved the problem.

I typed this command into rc.local

nvidia@tegra-ubuntu:~$ sudo su
root@tegra-ubuntu:/home/nvidia# nano /etc/rc.local
#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.


echo 255 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio255/direction
chmod +w /sys/class/gpio/gpio255/value

echo 254 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio254/direction
chmod +w /sys/class/gpio/gpio254/value

exit 0

Now, I dont need to enable pins again after rebooting.

Glad to know issue resolved, thanks for the update.