The OK LED can be controlled from user space software. Details here: Re: Can we control the on-board leds
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
Setting the brightness to 0 automatically 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.
Sample code
#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep
# Needs to be BCM. GPIO.BOARD lets you address GPIO ports by periperal
# connector pin number, and the LED GPIO isn't on the connector
GPIO.setmode(GPIO.BCM)
# set up GPIO output channel
GPIO.setup(16, GPIO.OUT)
# On
GPIO.output(16, GPIO.LOW)
# Wait a bit
sleep(10)
# Off
GPIO.output(16, GPIO.HIGH)