GPIO Access¶
Using Sysfs¶
The easiest way to access GPIOs is through sysfs. This works for all pins that haven’t been defined in the device tree and are being used by any driver.
To use a GPIO, it first needs to be exported and configured:
$ echo [gpio_number] > /sys/class/gpio/export
$ echo [in|out] > /sys/class/gpio/gpio[gpio_number]/direction
$ cat /sys/class/gpio/gpio[gpio_number]/value
$ echo [0|1] > /sys/class/gpio/gpio[gpio_number]/value
The gpio_number value can be calculated as follows.