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
  • OS: ARMBIAN .
  • 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.

13.3V25V
3TWI1-SDA / PH6 / GPIO23045V
5TWI1-SCK / PH5 / GPIO2296GND
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
19SPI0-MOSI/ PC2 / GPIO6620GND
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
numgpio=227
numgpio=str(numgpio)
print ("numgpio:"+numgpio)
os.system("sudo echo "+numgpio+" > /sys/class/gpio/export")
os.system("sudo echo out > /sys/class/gpio/gpio"+numgpio+"/direction")

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


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/Nom_du_programme.py

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

Leave a Reply

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