Orange PI Zero 2 H616 GPIO

The Orange PI Zero 2 is one of the many Orange Pi boards offering interesting features:

  • 64-bit ARM H616 4-core processor
  • 1GB ethernet
  • WIFI + BT
  • 512MB or 1GB RAM
  • USB 2
  • Micro HDMI
  • OS: DEBIAN. See article here for installation
  • price around 30 € at Aliexpress

To access the GPIO of an Orange PI, you can use one of the libraries (if it exists) or use the Sysfs virtual file system introduced by the Linux kernel which allows system commands to activate the GPIO pins.

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

Orange Pi Zero2 board connector

The Pi Zero 2 board has a 26-pin connector as shown in the diagram below.

Pinoutt Orange Pi Zero 2

Toaddress one of the input or output pins, you have to find the reference of the corresponding GPIO. The table below is valid for the Orange Pi Zero 2 H616. So if you want to use pin 10, it corresponds to GPIO 227. This table is for example different for an Orange Pi One Plus H6 or GPIO 227 corresponds to pin 26.

Numbering pin / GPIO

Example Oscillator on pin 10

Below is 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/user/Desktop/Nom_du_programme.py

You can enter commands manually from a terminal window.
The … export command activates the GPIO 227 which corresponds to pin 10.
The direction command, here out to be in output.
The commands value alternately to 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 problem, a solution can be to run the program when starting up the Orange PI which in this case is root before switching to user mode. All you have to do is modify the /etc/rc.local file (sudo nano /etc/rc.local). Put the launch command with the absolute path (python. /Home/……py) before exit 0 of the rc.local file. Another solution is a cron job.

Posts about the Orange Pi Zero 2

Leave a Reply

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