Home > Allwinner H-Series, Hardware, Linux, Testing, Video > Status of Orange Pi Boards GPIO Support

Status of Orange Pi Boards GPIO Support

September 26th, 2015 Leave a comment Go to comments

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.

  1. Carlos
    September 26th, 2015 at 23:46 | #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. slackstick
    September 27th, 2015 at 01:06 | #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. dvl36
    September 27th, 2015 at 02:24 | #3

    Ethernet work with laboris’ image on OPI PC. Using Debian Wheezy image at least.

  4. camh
    September 27th, 2015 at 08:11 | #4

    @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?

  5. camh
    September 27th, 2015 at 08:13 | #5

    The GPIO header pinouts are documented in the “user manual”. You can find that on the Orange Pi resources page (http://www.orangepi.org/downloadresources/) in the Software Design section. There appears to be a user manual for all the Orange Pi boards.

  6. camh
    September 27th, 2015 at 08:16 | #6

    There is a v1.1 H3 datasheet available linked from the linux-sunxi H3 page (http://linux-sunxi.org/H3). I don’t know the difference to the v1.0 datasheet linked in this article.

  7. September 27th, 2015 at 09:18 | #7

    @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.

  8. September 27th, 2015 at 09:20 | #8

    @slackstick
    I can also confirm Ethernet is working on Debian Jessie image by Loboris.
    I think Ethernet might be an issue when people mix up Orange Pi Plus and Orange Pi 2 images or script.bin/uImage. (TBC)

  9. slackstick
    September 27th, 2015 at 15:28 | #9

    @dvl36

    Thanks. You are right. The problem seems to be on the other side of the port.

  10. As1cK
    September 29th, 2015 at 04:56 | #10

    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.

  11. As1cK
    September 29th, 2015 at 05:01 | #11

    I’m trying to make the FTDI work in an Orange Pi Plus, but so far it doesn’t work.

  12. September 29th, 2015 at 09:26 | #12

    @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: http://www.cnx-software.com/2015/09/27/using-usb123-usbee-ax-pro-5-usb-logic-analyzer-with-pulseview-in-linux/

    No problem to have it work.

    I have not tried (2)

  13. emsen
    September 29th, 2015 at 15:13 | #13

    what is up with the orange pi price.

    its up 130% from just a week ago.

  14. September 29th, 2015 at 15:48 | #14

    @emsen
    Which Orange Pi? Orange Pi PC?

  15. T.Fuse
    October 9th, 2015 at 11:03 | #16

    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.

  16. October 9th, 2015 at 11:30 | #17
  17. Takanobu Fuse
    October 10th, 2015 at 07:03 | #18

    @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!

  18. October 18th, 2015 at 22:12 | #19

    @camh
    Nothing for Orange Pi PC

  19. October 18th, 2015 at 22:13 | #20

    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

  20. October 19th, 2015 at 09:19 | #21

    @Peter Scargill
    That’s weird, as if it was compiled for the wrong target (e.g. x86)…

    I used Debian 8 image (September 30) by Loboris.

  21. November 3rd, 2015 at 09:22 | #22

    WiringOP has been implemented @ https://github.com/zhaolei/WiringOP

  22. November 10th, 2015 at 09:38 | #23
  23. Bram Harmsen
    November 17th, 2015 at 04:11 | #24

    @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 update_kernel.sh script. (all files I’m referring to are available at https://drive.google.com/folderview?id=0B1hyW7T0dqn6fndnZTRhRm5BaW4zVDVyTGlGMWJES3Z1eXVDQzI5R1lnV21oRHFsWnVwSEU&usp=sharing#list see this thread from more info: http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=342&extra=page%3D1)

  24. dom
    January 27th, 2016 at 16:36 | #25

    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

  25. tkaiser
    January 27th, 2016 at 17:57 | #26

    @dom
    Did you ensure to use latest kernel+script.bin that’s been made for your board? Check http://filez.zoobab.com/allwinner/orangepi/mega/update_kernel.sh and optionally http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=785

  26. dom
    January 27th, 2016 at 22:27 | #27

    Thanks for you answer, tkaiser.
    I’m sure I’m using lastest kernel and script.bin.
    I run the update_kernel.sh, 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….

  27. January 28th, 2016 at 16:18 | #28

    @dom
    I used “/sys/class/gpio_sw/” to control the GPIOs in the example above.
    Are you sure /sys/class/gpio/ is what you need?

  28. dom
    January 28th, 2016 at 20:15 | #29

    @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

  29. dom
    February 28th, 2016 at 19:50 | #30

    Solution found. Look at this thread.
    http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=148&extra=&highlight=gpio%2Blibrary&page=7

    need to recompile the kernel with sysfs interface enabled and disable Gpio_sunxi
    I did so, and finally folder /sys/class/gpio/* appears and Interrupts work

    thanks to WereCatf

  30. tkaiser
    February 28th, 2016 at 20:00 | #31

    This should work out of the box with Armbian now. 5.04 has been released yesterday and supports all H3 Orange Pi boards: http://www.armbian.com/download/ (click there on the ‘Questions?’ link to display a short ‘Armbian H3 Mini FAQ’)

    We just created a new subsection for H3 right now: http://forum.armbian.com/index.php/forum/13-allwinner-h3/

  31. March 24th, 2016 at 14:55 | #32

    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

  32. March 24th, 2016 at 16:46 | #33

    @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”.

  33. tkaiser
    March 24th, 2016 at 17:02 | #34

    @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.

  34. March 24th, 2016 at 17:46 | #35

    Thanks guys

  35. Lennard Fonteijn
    May 26th, 2016 at 08:05 | #36

    @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 :/

  36. February 2nd, 2017 at 03:06 | #37

    Hi. How to control a servo using PWM? Is it possible? Thank you in advance.

  37. February 2nd, 2017 at 16:32 | #38

    @javier
    I can see people use PWM on Orange Pi Allwinner H3 Boards @ https://github.com/vlna/orange-pi-pwm

  38. February 2nd, 2017 at 19:03 | #39

    @cnxsoft
    Great, thanks for your response. I forget to say: in python… i don’t know c…. Sorry and thank you again.

  39. February 2nd, 2017 at 21:22 | #40

    @javier
    I’m not sure. It may be possible to write a Python wrapper around the C code. https://docs.python.org/2/extending/extending.html

    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.

  40. Dan
    February 3rd, 2017 at 19:17 | #41

    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
    and
    ls /sys/class/gpio_sw/
    folder gpio_sw appears, but is empty…

  41. February 3rd, 2017 at 19:28 | #42

    Ok, thanks. I will take a look

  42. February 4th, 2017 at 09:44 | #43

    @Dan
    I could list the GPIO in Orange Pi One with an older Armbian image @ http://www.cnx-software.com/2016/03/16/orange-pi-one-board-quick-start-guide-with-armbian-debian-based-linux-distribution/

    Are you sure gpio-sunxi module is loaded? You can check with lsmod.

  43. June 2nd, 2017 at 02:10 | #44

    Finally i figure it out how to move a servo with Orange Pi and Arduino. The text is spanish, but easy to understand or translate with google:

    http://orangepiweb.es/orange-pi-arduino.php

    Best regards.
    Javier

  1. No trackbacks yet.