Using GPIO from sysfs
Where to find GPIO's in sysfs
GPIO's are listed under /sys/class/gpio
Calculate Linux GPIO Number Freescale i.MX Processor Family
Linux GPIO Number = <GPIO_bank – 1> × 32 + <GPIO Port number>
Calculate Linux GPIO Number Texas Instruments Sitara Family
Linux GPIO Number = <GPIO_bank x 32> + <GPIO Port number>
Set GPIO as output
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
Set GPIO as Input
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