Raspberry Pi GPIO libraries don't target Orange Pi SoCs. Orange Pi's answer is wiringOP, a port of wiringPi, plus Python bindings.
Install wiringOP (C library + gpio tool)
sudo apt-get update && sudo apt-get install -y git
git clone https://github.com/orangepi-xunlong/wiringOP.git
cd wiringOP
sudo ./build clean
sudo ./build
Read the pin map first
gpio readall
prints a table for your board:
| Column | Meaning |
|---|---|
GPIO |
Linux GPIO number (what the kernel's GPIO interface uses) |
wPi |
wiringPi number (what wiringOP functions use after wiringPiSetup()) |
Name |
function or port name, e.g. SDA.1, TXD.2, PC07 |
Mode / V |
current mode (IN, OUT, ALT…, OFF) and level |
Physical |
the pin number on the header |
Three different numbers for the same pin. Mixing them up is the most common GPIO bug on these boards. The wiringOP README shows separate maps per SoC and model (H2+, H3, H5, …), and the numbers differ between models, so code written for one Orange Pi needs its pin numbers checked on another.
Python: wiringOP-Python
sudo apt-get install -y swig python3-dev python3-setuptools
git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python.git
cd wiringOP-Python
python3 generate-bindings.py > bindings.i
sudo python3 setup.py install
import time
import wiringpi
wiringpi.wiringPiSetup() # must be called before any IO function; uses wPi numbers
LED = 6 # wPi number, check with `gpio readall` on YOUR board
wiringpi.pinMode(LED, 1) # 1 = OUTPUT
for _ in range(5):
wiringpi.digitalWrite(LED, 1)
time.sleep(0.5)
wiringpi.digitalWrite(LED, 0)
time.sleep(0.5)
print(wiringpi.digitalRead(LED))
Tips
- Pins used by an enabled interface (I2C, SPI, UART via overlays) show
ALTmodes inreadall; don't drive them as plain GPIO. - Check the logic level in your model's manual before connecting 5 V sensors; use a level shifter when in doubt.