The board is sitting on my desk running the latest version of Armbian. One green LED is lit up, and there is another red LED somewhere. (The red LED is right next to the green one, as we discover below).
Linux has this whacko GPIO interface, and that can be used via the filesystem to screw with the LED's.cd /sys/class/leds uname -a Linux orangepipc2 5.4.43-sunxi64 #20.05.2 SMP Tue Jun 2 17:20:17 CEST 2020 aarch64 GNU/Linux tom@orangepipc2:/sys/class/leds$ ls -l total 0 lrwxrwxrwx 1 root root 0 Jan 1 1970 orangepi:green:pwr -> ../../devices/platform/leds/leds/orangepi:green:pwr lrwxrwxrwx 1 root root 0 Jan 1 1970 orangepi:red:status -> ../../devices/platform/leds/leds/orangepi:red:statusFollowing the above links, we see:
cd /sys/devices/platform/leds/leds ls -l drwxr-xr-x 3 root root 0 Jan 1 1970 orangepi:green:pwr drwxr-xr-x 3 root root 0 Jan 1 1970 orangepi:red:status ls -l * 'orangepi:green:pwr': total 0 -rw-r--r-- 1 root root 4096 Aug 16 22:28 brightness lrwxrwxrwx 1 root root 0 Aug 16 22:28 device -> ../../../leds -r--r--r-- 1 root root 4096 Aug 16 22:28 max_brightness drwxr-xr-x 2 root root 0 Aug 11 03:01 power lrwxrwxrwx 1 root root 0 Jan 1 1970 subsystem -> ../../../../../class/leds -rw-r--r-- 1 root root 4096 Aug 16 22:28 trigger -rw-r--r-- 1 root root 4096 Jan 1 1970 uevent 'orangepi:red:status': total 0 -rw-r--r-- 1 root root 4096 Aug 16 22:28 brightness lrwxrwxrwx 1 root root 0 Aug 16 22:28 device -> ../../../leds -r--r--r-- 1 root root 4096 Aug 16 22:28 max_brightness drwxr-xr-x 2 root root 0 Aug 11 03:01 power lrwxrwxrwx 1 root root 0 Jan 1 1970 subsystem -> ../../../../../class/leds -rw-r--r-- 1 root root 4096 Aug 16 22:28 trigger -rw-r--r-- 1 root root 4096 Jan 1 1970 ueventTyping the following turns on the red LED and off the green LED:
echo 1 >/sys/class/leds/orangepi\:red\:status/brightness echo 0 >/sys/class/leds/orangepi\:green\:pwr/brightness
su /sys/class/gpio tom@orangepipc2:/sys/class/gpio$ ls -al total 0 drwxr-xr-x 2 root root 0 Jan 1 1970 . drwxr-xr-x 58 root root 0 Jan 1 1970 .. --w------- 1 root root 4096 Jan 1 1970 export lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip0 -> ../../devices/platform/soc/1c20800.pinctrl/gpio/gpiochip0 lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip352 -> ../../devices/platform/soc/1f02c00.pinctrl/gpio/gpiochip352 --w------- 1 root root 4096 Jan 1 1970 unexportTo access a pin, you have to write the number to the export "file"
echo 2 > /sys/class/gpio/exportAfter doing this, a new "file" appears:
lrwxrwxrwx 1 root root 0 Aug 17 03:55 gpio2 -> ../../devices/platform/soc/1c20800.pinctrl/gpiochip1/gpio/gpio2 echo out > /sys/class/gpio/gpio2/direction echo 1 > /sys/class/gpio/gpio2/valueThis is all done via sysfs
root@orangepipc2:/sys/class/gpio# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)However, sysfs for gpio is now deprecated:
0x01C20800 is the base address for the first 7 (A-G).
0x01F02c00 is the base address for the last "special" GPIO (J).
The red LED is the "status" LED and is bit 15 on GPIO A
The green LED is the "power" LED and is bit 10 on GPIO J (the special GPIO).
These bit numbers start counting at 0.
Tom's electronics pages / tom@mmto.org