Are any of the on-board LEDS controllable by us users?
Simon
Can we control the on-board leds
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Can we control the on-board leds
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.
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
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
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.
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)
Re: Can we control the on-board leds
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

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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
- Grumpy Mike
- Posts: 1005
- Joined: Sat Sep 10, 2011 7:49 pm
- Location: English Lake District
Re: Can we control the on-board leds
[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.
Yes you are right.
Re: Can we control the on-board leds
So we might be able to use it to signal the IP address of our RPi? 
Simon

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Can we control the on-board leds
simplesi, I had the exact same idea, did a search and here's the thread!!!!
Time to write some script!
Time to write some script!
My Raspberry Pi blog with all my latest projects and links to articles
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.
Re: Can we control the on-board leds
Look forward to the results 
Si

Si
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Can we control the on-board leds
Exactly such a script has already been written.
100 % sure.
ghans
EDIT : Found it:
http://www.raspberrypi.org/phpBB3/viewt ... =26&t=7335
100 % sure.
ghans
EDIT : Found it:
http://www.raspberrypi.org/phpBB3/viewt ... =26&t=7335
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org
Re: Can we control the on-board leds
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
I think shell script, Python and PHP are enough to be going on with, so I'm going to carry on anyway

My Raspberry Pi blog with all my latest projects and links to articles
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.
http://raspberrypipod.blogspot.com. +++ Current project: PiPodTricorder - lots of sensors, lots of mini-displays, breadboarding, bit of programming.
Re: Can we control the on-board leds
Perl has it's place... been using it since '89.
Interesting conversation, script, ideas...
Interesting conversation, script, ideas...
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com
My RPI Info Pages including Current Setup - http://rpi.tnet.com
Re: Can we control the on-board leds
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:
This should be easier to grok than by reading binary or morse encoding off the LED.
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
Re: Can we control the on-board leds
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 thiscanyon wrote: The FDX, LNK and 10M LEDs are hardwired to the USB/Ethernet chip.

Re: Can we control the on-board leds
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?I had the same problem and solved it through espeak and the audio output by adding the following code to /etc/rc.local:
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
Re: Can we control the on-board leds
You have to install espeak first bysimplesi wrote: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?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
apt-get install espeak
Re: Can we control the on-board leds
/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.simplesi wrote:sudo chmod +x /etc/rc.local to get it to work
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com
My RPI Info Pages including Current Setup - http://rpi.tnet.com
Re: Can we control the on-board leds
Wow 
My Pi speaks to me
Time to add
"Hello Dave" methinks
Simon

My Pi speaks to me

Time to add
"Hello Dave" methinks

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter
http://cymplecy.wordpress.com/ @cymplecy on twitter
-
- Posts: 2
- Joined: Thu Dec 06, 2012 4:05 pm
Re: Can we control the on-board leds
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
Do you have any idea where I can find this "different datasheet"?
Re: Can we control the on-board leds
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.
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
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?
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?
-
- Posts: 16
- Joined: Tue Jun 04, 2013 11:14 pm
Re: Can we control the on-board leds
how to use and control GPIO?
are we use c-code or what?
and can you name the programming code?
sorry i'm newbie.
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
You can use many programming languages to control the GPIO, C (and its variants), shell scripting, PHP, Perl, Python, ARM assembler and more.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.
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

-
- Posts: 16
- Joined: Tue Jun 04, 2013 11:14 pm
Re: Can we control the on-board leds
thank you rpdom.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

can we control two motor using PWM each other with GPIO?

- [email protected]
- Posts: 2024
- Joined: Tue Feb 07, 2012 2:14 pm
- Location: Devon, UK
Re: Can we control the on-board leds
you might want to have a look at this to start with: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.
https://projects.drogon.net/raspberry-p ... -crossing/
WiringPi is a C based GPIO linbrary - details at http://wiringpi.com/
-Gordon
--
Gordons projects: https://projects.drogon.net/
Gordons projects: https://projects.drogon.net/