How to install and use GPIO on NanoPi 2?

Average Man

I want to try some GPIO add on boards from the Raspberry Pi, but I can't
find any documentation on using the NanoPi 2 GPIO?

Can you share install/setup and usage instructions?


Hussam Al-Hertani
I see the i2c (/dev/i2c-0/1) and SPI (/dev/spidev0.0) buses but nothing for
PWM (no /dev/pwm).

Control of the GPIOs (via SYSFS) should be accessible through
'/sys/class/gpio' but it would be nice if someone more knowledgeable could
chime in on the proper way to access the GPIOs and PWM via built-in Linux
drivers and/or SYSFS.

If  you  want to use NanoPi 2 physical GPIO pins , you  can refer to
the following steps:

# cd /sys/class/gpio  

# for i in gpiochip* ; do  echo `cat $i/label`: `cat $i/base` ; done   







Actually the gpio.0 express GPIOA, gpio.1 express GPIOB...

For example , if you want to use GPIOB30 of NanoPi 2 , we can use the GPIO
such as :64 + 30 = 94.

hi @jjm,

do you have any simple example showing how to read/write GPIO via built-int
linux drivers? I read the code from and there is a
MACRO defined as below:

#define GPIO_FILENAME_DEFINE(pin,field) char fileName[255] = {0}; \
        sprintf(fileName, "/sys/devices/virtual/gpio/gpio%d/%s", pin,

but I checked the file system of Nanopi2 and could not find any GPIO files
under /sys/devices/virtual/, I guess this is because the GPIO device is not
"booted" but don't know how.

Hi you can refer to our Matrix components' wiki sites:
Here is one :

I would encourage you to post on which we visit
more often

Peter Scargill
Much of this is just WAY too complicated. Isn't there a module to help run
the GPIO pins?  These boards are in the same marketplace as Raspberry Pi
and there is a TON of documentation - and several drivers to run simple I/O
(on/off), PWM, I2c etc. We need similar for these boards.

I have a FriendlyArm NanoPC 2 running Jessie and Node-Red, I've only been
able to get 1 of the 4 UARTS running and can find nothing in the way of
examples of which ports are available and how to access them.

A simple guide with examples would help.

Hi you can refer the Matrix components' wiki sites , and there are much
more  course and code  you can refer :

I am trying to run matrix gpio-out on nano pi s2 to blink led but getting
these error?
what went wrong please reply?

fa@NanoPi2:~/matrix$ matrix-gpio_out
FAHW-Lib: Fail to initPinGPIO
FAHW-Lib: Fail to initPwmGPIO
Fail to init board


eMail (not visible)
Subject (no text only in upper case; no HELP, URGENT...)
HTML tags are not supported and links are generated automatically if they start with http or ftp.
Please submit long source code or log files as attachment (only registered users).
Please enter the number: 4 7 7 5