GPIO on Orange PI One Plus H6

The Orange PI One plus is one of the many Orange Pi boards offering interesting features:

  • processor ARM H6 Quad-Core 64 bits
  • ethernet 1GB
  • USB 2
  • HDMI
  • price <30€ including power supply -available at Aliexpress
Orange Pi One Plus

To access the GPIO of an Orange PI, you can use one of the libraries like OPI.Gpio. In the case of the Orange Pi One Plus, the python program head must make the following declarations:

import orangepi.oneplus
from OPi import GPIO

This library uses the Sysfs virtual filesystem introduced by the Linux kernel which allows system commands to activate GPIO pins. In the following lines we will deal with these commands without using the OPI.GPIO library.

While the Sysfs virtual file method is simple and adapts to all cards, it does not allow the input resistance to be set in PULLUP or PULLDOWN. In addition, the actions sometimes take ms which makes it impossible to check for a few micro seconds.

Connector Orange Py One Plus board

The One Plus board has a 26-pin connector according to the diagram below.

GPIO Orange Pi One Plus H6 Pinout

To address one of the input or output pins, you must find the reference of the corresponding GPIO. The table below is valid for the Orange Pi One Plus H6. So if you want to use pin 26, it corresponds to GPIO 227.

3TWI1-SDA / PH6 / GPIO23045V
7PWM1 / PH4 / GPIO2288UART2-RTS / PD21 / GPIO117
9GND10UART2-CTS / PD22 / GPIO118
11UART3-RX / PD24 / GPIO12012SDC2-D3 / PC9 / GPIO73
13UART3-TX / PD23 / GPIO11914GND
15UART3-CTS / PD26 / GPIO12216SDC2-D2 / PC8 / GPIO72
173.3V18SPI0-WP / PC7 / GPIO71
21SPI0-MISO / PC3 / GPIO6722UART3-RTS / PD25 / GPIO121
23SPI0-CLK / PC0 / GPIO6424SPI0-CS / PC5 / GPIO69
25GND26SPI1-CS / PH3 / GPIO227
Numbering pin / GPIO

Example Oscillator on pin 26

Below a program in python 3. Attention, important constraint. You must be root to access the GPIO.

#!/usr/bin/python3  Python 3 environment
#-- coding: utf-8 --
import os              # To execute system command
from time import sleep # this lets us have a time delay
print ("numgpio:"+numgpio)
os.system("sudo echo "+numgpio+" > /sys/class/gpio/export")
os.system("sudo echo out > /sys/class/gpio/gpio"+numgpio+"/direction")

         print ("Square signal around 50Hz . Press CTRL+C to exit")
         while True:
              os.system("echo 0 > /sys/class/gpio/gpio"+numgpio+"/value")
              os.system("echo 1 > /sys/class/gpio/gpio"+numgpio+"/value")

except KeyboardInterrupt:
         # set port/pin value to 0/LOW/False
         os.system("echo 0 > /sys/class/gpio/gpio"+numgpio+"/value") 
         # Clean GPIO
         os.system("sudo echo "+numgpio+" > /sys/class/gpio/unexport")
         print ("Bye from F1ATB.")

to launch it, if the program is on your desktop:

python3 /home/utilisateur/Desktop/

Orders can be entered by hand from a terminal window.
The … export command activates GPIO 227 which corresponds to pin 26.
The direction command, here out to be output.
The commands value alternately at 0 or 1 to make an oscillator.

Then in case of Ctrl-C, we finish cleanly by freeing the GPIO 227.

To get rid of the root issue, a solution can be to launch the program when starting the Orange PI which in this case is in root before going into user mode. Just modify the /etc/rc.local file (sudo nano /etc/rc.local). Put the launch command with the path in absolute (python. /Home/……py) before exit 0 of the rc.local file.

Posts on Remote-SDR

F1ATB André

Ham Radio - Home automation - Photovoltaic

You may also like...

3 Responses

  1. stef says:

    Hello, thank you for this detailed explanation but unfortunately it doesn’t help me with my current problem.
    I have also an OPIone+ and would like to implement this GPIO-Control with a relay(switch) in Octorint with the plugin “PSU Control” so that I will be able to switch the 3D printer on/off by software commands?
    With the PSU-Control plugin it´s possible to adjust some parameters (GPIO pins Gcode commands) which I tried with no success.
    Would be a pleasure if you could help me out here!

    • F1ATB André says:

      Are you in root? With GPIO you need to be in root or give the authorization to the user to access the GPIO.

      Put a file in /etc/sudoers.d/
      which contains:
      user_name ALL=(ALL) NOPASSWD: /usr/bin/python3

      if it’s a python3 application which access the GPIO


      • stef says:

        I tired it in PSU Control ( Switching -> System Command) with system functions like e.g. gpio write 117 1 and with echo 1 > gpio117/value (to switch the relay on) but did not work.

        By doing it in Armbian with following commands it works with no problems:

        root@orangepioneplus:~# cd /sys/class/gpio
        root@orangepioneplus:/sys/class/gpio# ls
        export gpiochip0 gpiochip352 unexport
        root@orangepioneplus:/sys/class/gpio# echo 117 > export
        root@orangepioneplus:/sys/class/gpio# ls gpio117
        active_low device direction power subsystem uevent value
        root@orangepioneplus:/sys/class/gpio# echo out > gpio117/direction
        root@orangepioneplus:/sys/class/gpio# cat gpio117/direction
        root@orangepioneplus:/sys/class/gpio# echo 1 > gpio117/value //ON
        root@orangepioneplus:/sys/class/gpio# echo 0 > gpio117/value //OFF