Accessing LEDs on Ubuntu (/sys/class/leds)

What is the correct way to write into the 4 LEDs on Linux? I tried the following command but I get ‘permission denied’ error.

$ cd /sys/class/leds/ap8016-sbc:green:user1
$ sudo echo 1 > brightness.

This command worked on the same device while running ‘Android’.
Build tried: boot-linaro-vivid-qcom-snapdragon-arm64-20150710-61.

hi,

as per the manual [1], the LEDs are pre configured as:

  • user LED #1: heartbeat trigger
  • user LED #2: eMMC trigger
  • user LED #3: SD card trigger
  • user LED #4: n/a

If you want to reassign an already configured LED, you need to remove the preconfigured trigger first, e.g. run as root:


cd /sys/class/leds/apq8016-sbc:green:user1
echo none > trigger
echo 255 > brightness

Also, the ‘permission denied’ error is because of your command line, if you need to use ‘sudo’ and ‘>’, then you need to run:

sudo bash -c "echo 1 > brightness"

[1] https://github.com/96boards/documentation/wiki/Dragonboard-410c-Installation-Guide-for-Linux-and-Android#leds

Thank you ! I will give this a try.

Why should we need sudo/root access to work with sys/class? How do we add privileges for “linaro” to access /sys/class and /dev/i2c, uart, spi extra?

Tried adding linaro to sys group, didn’t help.

linaro@linaro-alip:~$ sudo usermod -a -G sys linaro
linaro@linaro-alip:~$ groups linaro
linaro : linaro sys adm dialout cdrom audio dip video plugdev pulse-access bluetooth admin
linaro@linaro-alip:~$ echo 1 > /sys/class/leds/apq8016-sbc:green:user3/brightness
-bash: /sys/class/leds/apq8016-sbc:green:user3/brightness: Permission denied

hi,

this is basically a ‘distro’ policy, and this is how it is being done in Ubuntu/Debian. I am not in favor of changing this policy in our own builds…

Understood. Let’s suppose I use a GUI text editor to write a C program that access GPIOs or LEDs, I then somehow invoke the Makefile from within the text editor (which is running under linaro group) - In this case my program will not be able to access GPIOs or LEDs. Are there any alternatives to achieve this?

I am not expert in Linux but made some of the small projects on LEDs blinking using the some standard boards.
I have gone through your commands and these are looking fine and working.The suggestions given by other members are also looking working.
I will try for your problem and will post a solution if i find any alternate solution for this.