Using GPIO from sysfs

Where to find GPIO's in sysfs

GPIO's are listed under /sys/class/gpio

Linux GPIO Number = <GPIO_bank – 1> × 32 + <GPIO Port number>

example

Linux GPIO Number = <GPIO_bank x 32> + <GPIO Port number>

example

root@MBaXXX:~ echo <gpionr> > /sys/class/gpio/export                 // export GPIO pin
root@MBaXXX:~ echo out > /sys/class/gpio/gpio<gpionr>/direction      // set GPIO direction
root@MBaXXX:~ echo 1 > /sys/class/gpio/gpio<gpionr>/value            // toggle GPIO to high 
root@MBaXXX:~ echo 0 > /sys/class/gpio/gpio<gpionr>/value            // toggle GPIO to low 

example

root@MBaXXX:~ echo <gpionr> > /sys/class/gpio/export                 // export GPIO pin 
root@MBaXXX:~ echo in > /sys/class/gpio/gpio<gpionr>/direction       // set GPIO direction
root@MBaXXX:~ cat /sys/class/gpio/gpio<gpionr>/value                 // read GPIO value

example

  • Last modified: 2022/08/04 15:02