linux operation GPIO command

 

Step 1. Use the echo command on the console to export the GPIO number to be operated:

echo N > /sys/class/gpio/export

After export, the /sys/class/gpio/gpioN directory will be generated.

Step 2: Use the echo command on the console to set the GPIO direction:
1. For input

echo in > /sys/class/gpio/gpioN/direction

2. For output

echo out > /sys/class/gpio/gpioN/direction

3. Use the cat command to view the GPIO direction

cat /sys/class/gpio/gpioN/direction

 

Step 3: Use cat or echo command on the console to view the GPIO input value or set the GPIO output value:
1. View the input value

cat /sys/class/gpio/gpioN/value

2. Low output

echo 0 > /sys/class/gpio/gpioN/value

3. High output

echo 1 > /sys/class/gpio/gpioN/value

 

Step 4: Use the echo command on the console to unexport the number of the operated GPIO:

echo N > /sys/class/gpio/unexport

During the demonstration, I encountered a problem with step one:

Please Check GPIOB05's multi-function = 0x9

It is found that other functions occupy the pin. If it needs to be exposed, the occupied part of the function needs to be removed.

echo 131 > export        //暴露接口
cd gpio131
echo out > direction    //设置方向
echo 1 > value          //设置输出电平值  0低  1高
 

 

Guess you like

Origin blog.csdn.net/weixin_38293850/article/details/110964190