What is SYS class GPIO?

What is SYS class GPIO?

GPIO (/ sys/class/gpio) is operated by file IO under Linux The GPIO operation interface includes direction and value, and direction controls the direction of GPIO, while value controls the output of GPIO or the input of GPIO. The file IO mode operates GPIO, using four functions open, close, read, write.

What is SYS class in Linux?

sys/class This subdirectory contains a single layer of further subdirectories for each of the device classes that have been registered on the system (e.g., terminals, network devices, block devices, graphics devices, sound devices, and so on).

Where can I Find my GPIO pin number?

You can use the file system directly to access GPIO pins using a terminal connection, scripts deployed to your Pi, or the file system interface of your programming environment. GPIO pins are exposed via the Linux sysfs file system at /sys/class/gpio/gpio [pin number], e.g. pin 17 would be accessible via /sys/class/gpio/gpio17.

How to export a GPIO pin in sysfs?

In order to use a GPIO pin through sysfs, we first have to “export” each one to make the appropriate paths available. The function exportPin at lines 16–21 does this. For example to export pin 9 it will use the following command (once all variables have been resolved to their values):

What does Bash do to the GPIO pins?

Without adding further dependencies, Bash scripts can access and control the Pi’s GPIO pins using sysfs. This presents as a set of filesystem paths which can be manipulated to configure individual pins as inputs or outputs and to set and read their values. On the Pi, these paths look like:

How do you calculate the GPIO number for a bank?

To calculate the GPIO number for a specific GPIO, use the following formula: gpio = (bank * 16) + pin. Bank numbers start with 0 (corresponding to Bank A), pin numbers start with 0 (corresponding to pin 0, etc).