Difference between revisions of "GPIO for NanoPi"
Jump to navigation
Jump to search
(Created page with "== GPIO (in/out) for NanoPi == Note: the test environment is a NanoPi K1 Plus with FriendlyCore installed in eMMC, kernel 4.14.x . To enable a pin, execute: echo X > /sys/...") |
|||
Line 21: | Line 21: | ||
and the directory/symbolic link gpio9 will disappear. | and the directory/symbolic link gpio9 will disappear. | ||
− | To set the | + | To set the direction (input or output pin), we need to execute: |
+ | |||
+ | echo out > /sys/class/gpio/gpio9/direction | ||
+ | |||
+ | or | ||
+ | |||
+ | echo in > /sys/class/gpio/gpio9/direction | ||
+ | |||
+ | To set the value: | ||
+ | |||
+ | echo 0 > /sys/class/gpio/gpio9/value | ||
+ | echo 1 > /sys/class/gpio/gpio9/value | ||
+ | |||
+ | To read the value | ||
+ | |||
+ | cat /sys/class/gpio/gpio9/value |
Revision as of 13:24, 1 March 2020
GPIO (in/out) for NanoPi
Note: the test environment is a NanoPi K1 Plus with FriendlyCore installed in eMMC, kernel 4.14.x .
To enable a pin, execute:
echo X > /sys/class/gpio/export
where X is the number of the linux gpio corresponding to the pin you want to enable.
For example, if we want to enable pin N. 37, according to the table in http://wiki.friendlyarm.com/wiki/index.php/NanoPi_K1_Plus#Diagram.2C_Layout_and_Dimension , we need to execute:
echo 9 > /sys/class/gpio/export
A new /sys/class/gpio/gpio9 directory will appear.
In the same way, to disable the pin we need to execute:
echo 9 > /sys/class/gpio/unexport
and the directory/symbolic link gpio9 will disappear.
To set the direction (input or output pin), we need to execute:
echo out > /sys/class/gpio/gpio9/direction
or
echo in > /sys/class/gpio/gpio9/direction
To set the value:
echo 0 > /sys/class/gpio/gpio9/value echo 1 > /sys/class/gpio/gpio9/value
To read the value
cat /sys/class/gpio/gpio9/value