Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

For Industry

Hardware
Software
Documentation
News
Forums
Foundation

Forum FAQ About

Search # " Register ! Login

$ Board index % Programming % General programming discussion

Can we control the on-board leds

( Locked ) * Search this topic… # 63 posts & 1 2 3 '

Re: Can we control the on-board leds


Wed Jun 19, 2013 2:08 pm

If you want to control the on-board 'ACT' LED, then here is a quick way:

Get wiringPi:
gordon@drogon.net

- Code: Select all


Posts: 2023
Joined: Tue Feb 07, 2012 2:14
cd pm
git clone git://git.drogon.net/wiringPi Location: Devon, UK
cd wiringPi Contact: + ,
./build
cd examples
make okLed
sudo ./okLed

And see what happens

-Gordon

--
Gordons projects: https://projects.drogon.net/

Re: Can we control the on-board leds amallaya

Sun Aug 04, 2013 2:09 pm Posts: 1


Joined: Sun Aug 04, 2013 2:05
Thanks for the info @BrianW pm
It is fun

Re: Can we control the on-board leds dingo35

Sat Oct 26, 2013 8:21 am Posts: 13


Joined: Sat Oct 26, 2013 8:09 am
I succesfully managed to clear the bright colored LED's on my Raspberry Pi, except for the red power led.

Clearing or setting the green led is already documented, so I won't cover that here.

Clearing the led's that are flickering at ethernet access can be done by modifying a few lines of kernel code.
In drivers/net/usb/smsc95xx.h you will find the code:

- Code: Select all

#define LED_GPIO_CFG (0x24)


#define LED_GPIO_CFG_SPD_LED (0x01000000)
#define LED_GPIO_CFG_LNK_LED (0x00100000)
#define LED_GPIO_CFG_FDX_LED (0x00010000)

If you modify this to:

- Code: Select all

#define LED_GPIO_CFG (0x24)


#define LED_GPIO_CFG_SPD_LED (0x00000000)
#define LED_GPIO_CFG_LNK_LED (0x00000000)
#define LED_GPIO_CFG_FDX_LED (0x00000000)

and recompile the kernel following these excellent instructions:


http://elinux.org/RPi_Kernel_Compilation, you will find your new kernel-image will not program the gpio pins of the
LAN9512 chip to drive the colored leds.

I have also tried to reprogram the gpio pins from user space (with and without using libusb), but somehow it
doesn't work; I find that, even after recompiling the kernel so it uses smsc95xx as a kernel module, and unloading
this module, the device 0424:ec00 can be opened, even claimed, but writing the LED configuration with the
usb_control_msg returns error -32 EBUSY, signalling that somehow the chip isn't accepting that control message.

If people are interested I can post my experimental code.

Re: Can we control the on-board leds unkzo

Thu Nov 28, 2013 11:34 pm Posts: 49


Joined: Mon May 06, 2013 11:38
Hi guys, now we can control all of ethernet leds from userspace: http://everpi.tsar.in/2013/11/patch-par ... pm
rrypi.html

Re: Can we control the on-board leds dingo35

Fri Nov 29, 2013 7:41 am Posts: 13


Joined: Sat Oct 26, 2013 8:09 am
This is not really taking control from userspace, since the kernel has to be recompiled also (first reason to
recompile is to enable sms95xx support as a module, since per default in Raspbian it is compiled in the kernel
itself; second reason to recompile is for the module to include the patch... ) but it looks like a nice patch!

With a solution from userspace I mean a program that writes the correct values to the low level registers to
control the leds without patching the kernel.

But progress is made, thanks for this!

Re: Can we control the on-board leds cmk20

Sun Jun 29, 2014 11:23 pm Posts: 4


Joined: Sun Nov 10, 2013 2:01
hi i'm new to this subject and I have my raspi booted of a usb drive but I want the act light to flash when it am
accesses the usb disk but it only blinks when it accesses the sd card, can I change this?

Re: Can we control the on-board leds mikerr

Wed Jul 02, 2014 11:33 am Posts: 2828


Joined: Thu Jan 12, 2012 12:46
You would need to add a trigger for usb filesystem access (no idea how though ) pm
Location: UK
I was surprised to find I had lots of triggers already setup instead of just SD (mmc0): Contact: +

- Code: Select all

cat /sys/class/leds/led0/trigger
none [mmc0] timer oneshot heartbeat backlight gpio cpu0 default-on rfkill0 phy0rx phy0tx ph
y0assoc phy0radio

I did find this (for openWRT routers, but still relevant):


http://wiki.openwrt.org/doc/uci/system#leds

Android app - Raspi Card Imager - download and image SD cards - No PC required !

Re: Can we control the on-board leds


Wed Jul 02, 2014 7:38 pm

I wrote a program to do that.


Only tested in Raspbian.

ragnarjensen
- Code: Select all
Posts: 332
/* Joined: Wed May 15, 2013 6:13
* This is free and unencumbered software released into the public domain. pm
* Location: Stockholm, Sweden
* Anyone is free to copy, modify, publish, use, compile, sell, or Contact: +
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of

--
Ragnar

Re: Can we control the on-board leds cmk20

Wed Jul 02, 2014 10:52 pm Posts: 4


Joined: Sun Nov 10, 2013 2:01
am
. ragnarjensen wrote:

I wrote a program to do that.


Only tested in Raspbian.

- Code: Select all


/*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit

--
Ragnar

Cool but how do you set this up?

Re: Can we control the on-board leds


Thu Jul 03, 2014 8:22 am

Save as actledPi.c
Then build it:

ragnarjensen
- Code: Select all
Posts: 332
gcc -Wall -O3 -o actledPi actledPi.c Joined: Wed May 15, 2013 6:13
pm
Location: Stockholm, Sweden
Contact: +
Put the binary somewhere in the PATH, I put it in /usr/local/bin:

- Code: Select all

sudo mv actledPi /usr/local/bin

and run it:

- Code: Select all

sudo actledPi -d

Put the line

- Code: Select all

/usr/local/bin/actledPi -d

in /etc/rc.local, just before the last line, that says "exit 0", to have it start automatically at boot.
--
Ragnar

Re: Can we control the on-board leds cmk20

Thu Jul 03, 2014 12:08 pm Posts: 4


Joined: Sun Nov 10, 2013 2:01
Thanks all try it! am

Re: Can we control the on-board leds cmk20

Thu Jul 03, 2014 9:27 pm Posts: 4


Joined: Sun Nov 10, 2013 2:01
yay it works my pi had problems compiling it because the text editor i was using put hidden Unicode symbols in it am
i used a simpler one and it compiled just fine...?

Re: Can we control the on-board leds


Sat Jan 03, 2015 6:29 am

With the Raspberry Pi model B+, a program I had that used GPIO16 to drive the STATUS OK LED on the
Raspberry Pi model B no longer works. Given that GPIO16 is now exposed on pin36 of the 40-pin header, I'm
not too surprised. However, this does beg the question: besides writing to /sys/class/leds/led0/brightness, how tonyhansen
can I drive the STATUS OK LED on the B+ using the GPIO interface?
Posts: 17
Joined: Sat Jan 03, 2015 6:20 am

Re: Can we control the on-board leds


Sat Jan 03, 2015 5:11 pm

True! On a A+ and B+ the status ACT LED is now controlled by GPIO47, and its actually controlling a FET, so
on/off is now inverted, with high being ON!
mahjongg
Forum Moderator
In fact you can now also sense the status of the PWR LED, that is the brownout detector driving it, by using
GPIO35 to read it out, but if you change GPIO35 to an output you can actually control the PWR LED now too,
same way as the ACT LED. Posts: 14208
Joined: Sun Mar 11, 2012 12:19
am
Location: South Holland, The
Netherlands

Re: Can we control the on-board leds


Sat Jan 03, 2015 5:14 pm

. tonyhansen wrote:
DougieLawson
With the Raspberry Pi model B+, a program I had that used GPIO16 to drive the STATUS OK LED on the
Raspberry Pi model B no longer works. Given that GPIO16 is now exposed on pin36 of the 40-pin Posts: 41883
header, I'm not too surprised. However, this does beg the question: besides writing to Joined: Sun Jun 16, 2013 11:19
pm
/sys/class/leds/led0/brightness, how can I drive the STATUS OK LED on the B+ using the GPIO interface?
Location: A small cave in deepest
darkest Basingstoke, UK
Change your code to use GPIO47. Contact: + ,

Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.


Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Re: Can we control the on-board leds


Sat Jan 03, 2015 11:25 pm

mahjongg, thank you for the complete response, along with the additional information on controlling the other
status LED.
tonyhansen

Posts: 17
Joined: Sat Jan 03, 2015 6:20 am

Re: Can we control the on-board leds


Sat Jan 03, 2015 11:47 pm

I'm very happy to help.

mahjongg
Forum Moderator

Posts: 14208
Joined: Sun Mar 11, 2012 12:19
am
Location: South Holland, The
Netherlands

Re: Can we control the on-board leds


Mon May 11, 2015 7:19 pm

. Geekmason wrote:
Hitechcomputergeek
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 ... Posts: 28
83#p366483 Joined: Wed Nov 27, 2013 4:29
am

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?

Not sure about this, but could you set the trigger for the other GPIO pin to mmc0 using /sys/idk/trigger?

Re: Can we control the on-board leds


Thu May 28, 2015 10:49 pm

This is excellent information. I managed to add 2 additional LED instantiations in the board support kernel file to
control the additional LEDs that we're using for our system. Much less hassle than instantiating the GPIO in our
control program.
ConnersJM

- Code: Select all


Posts: 2
Joined: Thu May 28, 2015 10:41
static struct gpio_led bcm2708_leds[] = { pm
[0] = { Location: San Jose, CA
.gpio = 16,
.name = "led0",
.default_trigger = "mmc0",
.active_low = 1,
},
[1] = {
.gpio = 2,
.name = "led1",
.default_trigger = "cpu0",
.active_low = 1,
},

For the trial-run I set them to cpu0 to show activity, but I'll change them to trigger on gpio. Then they're controlled
by changing the brightness between 0 and 1<=x<=255. I don't see any difference in brightness when I tested, but
I suppose they could be PWMed to control brightness. Not sure if this was the intent. Does anyone know?

-Jeremy

Re: Can we control the on-board leds rern

Tue Sep 06, 2016 8:12 am Posts: 2


Joined: Tue Sep 06, 2016 6:14
@ragnarjensen am
After hours of seacrhing for GPIO LED for USB drive, your code is the only one I've found that do exactly I want.
Please advice how to make it works on ArchLinux.

actledPi and hddledPi on another post, Custom Case indicator LEDs, run successfully on *Raspbian(OSMC) but
not on **ArchLinux(RuneAudio).
To run actledPi on GPIO connected LED:
On Pi3, dtoverlay=pi3-act-led,gpio=n must be appended to config.txt .

* compiling failed on error: usb.h, $ sudo apt-get install libusb-dev fixed it.
** ArchLinux compiling complained about missing braces at ... if (current == on) ...

(Edited: Sep 07, 2016)


Result after tried both actledPi and hddledPi.

Re: Can we control the on-board leds


Sat Sep 10, 2016 8:19 pm

. simplesi wrote: DavidS

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


Joined: Thu Dec 15, 2011 6:39
am
Simon
Location: USA
Contact: +
You could try something like:

- Code: Select all

.LedInit:
LDR R1,GPIOBase
LDR R0,#1 SHL #21
STR R0,[R1,#16]
MOV R15,R14

.LedOn
LDR R1,GPIOBase
LDR R0,#1 SHL #15 ;Turning on the GPIO controling the LED.
STR R0,[R1,#32] ;Write the GPIO Set Register.
MOV R15,R14 ;Return to caller.
Assuming you are running on the ARM, and on a RPi B+/2B/3B. A bit different if you are running on the
VideoCore IV, though same basic concept.

RPi = The best ARM based RISC OS computer around


More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Re: Can we control the on-board leds


Sun Sep 11, 2016 10:07 am

. DavidS wrote:
DougieLawson

. simplesi wrote: Posts: 41883


Joined: Sun Jun 16, 2013 11:19
Are any of the on-board LEDS controllable by us users? pm
Location: A small cave in deepest
Simon darkest Basingstoke, UK
Contact: + ,

You could try something like:


...
Assuming you are running on the ARM, and on a RPi B+/2B/3B. A bit different if you are running on the
VideoCore IV, though same basic concept.

You're replying to a post from Thu 26 Jul 2012 @ 21:19 by someone who hasn't visited the forum since Thu 05
Feb 2015 @ 12:46.

Good solid necro there.

Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.


Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Re: Can we control the on-board leds


Sun Sep 11, 2016 1:41 pm

. DougieLawson wrote: DavidS

Posts: 4340
. DavidS wrote: Joined: Thu Dec 15, 2011 6:39
am
Location: USA
. simplesi wrote: Contact: +

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

Simon

You could try something like:


...
Assuming you are running on the ARM, and on a RPi B+/2B/3B. A bit different if you are running on
the VideoCore IV, though same basic concept.

You're replying to a post from Thu 26 Jul 2012 @ 21:19 by someone who hasn't visited the forum since
Thu 05 Feb 2015 @ 12:46.

Good solid necro there.

Ooops

RPi = The best ARM based RISC OS computer around


More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

Re: Can we control the on-board leds Heater

Sun Sep 11, 2016 2:06 pm Posts: 18717


Joined: Tue Jul 17, 2012 3:02 pm
I don't see what is wrong with posting solutions to problems that were asked a long time ago.

In this case I can well imagine someone new here having the same question. Having googled it, as people always
suggest they should, they may end up here. At which point a recent post with a new or better solution, or a post
pointing out that perhaps the old solution don't work anymore due to whatever hardware software changes, is not
a bad thing.

In short questions don't become invalid just because they are old or the original poster has disappeared.

Memory in C++ is a leaky abstraction .

Re: Can we control the on-board leds


Sun Sep 11, 2016 5:49 pm

. Heater wrote:
DougieLawson
In short questions don't become invalid just because they are old or the original poster has disappeared.
Posts: 41883
Yes they do, because the RPi3B hardware is just a little bit different to the RPi1B and code that works on a 3B Joined: Sun Jun 16, 2013 11:19
pm
won't run on a 1B.
Location: A small cave in deepest
darkest Basingstoke, UK
Contact: + ,
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.


Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Display posts from previous: All posts * Sort by Post time * Ascending * Go

( Locked ) * 63 posts & 1 2 3 '

/ Return to “General programming discussion” Jump to *

Board index Delete cookies All times are UTC

Follow us

Sign up to newsletter

Twitter

Facebook

YouTube

Instagram

LinkedIn

About Raspberry Pi

News

Contact us

Trademark

About us

Accessibility

Cookies

Licensing

Terms and conditions of sale

Privacy

Security

For Industry

Raspberry Pi For Industry

Powered by Raspberry Pi

Design Partners

Hardware

Computers and microcontrollers

Cameras and displays

Add-on boards

Power supplies and cables

Cases

Peripherals

Software

Raspberry Pi OS

Raspberry Pi Imager

Raspberry Pi Desktop

Documentation

All categories

Product information portal

Datasheets

Forums

All forums

Raspberry Pi Store

Cambridge Store

Raspberry Pi Press

About Raspberry Pi Press

The MagPi

HackSpace

Wireframe

Custom PC

You might also like