User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

External led status lights.possible?

Tue Feb 24, 2015 2:09 pm

Busy starting my pi-in-a-snes project, I'm thinking of a couple ideas I want to implement, while emptying the snes housing right now.

First of all, my simple wiring plan for the power, since probable relevant to this question;

Walladapter->into snes->original flip power switch->into pi board.

Now I thought about 2 things I'd like, but I'm a beginner so don't be to hard on me;-P.

*I would like to add an external led to see if power is switched on. Connect to the switch directly,or somehow on the RPi? If so, how?

*And if possible, a led that lightens when the software shutdown has taken place, so power can be safely shut off.
So it lights up after soft shutdown. If it's easier opposite is also possible, so it's on while running RPi OS, and off as soon as shutdown has taken place, so only the power led keeps on burning.

***Ideal situation, but maybe hard to do for me as noob?
>system up and running, red light on.
>system is shutdown, so safe to turn off, green light on.



Can this easily being made, without to much coding etc.?

Or am I totally looking wrong way and you guys can figure a better way to have the system status clear with led's on the outside of the casing?

P.s. I found lots of info surfing, but nothing that's clear to me as noon. Feel a bit dumbish...if that's an existing word :oops: !

Something like this works directly(without the switch)?
Attachments
3v-led-diagram.png
3v-led-diagram.png (6.99 KiB) Viewed 19067 times
rpi-project01-breadboard.png
rpi-project01-breadboard.png (42.04 KiB) Viewed 19089 times
...never too old to to learn!

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Tue Feb 24, 2015 6:26 pm

I found something interesting, maybe what I want is possible. But, I don't really understand what the man who posted this on the internet means exactly, and, scared to burn my RPi or end with wrong parts or not working code.

Can someone here clarify this for a real beginner in this things...me... :oops: ? Thank you very very much!

{Quote from internet search}

...Your solution is simple, use an inverter, and a start up script. When The script runs, have an IO pin go high, which will force the LED off. When the OS is off, and the script driving the IO pin is off, the LED will illuminate.

I still haven't made it back to my Pi location, but it may be possible to do this without an inverter.

You would add you script to run by setting up

sudo vim /etc/rc.local

At the bottom, just above exit 0 we’ll add a call to our script.

python /home/pi/run.py

Your script would look something like this:

import RPi.GPIO as GPIO
pinNum = 8
GPIO.setup(pinNum,GPIO.OUT)
GPIO.output(pinNum,GPIO.HIGH)

Indent that last line.

You can see I am assuming the name run.py and that you have a user directory named /home/pi

Here is a picture of the schematic.

Invert output

Now, if you wanted to get a little extra fancy, you could have a green and red LED, one on either side of the inverter. When the OS is on, one led would be driving high the green LED, and low on the RED LED low. then when the OS were off, the green led would be off, and the red led, on. (I think that would be neat.) or not. do whatever you like....
{End of quote}
Attachments
90QUV.jpg
90QUV.jpg (6.13 KiB) Viewed 19055 times
...never too old to to learn!

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1881
Joined: Thu Jul 11, 2013 2:37 pm

Re: External led status lights.possible?

Tue Feb 24, 2015 7:11 pm

Device tree overlays are your friend.

http://www.raspberrypi.org/documentatio ... ce-tree.md

You can create a simple one for a GPIO-attached LED. You can set the trigger to anything valid that the kernel supports - usually heartbeat or MMC.

You can connect an LED directly to a GPIO pin. An inverter/level translator is not required if you only connect the LED/resistor combo to either GND or 3.3V. Blue/white LEDs may not illuminate particularly well as the GPIO pin can only drive (or sink from) 3.3V.

Use the hardware/circuit connections detailed here:

http://www.raspberrypi.org/learning/robot-antenna/
Rockets are loud.
https://astro-pi.org

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Tue Feb 24, 2015 9:11 pm

Thanks for the links, been reading a lot of info, and will continue tomorrow. Whished this was possible by direct connections without the need of further programming :oops: ...

Anyway I've figured to select exactly what I want, because I wasn't that clear in the beginning. I didn't know what would be possible.

I'll try to figure out to just make this work:
*State 1; RPi running (retropie) -> red led on,green led off. ("warning,don't remove power")
*State 2; RPi is shutdown properly (by retropie exit) -> red led off,green led on.("safe to power off system")

Guess will take a lot of reading before I can, but I'll try my best(, luckily with help from here:-)!)

Edit
Done a little more research...
I guess when it sound to good to be true, it will be,but I'll give it a shot.
Found this https://rpi.tnet.com/project/hardware/project001
And think what I read there is the led's work without further coding or scripting??
And with the little script+pushbutton I'd have a shutdown switch aswell?
If so that'll be great. From what I've read I can use this running just together with my retropie setup?
Again a lot of questions, but that's because I might have found a very simple solution to what I've thought would be very hard to accomplish for a beginner :shock: .

Hope this is true! :D
...never too old to to learn!

User avatar
ragnarjensen
Posts: 331
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: External led status lights.possible?

Wed Feb 25, 2015 7:56 pm

RichardPi wrote:If it's easier opposite is also possible, so it's on while running RPi OS, and off as soon as shutdown has taken place, so only the power led keeps on burning.
Connect a LED to the TxD pin. It will light up when the Pi gets power, flicker a bit while it boots up and then stay on solid.
At shutdown it will go off when it's safe to remove power.
3v-led-diagramTxD.png
LED on the serial console TXD pin
3v-led-diagramTxD.png (5.27 KiB) Viewed 18963 times
The TxD and RxD pins are the serial console, the flickering at boot is actually the boot up text messages and a login prompt.

EDIT: Oops! Just saw that it's just what is shown in the earlier diagram with the push button :oops:
--
Ragnar
Last edited by ragnarjensen on Wed Feb 25, 2015 8:34 pm, edited 1 time in total.

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Wed Feb 25, 2015 8:06 pm

Ragnarjensen, thank you for confirming it works like that, since I still didn't know for sure!

So if I understand correctly, just putting an led that way gives me my so called 'is running' indicator. Just like that, without the need of further coding? -great :D ! Thanks!

About the latest edit of my post, can you confirm that also, or is that not as easy as it looks like?

I seem to think a bit too difficult when it's not always necessary :roll: ..
...never too old to to learn!

User avatar
ragnarjensen
Posts: 331
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: External led status lights.possible?

Wed Feb 25, 2015 8:33 pm

RichardPi wrote:So if I understand correctly, just putting an led that way gives me my so called 'is running' indicator. Just like that, without the need of further coding?
Yes, I have it running like that on several of my Pis.
About the latest edit of my post, can you confirm that also, or is that not as easy as it looks like?
It looks like it actually is that easy :) The LEDs will work without coding, only the shutdown button needs code.
I seem to think a bit too difficult when it's not always necessary :roll: ..
I know how that feels :D
--
Ragnar

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Wed Feb 25, 2015 8:41 pm

ragnarjensen wrote:
RichardPi wrote: I seem to think a bit too difficult when it's not always necessary :roll: ..
I know how that feels :D
--
Ragnar
...But in the meanwhile you figured it out too, so for me you're a great help, I can tell you :!: .

I'll try to get this to work on my RPi B, before I toast my RPi 2 :oops: just in case. Fix myself a breadboard and listed components and give it a shot!

Just curious, would a push in that button, while RPi in sleeping state, wake it too? Or can it only be used to shutdown, not to boot up also, with same switch?

Again, you can't believe how happy I am with this help!
Last edited by RichardPi on Wed Feb 25, 2015 8:59 pm, edited 1 time in total.
...never too old to to learn!

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Wed Feb 25, 2015 8:56 pm

So, I'll have to make this:(attachment)
List:
* led green
* led red
* push switch
* 3 330ohm resistors
* some wires

in the file I create, shutdownswitch.sh, I put this:

Code: Select all

#!/bin/bash
#################################################
# Shutdown switch script
#
# whatches GPIO 4 for button press.
# Loop until the button is pressed
#
#################################################

# Setup the port

/usr/local/bin/gpio -g mode 4 in
/usr/local/bin/gpio -g mode 4 up

# Loop Looking for a button press

while [ 1 ]
do
    value=`/usr/local/bin/gpio -g read 4`
    if [ $value -eq 0 ]
    then
       break
    fi
    sleep 1
done

echo "Shutting down RPi"
/bin/sync;/bin/sync; /sbin/halt

exit
And add this to rd.local:

Code: Select all

...
echo activate button script
/src/shutdownswitch.sh &
exit 0
And all should work. This keeps running in the background(and when retropie is running also?) and won't eat much resources/CPU I guess..

Just to confirm I get the picture :idea: :roll: .
If so, hoping same button can also wake the RPi again.

Edit, sorry for 2x posting.me bad :oops: .
Attachments
rpi-project01-breadboard.png
rpi-project01-breadboard.png (42.04 KiB) Viewed 18898 times
...never too old to to learn!

User avatar
ragnarjensen
Posts: 331
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: External led status lights.possible?

Wed Feb 25, 2015 9:08 pm

RichardPi wrote:Just curious, would a push in that button, while RPi in sleeping state, wake it too? Or can it only be used to shutdown, not to boot up also, with same switch?
That will only shut it down. But the Pi has a "RUN" or "RESET" facility, that just requires a button connected in the right place.
You will probably have to solder it or some header pins into place, though. Once connected, it just takes a quick press on the button to wake the Pi up from its shutdown state.
https://blog.adafruit.com/2014/10/10/ma ... pberry_pi/

--
Ragnar

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Wed Feb 25, 2015 9:14 pm

I'll probably add that one also, the tiny header and wire are the only things I have already :D .

But for the rest...that's it, so the last is posted the whole story together will work? -great! I'm happy!

Would such a breadboard serve as a definite solution or better solder all wires and components to each other?

Appreciate all your quick and clear replies!
You've been a great help figuring this out.thank you.
...never too old to to learn!

User avatar
ragnarjensen
Posts: 331
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: External led status lights.possible?

Wed Feb 25, 2015 9:22 pm

RichardPi wrote:But for the rest...that's it, so the last is posted the whole story together will work? -great! I'm happy!
Yes, I think so.
Would such a breadboard serve as a definite solution or better solder all wires and components to each other?
Breadboards are great for prototyping, but if I want to make a circuit more permanent, I usually solder it on a stripboard.
http://en.wikipedia.org/wiki/Stripboard
--
Ragnar
Last edited by ragnarjensen on Wed Feb 25, 2015 9:32 pm, edited 1 time in total.

User avatar
RichardPi
Posts: 39
Joined: Sat Feb 14, 2015 12:44 pm
Location: The Netherlands

Re: External led status lights.possible?

Wed Feb 25, 2015 9:27 pm

Okay that's what it gonna be then. If I can make it soon enough out of work I'll get to the local electronics shop then, can't wait to see this all happen!

For now I'll stop keep asking you all these questions, hope you didn't mind!

But, by your quick replies I now have all the answers I was looking for about this part of my little snes-RPi to-be project in a couple of hours. :mrgreen:
...never too old to to learn!

lgalati
Posts: 1
Joined: Fri Mar 10, 2017 9:28 pm

Re: External led status lights.possible?

Fri Mar 10, 2017 9:30 pm

For some reason the led only illuminates briefly at start up and then goes out. Have it connected to ground with 330R and pin 8 (txd0) on Pi3. Goal is to show me if the pi is on or off.

User avatar
ragnarjensen
Posts: 331
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: External led status lights.possible?

Sat Mar 11, 2017 1:14 pm

When Raspbian went from Wheezy to Jessie, things changed. The Pi3 introduced further changes.
This might help you getting the serial console going:
http://spellfoundry.com/2016/05/29/conf ... ding-pi-3/
https://www.abelectronics.co.uk/kb/arti ... port-usage

--
Ragnar

Return to “Beginners”