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.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
44 Comments
oldest
newest
Carlos
Carlos
9 years ago

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.

slackstick
slackstick
9 years ago

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

dvl36
dvl36
9 years ago

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

camh
camh
9 years ago

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

camh
camh
9 years ago

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.

camh
camh
9 years ago

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.

slackstick
slackstick
9 years ago

@dvl36

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

As1cK
As1cK
9 years ago

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.

As1cK
As1cK
9 years ago

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

emsen
emsen
9 years ago

what is up with the orange pi price.

its up 130% from just a week ago.

T.Fuse
T.Fuse
9 years ago

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.

Takanobu Fuse
Takanobu Fuse
9 years ago


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!

Peter Scargill
9 years ago

@camh
Nothing for Orange Pi PC

Peter Scargill
9 years ago

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

Bram Harmsen
Bram Harmsen
9 years ago

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

dom
dom
8 years ago

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… Read more »

tkaiser
tkaiser
8 years ago

@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

dom
dom
8 years ago

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

dom
dom
8 years ago

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

dom
dom
8 years ago

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

tkaiser
tkaiser
8 years ago

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/

Kristian Kirilov
8 years ago

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

tkaiser
tkaiser
8 years ago


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.

Kristian Kirilov
8 years ago

Thanks guys

Lennard Fonteijn
Lennard Fonteijn
8 years ago

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

javier
7 years ago

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

javier
7 years ago


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

Dan
Dan
7 years ago

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…

javier
7 years ago

Ok, thanks. I will take a look

Javier
7 years ago

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

Boardcon Rockchip RK3588S SBC with 8K, WiFI 6, 4G LTE, NVME SSD, HDMI 2.1...