Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

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

Edge2 IO GPIO header

An Edge2 IO board is needed.

Edge2 IO board 16 pins GPIO header, used for communication between board and different external devices.

Reference table

GPIO num Name Pin Pin Name GPIO num
VCC_3V3 1 9 SARADC
13 DEBUG_TX 2 10 VCC_1V8
14 DEBUG_RX 3 11 SPI1_MOSI 111
GND 4 12 SPI1_MISO 112
GND 5 13 SPI1_CSO 114
MCUSWDIO 6 14 SPI1_CLK 113
MCUSWCLK 7 15 I2C6_SCL 24
VCCMCU 8 16 I2C6_SDA 23

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
2022/06/30 00:01 · nick
Last modified: 2022/12/06 03:46 by nick