simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Can we control the on-board leds

Thu Jul 26, 2012 8:19 pm

Are any of the on-board LEDS controllable by us users?

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

canyon
Posts: 38
Joined: Sun Jan 29, 2012 9:47 am
Location: London UK

Re: Can we control the on-board leds

Fri Jul 27, 2012 9:04 am

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.

BrianW
Posts: 83
Joined: Sun Jul 29, 2012 9:03 pm

Re: Can we control the on-board leds

Sun Jul 29, 2012 10:08 pm

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.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Re: Can we control the on-board leds

Tue Aug 14, 2012 11:09 am

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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
Grumpy Mike
Posts: 1005
Joined: Sat Sep 10, 2011 7:49 pm
Location: English Lake District

Re: Can we control the on-board leds

Wed Aug 15, 2012 6:11 pm

[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.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Re: Can we control the on-board leds

Wed Aug 15, 2012 6:19 pm

So we might be able to use it to signal the IP address of our RPi? :)

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

recantha
Posts: 209
Joined: Mon Jun 25, 2012 10:41 am

Re: Can we control the on-board leds

Fri Aug 24, 2012 10:51 am

simplesi, I had the exact same idea, did a search and here's the thread!!!!
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.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Re: Can we control the on-board leds

Fri Aug 24, 2012 11:11 am

Look forward to the results :)

Si
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

ghans
Posts: 7893
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Can we control the on-board leds

Fri Aug 24, 2012 1:15 pm

Exactly such a script has already been written.
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

recantha
Posts: 209
Joined: Mon Jun 25, 2012 10:41 am

Re: Can we control the on-board leds

Fri Aug 24, 2012 3:56 pm

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 :-)
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.

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ

Re: Can we control the on-board leds

Sat Aug 25, 2012 7:18 am

Perl has it's place... been using it since '89.

Interesting conversation, script, ideas...
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

dov
Posts: 14
Joined: Sat Oct 20, 2012 9:13 pm

Re: Can we control the on-board leds

Sat Oct 20, 2012 9:19 pm

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.

plugwash
Forum Moderator
Forum Moderator
Posts: 3826
Joined: Wed Dec 28, 2011 11:45 pm

Re: Can we control the on-board leds

Wed Oct 24, 2012 11:02 am

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 :(

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Re: Can we control the on-board leds

Wed Oct 24, 2012 11:14 am

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
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

dov
Posts: 14
Joined: Sat Oct 20, 2012 9:13 pm

Re: Can we control the on-board leds

Wed Oct 24, 2012 11:44 am

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
.

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ

Re: Can we control the on-board leds

Wed Oct 24, 2012 3:23 pm

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.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK

Re: Can we control the on-board leds

Wed Oct 24, 2012 5:07 pm

Wow :)
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

RussNelson
Posts: 2
Joined: Thu Dec 06, 2012 4:05 pm

Re: Can we control the on-board leds

Thu Dec 06, 2012 4:10 pm

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.

plugwash
Forum Moderator
Forum Moderator
Posts: 3826
Joined: Wed Dec 28, 2011 11:45 pm

Re: Can we control the on-board leds

Fri Dec 07, 2012 1:25 pm

Do you have any idea where I can find this "different datasheet"?

doublehp
Posts: 77
Joined: Wed May 02, 2012 1:11 am

Re: Can we control the on-board leds

Sun Jan 06, 2013 10:25 pm

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.

Geekmason
Posts: 5
Joined: Sat Jun 08, 2013 1:51 pm

Re: Can we control the on-board leds

Sun Jun 09, 2013 8:46 am

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?

yogisyaputra
Posts: 16
Joined: Tue Jun 04, 2013 11:14 pm

Re: Can we control the on-board leds

Mon Jun 17, 2013 8:54 am

how to use and control GPIO?
are we use c-code or what?
and can you name the programming code?
sorry i'm newbie. :)

User avatar
rpdom
Posts: 22355
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Can we control the on-board leds

Mon Jun 17, 2013 9:26 am

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 :)

yogisyaputra
Posts: 16
Joined: Tue Jun 04, 2013 11:14 pm

Re: Can we control the on-board leds

Wed Jun 19, 2013 3:47 am

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? :)

User avatar
[email protected]
Posts: 2024
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK

Re: Can we control the on-board leds

Wed Jun 19, 2013 2:00 pm

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
--
Gordons projects: https://projects.drogon.net/

Return to “General programming discussion”