{{indexmenu_n>1}} ====== GPIO Header ====== ===== GPIO usage examples ===== Please make sure that the GPIOs you want to use are not configured as other functions, if they are, you can follow [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]] to configure them as normal GPIOs. When you get the GPIO number, you can follow the steps below to control it. Here we take GPIO number ''465'' as an example. ==== Export GPIO ==== ```shell $ echo 465 | sudo tee /sys/class/gpio/export ``` ==== Set-up GPIO direction ==== We can configure direction as input or output. ```shell $ echo out | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO output $ echo in | sudo tee /sys/class/gpio/gpio465/direction # Set GPIO input ``` ==== Set GPIO value ==== ```shell $ echo 1 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output high $ echo 0 | sudo tee /sys/class/gpio/gpio465/value # Set GPIO output low ``` ==== Get GPIO value ==== ```shell $ cat /sys/class/gpio/gpio465/value # Get GPIO input value ``` ==== Unexport GPIO ==== ```shell $ echo 465 | sudo tee /sys/class/gpio/unexport ``` ==== Troubleshooting ==== If you got the similar error below, it means that the PIN you try to export is used for another function, you need to edit [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]] configuration file to set the PIN as normal GPIO. ```shell khadas@Khadas:~$ echo 465 | sudo tee /sys/class/gpio/export tee: /sys/class/gpio/export: Invalid argument ```