Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Controlling Raspberry Pi 2 LEDs

Commands for controlling the Raspberry Pi 2 LEDs.

See rpi-leds for a node module that does this.

Power (PWR) LED

  • OK (ACT) LED = led0
  • Power (PWR) LED = led1

Allow access

echo gpio | sudo tee /sys/class/leds/led0/trigger
echo gpio | sudo tee /sys/class/leds/led1/trigger

Heartbeat effect

echo heartbeat | sudo tee /sys/class/leds/led0/trigger
echo heartbeat | sudo tee /sys/class/leds/led1/trigger

Timer effect

echo timer | sudo tee /sys/class/leds/led0/trigger
echo timer | sudo tee /sys/class/leds/led1/trigger

Turn on/off

echo 1 | sudo tee /sys/class/leds/led0/brightness
echo 0 | sudo tee /sys/class/leds/led0/brightness

echo 1 | sudo tee /sys/class/leds/led1/brightness
echo 0 | sudo tee /sys/class/leds/led1/brightness

Revert back to default setting

echo input | sudo tee /sys/class/leds/led1/trigger
echo mmc0 | sudo tee /sys/class/leds/led0/trigger

Notes

Resources

LED trigger original values:

pi@raspberrypi ~ $ cat /sys/class/leds/led1/trigger
none mmc0 timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on [input] rfkill0
pi@raspberrypi ~ $ cat /sys/class/leds/led0/trigger
none [mmc0] timer oneshot heartbeat backlight gpio cpu0 cpu1 cpu2 cpu3 default-on input rfkill0
@wsmoak

This comment has been minimized.

Show comment
Hide comment
@wsmoak

wsmoak Dec 25, 2015

On a Raspberry Pi 2 Model B purchased from Adafruit (with their pre-loaded card) I found that the green led is controlled with /sys/class/leds/ACT/trigger and /brightness. The ACT directory is a symlink, and the files are only writeable by root.

wsmoak commented Dec 25, 2015

On a Raspberry Pi 2 Model B purchased from Adafruit (with their pre-loaded card) I found that the green led is controlled with /sys/class/leds/ACT/trigger and /brightness. The ACT directory is a symlink, and the files are only writeable by root.

@JamesTheAwesomeDude

This comment has been minimized.

Show comment
Hide comment
@JamesTheAwesomeDude

JamesTheAwesomeDude Apr 9, 2016

$ cat /sys/class/leds/led1/trigger
none mmc0 timer oneshot heartbeat backlight gpio cpu0 default-on [input]
$ 

What does that do??

$ cat /sys/class/leds/led1/trigger
none mmc0 timer oneshot heartbeat backlight gpio cpu0 default-on [input]
$ 

What does that do??

@ricknoelle

This comment has been minimized.

Show comment
Hide comment
@ricknoelle

ricknoelle Oct 8, 2017

James, that tells you the possible values and the current value. The brackets surround the current value (in your listing it is input), all the rest are possible values. To change the value, you can use an echo command similar to those in the gist.

James, that tells you the possible values and the current value. The brackets surround the current value (in your listing it is input), all the rest are possible values. To change the value, you can use an echo command similar to those in the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment