I wrote a python program that boots with pi, do it's job, and shutdown pi when finished working. It works fine, and when I'm connecting an lcd to the pi, I can know whether the pi finished shutting down or not, but the problem is that the screen shouldn't be connected. So how could the user know when the pi completed shutting down to safely unplug it from power?

  • Is this a secret program? How do you shut down? I could guess and make a couple of suggestions - BUT
    – Milliways
    Jun 22 '16 at 11:44
  • os.system("sudo shutdown -h now")
    – Dani
    Jun 22 '16 at 12:10
  • How about attaching another LED and resistor parallel with the original power LED?
    – v7d8dpo4
    Jun 22 '16 at 14:45
  • If visual feedback is out of the question , you will be forced to add an USP. Users will forget to shutdown properly , power failures will happen.
    – flakeshake
    Jun 24 '16 at 8:32

If you run poweroff the green activity LED will flash 10 times at 1 sec intervals, and then SHOULD extinguish - although the latter depends on model and OS version.

You can use Device Tree gpio-poweroff to set the state of a pin on shutdown.


Let's examine this problem a bit:

  • The user cannot tell using a screen, because no screen is attached.

  • The user cannot tell by the green act flashing briefly and then going off, because the pi "would be inside a box so the green led wouldn't be visible".

In other words, the pi might as well be in another room or on another planet, from the user's perspective. It is completely concealed in an impenetrable container with no interface.

Is there any kind of computer system or electronic device which you would expect to be able to demonstrate anything about state while sealed in an impenetrable box, in another room, or on another planet? Logically enough of course not.

This is a design flaw -- your design flaw -- if your intention is to communicate state to the user. The device itself comes with LEDs for this purpose, but you have intentionally concealed them.

So you need to implement something of your own. One thing I think is possible is to use a form of light conductive plastic fiber from the LEDs to the outside of the case; there are I think cases exploiting this for the pi already on the market. The material is probably pretty cheap but I could not find much online; they used to (and may still) sell decorative things with long strands of this in novelty/gift stores (if you search online "fiber optic lamp" you'll find some pictures).

That would be ideal IMO. Another option is to mount your own power LED on the outside of the box and turn it on using a GPIO, preferably one that by default uses a pull-down as an input. I am pretty sure when the system halts the GPIOs are reset to those defaults, in which case you won't have to do anything else; when the system stops it will go off (even without the pull-down, it should dim). If not, you will have to arrange something late in the shutdown cycle (this is controlled by the init system, on current versions of Raspbian, systemd) to turn it off (or try Milliway's suggestion about device tree configuration).

Another point to consider is it probably takes no more than 2-5 seconds to shutdown (the green blinking is subsequent to that and irrelevant; you can pull the plug once it starts, but beware the irregular green flashing before that is not irrelevant), so if the user knows this it is not hard to just count to 3 or 5 or whatever.

  • 4
    Actually counting to three could be an issue: ...then shalt thou count to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once the number three, being the third number, be reached... (Monty Python)
    – Ghanima
    Jun 22 '16 at 16:49
  • 1
    @Ghanima I was going to include the terms "reasonably competent user" and "at a reasonably appropriate speed" but I find myself using the world "reasonable" so much I am worry sometimes I am not...and/or "reasonable" is too subjective a standard to be reasonably meaningful.
    – goldilocks
    Jun 22 '16 at 17:03
  • @goldilocks Basically I agree. It reminds me of a saying we used often in the '70s when developing software "You can't make a foolproof program - fools are so ingenious" PS no offence intended to OP. While writing this I was also reminded of writing a BASIC in the '70s. I corresponded with a partner who was writing the manual, and it seemed impossible to avoid the word "basically" in every 2nd sentence.
    – Milliways
    Jun 23 '16 at 1:16

Depends on your model. The Pi2's green LED will flash 10 times(rather slowly) and stay unlit after that. The red power LED will still be on after poweroff.

  • The Pi would be inside a box so the green led wouldn't be visible, what I need is connect external led, and let this led stay flashing on until the pi finished shut down, and that's what I don't know how to achieve yet. I'm using pi 2 B+.
    – Dani
    Jun 22 '16 at 12:12
  • 2
    Please note that all relevant info should be edited into the question itself not hidden in the comments to some answers.
    – Ghanima
    Jun 22 '16 at 13:37
  • Have you observed the serial console's output? I'm currently working with an A20 arm whose serial output is well suited to determine power state. e.g: the final message received is "power-off" I believe. On the other hand, you could specify a simple offset to the shutdown command, at which point you can be sure the pi is powered off.
    – mystery
    Jun 22 '16 at 13:37

If you set a GPIO as OUTPUT-HIGH at the start-up time, it'll probably go LOW after shutting down.

  • 3
    You obviously haven't tried this.
    – Milliways
    Mar 8 '19 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.