Page 1 of 3

Can we control the on-board leds

Posted: Thu Jul 26, 2012 8:19 pm
by simplesi
Are any of the on-board LEDS controllable by us users?

Simon

Re: Can we control the on-board leds

Posted: Fri Jul 27, 2012 9:04 am
by canyon
The short answer is no...
The red PWR LED is hardwired to the on-board 3.3V.
The FDX, LNK and 10M LEDs are hardwired to the USB/Ethernet chip.
The green OK LED is hardwired to GPIO 16 and is programmed in the 'firmware' to indicate SD card activity: It may be possible to control this one, but only from low level code, which is well beyond me. Only someone like dom will know the answer to that.

Re: Can we control the on-board leds

Posted: Sun Jul 29, 2012 10:08 pm
by BrianW
Hi,

The green OK LED can be controlled from software. It's available as /sys/class/leds/led0/

The kernel LED driver, which controls led0, 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]


Here, the mmc0 trigger is selected. You can deactivate this 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 (specified in the 'max_brightness' file). However, as there is no hardware support for variable brightness, 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

As an aside, 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.

Sample code, using http://pypi.python.org/pypi/RPi.GPIO

Code: Select all

#!/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)
It's important to note that RPi.GPIO will set the GPIO port to be an input when it's finished (it sets to an input any port which the script set to an output, and you have to set it to an output before you can do anything with it, even if it already was). As GPIO16 stops being an output, control via the kernel interface will no longer work.

Re: Can we control the on-board leds

Posted: Tue Aug 14, 2012 11:09 am
by simplesi
Brilliant stuff :)

Lost track that I'd asked this question so sorry for delay in getting back :(

Am I right in thinking that no real harm will occur to small fruit objects by forgetting to ask for/take or not hand back control of the LED from python using the GPIO lib?

Simon

Re: Can we control the on-board leds

Posted: Wed Aug 15, 2012 6:11 pm
by Grumpy Mike
[quote="simplesi"Am I right in thinking that no real harm will occur to small fruit objects by forgetting to ask for/take or not hand back control of the LED from python using the GPIO lib?[/quote]
Yes you are right.

Re: Can we control the on-board leds

Posted: Wed Aug 15, 2012 6:19 pm
by simplesi
So we might be able to use it to signal the IP address of our RPi? :)

Simon

Re: Can we control the on-board leds

Posted: Fri Aug 24, 2012 10:51 am
by recantha
simplesi, I had the exact same idea, did a search and here's the thread!!!!
Time to write some script!

Re: Can we control the on-board leds

Posted: Fri Aug 24, 2012 11:11 am
by simplesi
Look forward to the results :)

Si

Re: Can we control the on-board leds

Posted: Fri Aug 24, 2012 1:15 pm
by ghans
Exactly such a script has already been written.
100 % sure.
ghans

EDIT : Found it:
http://www.raspberrypi.org/phpBB3/viewt ... =26&t=7335

Re: Can we control the on-board leds

Posted: Fri Aug 24, 2012 3:56 pm
by recantha
Yeah... a Perl script. To quote "Bones McCoy"... "Oh... Joy."
I think shell script, Python and PHP are enough to be going on with, so I'm going to carry on anyway :-)

Re: Can we control the on-board leds

Posted: Sat Aug 25, 2012 7:18 am
by Dweeber
Perl has it's place... been using it since '89.

Interesting conversation, script, ideas...

Re: Can we control the on-board leds

Posted: Sat Oct 20, 2012 9:19 pm
by dov
This reply has nothing to do with the online LED, but I saw that the question of getting the current IP came up. I had the same problem and solved it through espeak and the audio output by adding the following code to /etc/rc.local:

Code: Select all

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
  espeak "Welcome to Rasberry pi. My I.P. is $_IP. I repeat: $_IP"
else
  espeak "Welcome to Rasberry pi. No I.P. found."
fi
This should be easier to grok than by reading binary or morse encoding off the LED.

Re: Can we control the on-board leds

Posted: Wed Oct 24, 2012 11:02 am
by plugwash
canyon wrote: The FDX, LNK and 10M LEDs are hardwired to the USB/Ethernet chip.
According to the LAN9512 datasheet it is possible to reprogram those pins as GPIO. Unfortunately I can't seem to find any information in the datasheet as to how to do this :(

Re: Can we control the on-board leds

Posted: Wed Oct 24, 2012 11:14 am
by simplesi
I had the same problem and solved it through espeak and the audio output by adding the following code to /etc/rc.local:
Do we just have to put this code into /etc/rc.local and do an sudo chmod +x /etc/rc.local to get it to work or is there any apt-getting to be done first?

Simon

Re: Can we control the on-board leds

Posted: Wed Oct 24, 2012 11:44 am
by dov
simplesi wrote:
I had the same problem and solved it through espeak and the audio output by adding the following code to /etc/rc.local:
Do we just have to put this code into /etc/rc.local and do an sudo chmod +x /etc/rc.local to get it to work or is there any apt-getting to be done first?
You have to install espeak first by

Code: Select all

apt-get install espeak
.

Re: Can we control the on-board leds

Posted: Wed Oct 24, 2012 3:23 pm
by Dweeber
simplesi wrote:sudo chmod +x /etc/rc.local to get it to work
/etc/rc.local should already have proper permissions. Make sure you use full paths to whatever you want run from there since it doesn't have your user environment.

Re: Can we control the on-board leds

Posted: Wed Oct 24, 2012 5:07 pm
by simplesi
Wow :)
My Pi speaks to me :)

Time to add
"Hello Dave" methinks :)

Simon

Re: Can we control the on-board leds

Posted: Thu Dec 06, 2012 4:10 pm
by RussNelson
plugwash, you're looking in the wrong datasheet. That datasheet is just for the hardware. You need a different datasheet to find out how to program the USB Hub / Ethernet controller. It will explain how to change the pin assignment from Ethernet signals to GPIO control.

Re: Can we control the on-board leds

Posted: Fri Dec 07, 2012 1:25 pm
by plugwash
Do you have any idea where I can find this "different datasheet"?

Re: Can we control the on-board leds

Posted: Sun Jan 06, 2013 10:25 pm
by doublehp
I am asking the question about the LAN9512 in there:
http://www.raspberrypi.org/phpBB3/viewt ... 44&t=28624

Reusing the existing 3 LEDs is possible by software, but needs to rebuild the kernel. I think (hope) that the other 5 pins can be used by compiling new C code, but without rebuilding the kernel. Probably a kernel module; hopefully a root-land app.

Re: Can we control the on-board leds

Posted: Sun Jun 09, 2013 8:46 am
by Geekmason
I'm not sure, but I it looks like this thread (or rather its intrepid participants) may be able to solve a riddle I have concerning the onboard LEDs. See my questions here: http://www.raspberrypi.org/phpBB3/viewt ... 83#p366483

I was hoping to "recreate" an ACT(ivity) LED off one of the GPIO pins so I can mount it to the exterior of a custom case. Doable?

Re: Can we control the on-board leds

Posted: Mon Jun 17, 2013 8:54 am
by yogisyaputra
how to use and control GPIO?
are we use c-code or what?
and can you name the programming code?
sorry i'm newbie. :)

Re: Can we control the on-board leds

Posted: Mon Jun 17, 2013 9:26 am
by rpdom
yogisyaputra wrote:how to use and control GPIO?
are we use c-code or what?
and can you name the programming code?
sorry i'm newbie. :)
You can use many programming languages to control the GPIO, C (and its variants), shell scripting, PHP, Perl, Python, ARM assembler and more.

Have a read of this page http://elinux.org/Rpi_Low-level_periphe ... .28GPIO.29
It describes the GPIO connections and gives a few examples of ways to use them. Then look at the online MagPi magazine for more programs :)

Re: Can we control the on-board leds

Posted: Wed Jun 19, 2013 3:47 am
by yogisyaputra
rpdom wrote:
You can use many programming languages to control the GPIO, C (and its variants), shell scripting, PHP, Perl, Python, ARM assembler and more.

Have a read of this page http://elinux.org/Rpi_Low-level_periphe ... .28GPIO.29
It describes the GPIO connections and gives a few examples of ways to use them. Then look at the online MagPi magazine for more programs :)
thank you rpdom. :)
can we control two motor using PWM each other with GPIO? :)

Re: Can we control the on-board leds

Posted: Wed Jun 19, 2013 2:00 pm
by gordon@drogon.net
yogisyaputra wrote:how to use and control GPIO?
are we use c-code or what?
and can you name the programming code?
sorry i'm newbie. :)
you might want to have a look at this to start with:

https://projects.drogon.net/raspberry-p ... -crossing/

WiringPi is a C based GPIO linbrary - details at http://wiringpi.com/

-Gordon