Skip to content

Control Gpio

RAKwireless edited this page Sep 26, 2017 · 2 revisions

Here to Control Gpio

To Use Shell Command


First you have to access the serial console - setup console, in the terminal. Then power on,and input command in the terminal

Step 1 Enter Gpio Control Directory

cd /sys/class/gpio

Step 2 Enable Gpio, such as gpio38

echo 38 > export

Then you will find a directory gpio38

Step 3 Control Gpio

cd gpio38

ls

Then you will find some files in this directory,and we usually use "value" and "direction "

  • value:gpio value, low level: 0, high level: 1

get value

cat value

set value

echo 0/1 > value
  • direction: include some modes

in: to set gpio "input mode"

echo in > direction

out: to set gpio "output mode"

echo out > direction

low:to set gpio "output mode", and value=0

echo low > direction

cat value

high:to set gpio "output mode", and value=1

echo high > direction

cat value

Step 4 Disable Gpio

cd ../

echo 38 > unexport

## To Use Api

Use I/O opration to control gpio,and we have provided the api - to use RKGpioApi.c

  • Enable Gpio: RK_GpioOpen();

  • Set Value: RK_GpioWrite();

  • Gey Value: RK_GpioRead();

  • Set Edge(not necessary): RK_GpioEdge();

  • Disable Gpio: RK_GpioClose();

and if you need file descriptor of value, use:

  • Open Gpio Value and return fd: RK_GpioValueOpen();

  • Close Gpio Value: RK_GpioValueClose();