Difference between revisions of "GPIO for NanoPi"
Jump to navigation
Jump to search
Line 37: | Line 37: | ||
cat /sys/class/gpio/gpio9/value | cat /sys/class/gpio/gpio9/value | ||
+ | |||
+ | = How to calculate linux gpio numbers = | ||
+ | |||
+ | A0 = gpio0 | ||
+ | A1 = gpio1 | ||
+ | A2 = gpio2 | ||
+ | .... | ||
+ | B0 = gpio32 | ||
+ | B1 = gpio33 | ||
+ | ... | ||
+ | C0 = gpio64 | ||
+ | ... |
Latest revision as of 09:43, 20 August 2022
GPIO (in/out) for NanoPi[edit]
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
How to calculate linux gpio numbers[edit]
A0 = gpio0 A1 = gpio1 A2 = gpio2 .... B0 = gpio32 B1 = gpio33 ... C0 = gpio64 ...