I finally figured out how to do simple I/O on the GPIO pins on the Orange Pi Zero. It’s actually the same as Raspberry Pi and it relies on /sys/class/gpio/
Most important: Use Armbian, and I in particular use 3.4.113 (legacy).
GPIO
Linux GPIO |
SOC |
Label |
CON4 |
CON4 |
Label |
SOC |
Linux GPIO |
|
|
Vcc3V3-EXT |
1 |
2 |
DCIN-5V |
|
|
12 |
PA12 |
TWI0-SDA |
3 |
4 |
DCIN-5V |
|
|
11 |
PA11 |
TWI0-SCK |
5 |
6 |
GND |
|
|
6 |
PA6 |
PWM1 |
7 |
8 |
UART1_TX |
PG6 |
198 |
|
|
GND |
9 |
10 |
UART1_RX |
PG7 |
199 |
1 |
PA1 |
UART2_RX |
11 |
12 |
PA7 |
PA7 |
7 |
0 |
PA0 |
UART2_TX |
13 |
14 |
GND |
|
|
3 |
PA3 |
UART2_CTS |
15 |
16 |
TWI1-SDA |
PA19 |
19 |
|
|
VCC3V3-EXT |
17 |
18 |
TWI1-SCK |
PA18 |
18 |
15 |
PA15 |
SPI1_MOSI |
19 |
20 |
GND |
|
|
16 |
PA16 |
SPI1_MISO |
21 |
22 |
UART2_RTS |
PA2 |
2 |
14 |
PA14 |
SPI1_CLK |
23 |
24 |
SPI1_CS |
PA13 |
13 |
|
|
GND |
25 |
26 |
PA10 |
PA10? |
|
Note: PA10 does not seem to work.
To enable one GPIO pin, do this as root:
echo 7 >/sys/class/gpio/export
chmod a+rw /sys/class/gpio/gpio7/*
Now in NodeJS you can do (as non-root):
var Gpio = require('onoff').Gpio,
led = new Gpio(7, 'out');
function blinkled7() {
var state=false;
return function () {
console.log(state);
if (state) led.writeSync(0)
else led.writeSync(1);
state = ! state;
}
}
f=blinkled7();
setInterval(f, 1000);
which blinks GPIO pin 7 (AKA PA7). You can also watch pins:
var Gpio = require('onoff').Gpio,
led = new Gpio(7, 'out'),
button = new Gpio(16, 'in', 'both');
button.watch(function (err, value) {
if (err) {
throw err;
}
console.log("Changing to ", value);
led.writeSync(value);
});
process.on('SIGINT', function () {
console.log("Leaving...");
led.unexport();
button.unexport();
});
which makes the LED match what PA16 is. If you connect PA16 to e.g. PA6, you can change PA6, which is detected by PA16 which is reflected in the LED change on PA7!
LED’s
The 2 on-board LED’s can be controlled via
echo [0|1] > /sys/class/leds/[red|green]_led/brightness
which map to PA17 (red) and PL10 (green), but those are (of course) claimed by the LED driver.
PWM
Not figured out yet.