Status of Orange Pi Boards GPIO Support

Yesterday, one person asked me to make a video showing GPIO control on Orange Pi 2 mini on YouTube, and since I have just completed a post about Orange Pi camera, I thought it might be fun to check GPIO support too. This post focuses on Allwinner H3 boards, but the instructions and status should be very similar for Allwinner A20 and A31s versions.

One of the first things you want before starting playing with GPIOs is the expansion header’s pinout chart, and I could not find any until I had the idea to check for schematics, which are available on Orange Pi resources page. I downloaded the schematics for Orange Pi 2, which should be the same as for Orange Pi 2 mini as the only difference is the lack of WiFi module. Orange Pi PC is a little different, and the schematics are nowhere to be found, but it would be surprising if the 40-pin connector had a different layout.

Orange Pi 2 (Mini) GPIO Pinout
Orange Pi 2 (Mini) GPIO Pinout

Some documentation would be nice too, and there’s a WiringPi for Orange Pi page in the wiki, which points to WiringOP on github, but unfortunately it does not exist [Update Nov 3, 2015: WiringOP is up on Github with the last changes 4 days ago]. A more generic GPIO page refers to RPi.GPIO, BCM2835 and WebioPi libraries, but again those sections are empty. After cheking in the forums, it seems there’s no GPIO library for Orange Pi boards. If somebody is interested in working on a GPIO library for Orange Pi, starting with LeMaker’s WiringBP for Banana Pro might be a good idea, as GPIO, SPI and I2C support is implemented. Banana Pro is based on Allwinner A20, so some registers and addresses might be different, but required technical information should be available in Allwinner H3 datasheet.

So instead I used sysfs to control the board’s I/Os. GPIO (gpio-sunxi), SPI (spi-sunxi), and I2C (i2c-sunxi) drivers are pre-installed in the Debian Jessie image I installed in Orange Pi 2 mini board, but today, I only played with GPIO on my board.

Using sysfs is pretty easy:

The few commands above load the GPIO driver, list the GPIOs, and turn on and off a green LED (D7) on the board.

To film a more entertaining video, I used the LED board from my Raspberry Pi perfboard enclosure which I connected to 9 GPIOs on the board, as well as 5V and GND. You can ignore IO-0, IO-2 on the schematics at the top,  as only the pin numbers (1 – 40) are used to wire the boards, and PA7, PA8, etc… are used to control the GPIOs from Linux.

I’ve written a shell script that turn on each LED, or group of LEDs, one by one every second, before turning them off every second in an infinite loop. That’s the result.

44 Replies to “Status of Orange Pi Boards GPIO Support”

  1. Thanks for sharing the GPIO info.

    IT is a pitty that the info on the official webpage is so bad.

    Good info would help the community build better images and librarles and boost the sales.
    But the seller is really crappy.

  2. @Carlos

    You get what you pay for. Default distributions are really crappy. Laboris’ distributions seem to be quite good, however he can’t test every function on every board. Ethernet does not work on OPI PC with his distributions. OPI forum did not allow me to register since 30 hours and to ask for help there…

  3. @slackstick
    slackstick, I used loboris’ debian image on an OPI PC and was able to bring up the ethernet interface, get an IP address via DHCP and ping other servers on the network. I haven’t done any more than that yet. Did you follow the instructions properly and copy over the correct script.bin file before booting the image?

  4. @camh
    OK I see, yesterday I went there and tried to click the link on Orange Pi 2 mini user’s manual, but nothing happened. Looks like I had to click on Google Drive icon instead…

    I can’t find manual for Orange Pi PC, but it should be pretty similar to Orange Pi 2 mini.

  5. Has anybody tried using an ftdi connected to the usb? did you get the drivers to work for the ft232rl? FTDI works fine in the usb ports of Cubieboard 2. Any luck with the uart pins in the GPIO? thanks in advance.

  6. @As1cK
    I’m not sure if you want to :
    1. Connect a USB to TTL debug to the UART pin of the boards, and to a USB port of a computer
    2. Connect that board to the USB port of the board itself to control/monitor something else.

    I’ve done (1) by connecting it to the three pin header as shown in in the second photo in that post:

    No problem to have it work.

    I have not tried (2)

  7. I need to use the same function of GPIO on RPi. How to activate GPIO interrupt function on Orange Pi PC with Allwinner H3? Have to wait for next version kernel? Please help.

  8. @cnxsoft
    H3 GPIO function configured in /sys/class/gpio_sw/P$xx/ files; cfg(for direction, o(in)or 1(out)), data(for read/write data 0 or 1), direction and data only? In same diretion, ‘drv’ and ‘pull’ files. those means ‘drv’ is for drive current configuration, and ‘pull’ is for pull down/up enable/disable configuration? If ‘edge’ function like RPi identified, Orangepi PC will be perfectly compatible with RPi GPIO. EXTINT function will be primary important issue for expanding more Orangepi PC market.
    Anyway, I will check more of your suggestion contents. Thanks!

  9. I could be missing something – but on my Orange Pi PC – that command of yours…

    modprobe gpio-sunxi – produces…

    modprobe: ERROR: could not insert ‘gpio_sunxi’: Exec format error

  10. @Peter Scargill
    I actually had the same problem. I was using the most recent version of Debian_jessie_mini.img from Google Drive (as of November 14th). But also got the “modprobe: ERROR: could not insert ‘gpio_sunxi’: Exec format error” error.I was able to fix this by downloading the desktop_scripts.tar.gz and running the script. (all files I’m referring to are available at see this thread from more info:

  11. Hello. I’ve got a problem using interrupt with WiringOP. In my C program I use the method wiringPiISR to catch an Input Change Event.
    if I run the program I’ve got the following error:
    wiringPiISR: unable to open /sys/class/gpio/gpio10/value: No such file or directory
    Actually the folder is missing.

    I read elsewhere that I’ve got to export the pin before using the method but if I execute
    gpio export 10 out
    I’ve the error
    gpio: Unable to open GPIO export interface: No such file or directory
    Again, the /sys/class/gpio/export is missing.

    Actually all the structure /sys/class/gpio/* is missing.
    Only the /sys/class/gpio_sw/* folders exist but is not good for gpio export command.

    Has anyone encountered the same problem?
    Any solution?

    thanks in advance

  12. Thanks for you answer, tkaiser.
    I’m sure I’m using lastest kernel and script.bin.
    I run the, in the past, and I did again fine minute ago (reboot and sudo depmod -a)

    Currently I’m using dietPI image (based on Debian loboris image) .
    But I had the same problem (missing folder /sys/class/gpio/* ) also with loboris image or raspbian.

    I found no solution in internet….

  13. @cnxsoft

    I also uses gpio_sw for normal pin use. It works very well. The problem is when using wiringop interrupt functionality (method wiringPiISR). It needs sys/class/gpio/ folders because it performs a gpio export that needs that folder.

    The error is:
    wiringPiISR: unable to open /sys/class/gpio/gpio10/value: No such file or directory

  14. Hello,

    what about reading data from GPIO pins? Why some of pings are named like PA, others is PC, PD or PG? What is the difference?

    I mean if i want to connect temperature sensor to some of these pins, which one i have to use?
    Thanks in advice

  15. @Kristian Kirilov
    The GPIOs are usually grouped in blocks, so A, C, P, G are just names. However, most pins usually has multiple uses e.g. GPIO, I2C, UART, one-wire, etc… and some may have different features (e.g. interrupt support), so you need to check the datasheet or at least the pinout diagram to find out which pin(s) is/are more suitable for your sensor. Your temperature sensor is likely using I2C or one-wire interface, so you may want to locate these pins.

    It’s quite likely somebody has already connect your sensors with other Linux based board, so to get the software part easily sorted out, simply search online with your sensor name + “linux” or “raspberry pi”.

  16. @cnxsoft
    It should be added that regarding 1-Wire all H3 OS images use pin 37 instead of the one normally used on Raspberry Pi. Loboris started with this setting and Armbian/OpenELEC decided to use it too to avoid confusion (even FriendlyARM chose the same pin with their OS images for NanoPi M1 🙂 )

    Loading or adding/uncommenting to/in /etc/modules the following is enough to make it work (applies to loboris, OpenELEC or Armbian images): w1-sunxi, w1-gpio and w1-therm.

  17. @cnxsoft have you been able to change the direction of GPIO pins on the Orange Pi PC 2 (H3) – I believe /sys/class/gpio_rw/PA*/cfg is used for that? Even after root permissions, setting the file to either 0 or 1 seemingly goes fine, but it will never actually change the contents (if you verify with cat).

    I managed to change it one time ever, now it refuses to work even after many reboots :/

  18. @javier
    I’m not sure. It may be possible to write a Python wrapper around the C code.

    While you can do many things with Python, if you are going to play with development boards, it’s always useful to know some C, in case you have to do some optimization (code in Python may be slower), debug some Linux driver code written in C, and so on… You may also end up using Arduino at some points, which uses C API.

  19. Hello!
    At a Armbian image put on Orange PI Lite (One) what i have to do to optain list of GPIO pins
    like in that commands:
    ls /sys/class/gpio_sw/
    normal_led PA10 PA13 PA18 PA20 PA6 PA9 PC2 PC7 PG7 PL10
    PA0 PA11 PA14 PA19 PA21 PA7 PC0 PC3 PD14 PG8 standby_led
    PA1 PA12 PA15 PA2 PA3 PA8 PC1 PC4 PG6 PG9
    when i do
    modprobe gpio-sunxi
    ls /sys/class/gpio_sw/
    folder gpio_sw appears, but is empty…

Leave a Reply

Your email address will not be published. Required fields are marked *