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?

Lucas Walter
  • 175
  • 1
  • 1
  • 6

5 Answers5

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
Ameer
  • 405
  • 3
  • 10
  • Does default-on turn off after shutdown, or only when power is removed? – Lucas Walter Jul 14 '17 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 '17 at 09:00
  • 1
    To test the modes, you can do echo heartbeat | sudo tee /sys/class/leds/led1/trigger (on Raspberry Pi 4) – Moritz Ringler Jun 09 '20 at 02:18
  • 1
    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 04 '21 at 10:12
5

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

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • 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 – Lucas Walter Jul 12 '17 at 00: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 '17 at 00: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. – Lucas Walter Jul 12 '17 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 :)

Lucian
  • 31
  • 2
1

I've tried and it works:

In /boot/config.txt:

dtparam=pwr_led_trigger=heartbeat

Enjoy.

Greenonline
  • 2,740
  • 4
  • 23
  • 36
MitchFR
  • 11
  • 1
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 
Lucas Walter
  • 175
  • 1
  • 1
  • 6
Al_
  • 11
  • 2