7

/boot/overlays/README has this text:

    act_led_trigger         Choose which activity the LED tracks.
                            Use "heartbeat" for a nice load indicator.
                            (default "mmc")

But are there other options? If I wanted to create my own (e.g. led constantly on until shutdown), where would I start? Is it recompiling a kernel module, or recompiling the entire kernel?

1

5 Answers 5

12

I have tried describing the values mentioned.

none                No trigger
kbd-scrolllock      Keyboard scroll lock
kbd-numlock         Keyboard num lock
kbd-capslock        Keyboard caps lock
kbd-kanalock        Keyboard kana lock
kbd-shiftlock       Keyboard shift
kbd-altgrlock       Keyboard altgr
kbd-ctrllock        Keyboard ctrl
kbd-altlock         Keyboard alt
kbd-shiftllock      Keyboard left shift
kbd-shiftrlock      Keyboard right shift
kbd-ctrlllock       Keyboard left ctrl
kbd-ctrlrlock       Keyboard right ctrl
timer               Flash at 1 second intervals
oneshot             Flash only once
heartbeat           Flash like a heartbeat (1-0-1-00000)
backlight           Always on
gpio                Flash when a certain GPIO is high???
cpu0                Flash on cpu0 usage
cpu1                Flash on cpu1 usage
cpu2                Flash on cpu2 usage
cpu3                Flash on cpu3 usage
default-on          Always on
[input]             Default state
panic               Flash on kernel panic
mmc0                Flash on mmc0 (primary SD Card interface) activity
mmc1                Flash on mmc1 (secondary SD Card interface) activity
rfkill0             Flash on wifi activity
rfkill1             Flash on bluetooth activity
4
  • Does default-on turn off after shutdown, or only when power is removed? Jul 14, 2017 at 15:00
  • default-on turns on only when Raspberry Pi is powered on. When the Pi shuts down, it turns off.
    – Ameer
    Jul 15, 2017 at 9:00
  • 1
    To test the modes, you can do echo heartbeat | sudo tee /sys/class/leds/led1/trigger (on Raspberry Pi 4) Jun 9, 2020 at 2:18
  • When I set dtparam=act_led_trigger=oneshot in /boot/config.txt, the LED is turned on all the time (the same for pwr_led_trigger and none value.) With heartbeat the LED really blinks in a heartbeat. Whis is that? echo oneshot | sudo tee /sys/class/leds/led0/trigger successfully turns off the LED.
    – sup
    Apr 4, 2021 at 10:12
4

Try any of the values in cat /sys/devices/platform/leds/leds/led0/trigger

3
  • Any documentation for those? Many look like they are tied to keyboard keys, but the others aren't as obvious: none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on [input] panic mmc0 mmc1 rfkill0 rfkill1 Jul 12, 2017 at 0:45
  • 1
    Documentation? This is the Pi we are talking about; the Foundation seems to be even worse at documentation than the average Linux programmer. You may find comments in the kernel source.
    – Milliways
    Jul 12, 2017 at 0:48
  • It looks like the implementation of the triggers are generic to the linux kernel, and not the pi (though the particular triggers available for a given led are pi specific?)- so the details can be found elsewhere if not just in the source (linuxkernel.stackexchange anybody?). drivers/leds/trigger has the source to many of the non kbd triggers. Jul 12, 2017 at 18:29
3

In this Makefile, you can find all the triggers chosen for a 5.4 kernel.

But I noticed that by cat /sys/devices/platform/leds/leds/led0/trigger, some triggers are not listed (e.g. "pattern" and "activity").

It turned out that they are compiled as kernel modules but not loaded by default. They are located under /lib/modules/[your kernel release]/kernel/drivers/leds/trigger, and you can find out your kernel release by uname -r.

Then you can either manually load the triggers by sudo modprobe ledtrig_xxx or add them to /etc/modules-load.d/xxx.conf to load automatically during boot time.

Finally, try cat /sys/devices/platform/leds/leds/led0/trigger again and play with the triggers :)

1
  • Nice answer! Welcome to the site, Lucian! Jul 22, 2020 at 12:05
1

I've tried and it works:

In /boot/config.txt:

dtparam=pwr_led_trigger=heartbeat

Enjoy.

1
  • 2
    surely you meant dtparam=act_led_trigger=heartbeat - to answer a question about the act_led_trigger Aug 15, 2018 at 2:32
0

Lucian's answer suggesting the Makefile prompted me to look into the related kernel source code.

When /sys/devices/platform/leds/leds/led1/trigger (same for led0) is set to gpio, then the virtual filesystem exposes additional 'files'; I will use gpio 35 to drive the red on-board led ("power led").

$ sudo sh -c "echo 'gpio' > /sys/class/leds/led1/trigger"
$ ls -lA /sys/class/leds/led1/
total 0
-rw-r--r-- 1 root root 4096 Aug  6 10:33 brightness
-rw-r--r-- 1 root root 4096 Aug  6 10:34 desired_brightness
lrwxrwxrwx 1 root root    0 Aug  6 10:33 device -> ../../../leds
-rw-r--r-- 1 root root 4096 Aug  6 10:34 gpio
-rw-r--r-- 1 root root 4096 Aug  6 10:34 inverted
-r--r--r-- 1 root root 4096 Aug  6 10:33 max_brightness
drwxr-xr-x 2 root root    0 Aug  6 10:33 power
lrwxrwxrwx 1 root root    0 Aug  6 10:33 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root    0 Aug  6 10:34 trigger
-rw-r--r-- 1 root root 4096 Aug  6 10:33 uevent
$ sudo sh -c "echo '255' > /sys/class/leds/led1/desired_brightness"
$ sudo sh -c "echo '35' > /sys/class/leds/led1/gpio"
$ echo 35 >  /sys/class/gpio/export 
$ echo 'out' > /sys/class/gpio/gpio35/direction 
$ echo '1' > /sys/class/gpio/gpio35/value 

Not the answer you're looking for? Browse other questions tagged or ask your own question.