Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

There are 5 LEDs on the RPi: OK, PWR, FDX, LNK, 10M.

I'd like to know if it's possible to control any of these from software i.e. turn them on, or change intensity (or even change colour gasp).

And if so, where can I read up about it? The LEDs could be quite handy way of signalling user application status when they are not required for the original use.

share|improve this question
1  
And yes - I know I can add LEDs easily onto the GPIO outputs - but I'm curious what can be done without external hardware. –  Maria Zverina Jun 25 '12 at 20:10
1  
LEDs are generally single colour (especially when required for one purpose), so you can forget about that part :) –  Jivings Jun 26 '12 at 0:11
1  
@Jivings Agree that they're probably single colour given RPi's cost ... but it never hurts to ask :) –  Maria Zverina Jun 26 '12 at 8:19

4 Answers 4

up vote 30 down vote accepted

The OK LED can be controlled from user space software. Details here:

http://www.raspberrypi.org/phpBB3//viewtopic.php?p=136266#p136266

Summarised from the above (all credit to BrianW):

The OK LED is available as /sys/class/leds/led0/

The kernel LED driver has "triggers" which let some other part of the kernel control the LED. The default trigger for the LED is 'mmc0', which makes it come on when the SD card is accessed.

root@raspberrypi:~# cat /sys/class/leds/led0/trigger
none [mmc0]

You can deactivate the mmc0 trigger as follows:

echo none >/sys/class/leds/led0/trigger

The LED can be turned on and off using the 'brightness' file. The minimum brightness is 0, and the maximum is 255. As there is no variable brightness support, any value greater than 0 will turn the LED on.

echo 1 >/sys/class/leds/led0/brightness
echo 0 >/sys/class/leds/led0/brightness

atically sets the trigger to "none"

If you want the LED to go back to its default function:

echo mmc0 >/sys/class/leds/led0/trigger

There are a couple of kernel modules you can load up (ledtrig_timer and ledtrig_heartbeat) which will flash the LED for you.

modprobe ledtrig_heartbeat
echo heartbeat >/sys/class/leds/led0/trigger

Once you have turned off the mmc0 trigger, you can use GPIO16 to control the LED. It's active-low, so you need to set the pin low to turn the LED on, and high to turn it off.

From Python, you can use the module RPi.GPIO to control pin 16. There is also a C# driver.

share|improve this answer
2  
Hello Guy! In order to prevent link rot can you summarize the main points of the thread here? Thanks! –  Bryan Dunsmore Aug 9 '12 at 2:52
    
That's not even a hack! –  Alex Chamberlain Aug 9 '12 at 8:48
    
That's right. Sure the ethernet and pwr leds can't, but if you need more they can just be added (as hardware) to the exposed GPIO pins. There are many examples of adding LEDs to the GPIO pins. It seems to have replaced the crystal set as electronics 101 these days :) I have my OK LED flashing each time a NMEA sentence is received on the UART. –  Guy Aug 9 '12 at 9:00

None of the on board LEDs can be controlled in software - they are all used for other things.

  • OK - indicates SD card access
  • PWR - indicates power to the micro USB connection
  • FDX - Full Duplex LAN
  • LNK - LAN Activity
  • 10M - 10M/100M connection speed - if it is lit, the RPi is connected at 100M.

Now, that's the official answer... Let's study the schematic.

Page 4 The PWR LED is connected directly to the power supply, so we can't control that in software.

Page 3 FDX, LNK and 10M are all connected to the Ethernet chip, so again we can't control them in software (without some funky traffic hack...).

Page 4 BUT OK is actually controlled by GPIO 16, so there is the possibility of a hack...

share|improve this answer
    
@AlexChamberlain Nice definition of the LEDs. But are we really sure they can't be controlled by software? Are network LEDs under firmware control or the actual hardware? And if they are firmware controlled, can we reverse engineer this somehow? –  Maria Zverina Jun 26 '12 at 9:38
4  
Check out the schematic - PWR is directly connected to the power, and FDX, LNK & 10M to the ethernet chip. As I said, you might be able to hack the OK LED. –  Alex Chamberlain Jun 26 '12 at 9:43
    
Alex is correct. the BCM chip has no control (excpet for GPIO16) over those LED's; so no software can access them, not even low level kernel code. You would have to hack the LAN chip or create your own short cut circuit to these LED's- BUt that is really not a great idea. Why not just add your own? –  ppumkin Aug 9 '12 at 10:13
    
It seems to me that this other answer shows at least part of this answer (and some comments) to be false. Am I reading things correctly? It may be accurate that only OK (labeled "ACT" on my Rev B. board) can be controlled, but it seems like that one can be. (I haven't tried to actually do it yet, though.) –  lindes Oct 28 '13 at 19:01

There is a simpler way to control the LAN LEDs from userland. Source code is available from

http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=72070

The program needs to be run with sudo.

share|improve this answer

You can control all leds except PWR led(as said in other answers).

But for ethernet leds you will need to patch the driver and recompile the kernel.

Information of how recompile can get here: http://elinux.org/RPi_Kernel_Compilation

Patch and more information here(google translate if need): http://everpi.tsar.in/2013/11/patch-para-controlar-os-leds-ethernet-do-raspberrypi.html

After done, you be able to control over: /sys/class/smsc95xx_leds and eth_fdx, eth_lnk e eth_spd.

Example: echo 0 > /sys/class/smsc95xx_leds/eth_fdx echo 1 > /sys/class/smsc95xx_leds/eth_fdx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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