Turning on and off Raspberry Pi’s LEDs for rapid physical identification.

My current project involves doing work with several Raspberry Pis and it gets frustrating, especially when you’re moving them around and changing SD cards, to remember which devices are which and which corresponds to a specific IP. One way people locate the Pi is by turning on or off the red and green LEDs. Most use the green LED or activity LED. The most common approach I have found to do this is documented below. One thing to note, and I found this issue on all my Pis running the most recent versions of Bullseye, is that when you run the commands you get something like:

pi@somepi:~ $ sudo echo 1 > /sys/class/leds/led0/brightness

-bash: /sys/class/leds/led0/brightness: Permission denied

The way around this, at least for me, was to use sudo bash -c “the string” and that works well. So the code to turn on and off a LED for quick identification of  a Pi is:

sudo  bash -c “echo 1 > /sys/class/leds/led0/brightness”

The green LED will be turned on to a solid green. You can do this to the red LED with led1 but in general, this is not very useful nor a good idea.

To reverse to default state:

sudo bash -c “echo 0 > /sys/class/leds/led0/brightness echo mmc0 > /sys/class/leds/led0/trigger”

You can, and I have started to do this, wire up a LED to the Pi and control that. This really makes sense when you use lots of Pi’s, for example, I am using 12, and it is painful to keep track of them when you constantly have to move them, replace SD cards and hats or radios and the like.

I found this tip here.

https://raspberrypi.stackexchange.com/questions/70593/turning-off-leds-on-raspberry-pi-3

About ordo tacitus

ordo tacitus
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment