Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:common:applications:gpio:40pin-header

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 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

$ echo 465 | sudo tee /sys/class/gpio/export

Set-up GPIO direction

We can configure direction as input or output.

$ 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

$ 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

$ cat /sys/class/gpio/gpio465/value # Get GPIO input value

Unexport GPIO

$ 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 Device Tree Overlay configuration file to set the PIN as normal GPIO.

khadas@Khadas:~$ echo 465 | sudo tee /sys/class/gpio/export 
tee: /sys/class/gpio/export: Invalid argument
Last modified: 2023/08/16 06:33 by jacobe