How to shutdown your Raspberry Pi at the push of a button

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024

Комментарии • 50

  • @edmondsjc
    @edmondsjc 5 лет назад

    Exactly what I was looking for: a simple shutdown button. Thanks!

  • @FuzzyScaredyCat
    @FuzzyScaredyCat 9 лет назад +10

    Nice tutorial. If you use pins 5 and 6 instead then once the pi has shut down, if you push your button again, it will start up again. No need to remove and re-apply power.

    • @LucSmall
      @LucSmall  9 лет назад

      Andy Powell That's something I will definitely have to try. How does it work? Does one of these pins function as a kind of reset pin when the pi has been shutdown?

    • @FuzzyScaredyCat
      @FuzzyScaredyCat 9 лет назад

      Luc Small It's a gpio interrupt. Works well, I only have one button to startup and shutdown my Pi. ( dl.dropboxusercontent.com/u/188253/pifi-button.png )

    • @CubiShax
      @CubiShax 9 лет назад

      +Andy Powell Mind showing your schematics and the script for that one? Would be great for the mini retro system I am building into an old SNES case.

    • @FuzzyScaredyCat
      @FuzzyScaredyCat 8 лет назад

      For shutdown, yes. No code is needed for just starting. I just wrote a small c progam for the shutdown part

    • @yovanyluis
      @yovanyluis 8 лет назад

      +Andy Powell I was thinking in implementing your solution for my project, but pin 5 is the SCL signal for the i2c port which I use a lot, so for my case it wouldn't work, right?

  • @troykleeman4258
    @troykleeman4258 8 лет назад +3

    Is there any way to make this work with a non-momentary on/off switch?

  • @jprcell
    @jprcell 9 лет назад +1

    Hi great video!. Question .. So all you need is just a push button? Nothing else? What is that little board on the right in the beginning of the video? Im just asking because other videos have small circuit boards and this seems too easy. Any information would be greatly appreciated

    • @LucSmall
      @LucSmall  9 лет назад

      Juan Rodriguez Yep - just a push button. The board on the right is a wifi dongle that's been stripped of its casing and soldered directly to the raspberry pi. Check out my earlier video on the raspberry pi camera rig for more details about the wifi dongle.
      I assume the solutions that have boards are doing some hardware switch debouncing and a hardware pull up resistor. They also probably have the capacity to reset the raspberry pi once it's shut down. By contrast, I use the raspberry pi's built in pull up resistor and once it looks like the button is pressed, I sample 20 times over 2 seconds to verify it really has been intentionally pressed to avoid a spurious current spike or accidental short press from shutting down the raspberry pi.

  • @TheOriginalVersatile
    @TheOriginalVersatile 6 лет назад +1

    Where to buy push button and gpio header pins?

  • @gumbycampbell1652
    @gumbycampbell1652 4 года назад

    Is there any reason why this wouldn't work for a Pi 4B?

  • @tropicaljantie
    @tropicaljantie 7 лет назад

    good stuff. I am going to apply this on my rpi b v1. fingers crossed. I am new to python.

  • @JustinMasuga
    @JustinMasuga 5 лет назад

    I don't know how to set up the directory for the files. Do I simply create a folder and drop that file in there? Is there a more novice walk-thru?

  • @tropicaljantie
    @tropicaljantie 7 лет назад

    I don't understand the button 7 link you talk about. Is that a physical connection via soldering?

  • @coryengel
    @coryengel 7 лет назад

    Is there a variation on this that would also work with the Pi Zero without a secondary power board?

  • @akutimestwo
    @akutimestwo 8 лет назад +1

    does this not need a resistor to work? im afraid of messing up the pi with too big of a current

    • @CoolAsFreya
      @CoolAsFreya 8 лет назад +1

      I would recommend the one with the 2 resistor voltage divider just for good measure, but directly putting 3.3 to grip shouldn't pose problem, neither should grounding the gpio pin.

  • @CommanderCrash
    @CommanderCrash 6 лет назад

    Very useful Thanks.

  • @robertobernardes4035
    @robertobernardes4035 8 лет назад

    Hello good afternoon.
    can you help me? Studs for raspberry pi 2 are the same?
    What would be the script and how where I should put in recalbox could help me?
    I'm trying to put a button to turn off within the SNES but without success.
    Thnks! Beto.

  • @davidportelli5955
    @davidportelli5955 5 лет назад

    hi great video but how to i do it just copy the Raspberry-Pi-Shutdown-Button/wait-for-power-off-button.sh from your link?

  • @VeganBoyDDB
    @VeganBoyDDB 9 лет назад +1

    why sudo halt not sudo shutdown?

    • @CoolAsFreya
      @CoolAsFreya 8 лет назад

      Depends what you want it for, you could also use sudo reboot if that's what you need, halt and shutdown are almost identical but I believe halt can be interrupted and started back again also I think any displays stay connected

    • @seamusdemora5598
      @seamusdemora5598 3 года назад

      @@CoolAsFreya So all the button does is issue a `halt`? You leave power on the board? So you will need to pull the USB power jack & re-insert it to re-start the PI? Is that it?

  • @artauer4641
    @artauer4641 8 лет назад

    Can you provide a link to that button that you used by chance? I need to know how deep it is as I am trying to put together a custom retropie build and want to use the existing push button built into the casing of the old console. Thanks!

    • @jlwinkler
      @jlwinkler 8 лет назад

      I would also love to know which button you are using and where I can find it on the web ;-) thanks a lot in advance!

    • @Uneke
      @Uneke 7 лет назад +1

      It's a standard momentary switch. Can pick them up at any electronic/ computer store for 2-4$

    • @AtlantaTerry
      @AtlantaTerry 6 лет назад

      www.BangGood.com

  • @OyunKandr
    @OyunKandr 7 лет назад

    code link?? plsssss

  • @Joel-vn7qd
    @Joel-vn7qd 7 лет назад

    i followed these steps and when i go to boot it runs all the normal stuff and then says now halting and shuts down. i assume i have a typo in the file but now i cant boot up to edit the file. can anyone help!!

    • @LucSmall
      @LucSmall  7 лет назад +1

      Not 100% sure if this will work because of permissions, etc. But if you have another Linux computer, you might be able to mount the main partition on the SD card, edit the mistake, unmount the partition, and then try to boot the raspberry pi again.

  • @NonsenseSystems
    @NonsenseSystems 7 лет назад

    Can u make it s

  • @CoolAsFreya
    @CoolAsFreya 8 лет назад

    Can someone help I made an error in the script and now the Pi shuts down every time it boots

    • @CoolAsFreya
      @CoolAsFreya 8 лет назад

      Hey for anyone who might have made a similar mistake I fixed it by using an sd card reader. I would recommend for anyone to just edit the bash (.sh) file itself but since I was stupid I put it in a mounted directory that was linked somehow with the boot partition not the root partition so I wasn't able to access the file from anything but the pi. Luckily I looked up where the crontab are located and found the one then modified the code, to remove the invading script from starting at boot. Another issue I had was that i could read the Linux partition on the card with a card reader and a windows computer with a simple free program but I couldn't write to it so I actually used the raspberry pi with a blank raspbian os on it, the card reader (it is USB 3.0 but it worked) and a USB drive with the fixed crontab, I then removed the old one from the sd (wouldn't reccomend this but it was that or nothing) with rm and copied the new one over with cp (make sure you use sudo for both commands)

    • @quadcopteruploads6685
      @quadcopteruploads6685 8 лет назад

      +CoolAsFinnBro i am having the same problems, but cant follow what you said

    • @CoolAsFreya
      @CoolAsFreya 8 лет назад +2

      +QuadCopter Uploads basically I found the crontab file on the sd card and edited it in the end, and now I have a 30 second emergency delay on the shutdown button script before it enables so if another error occurs I can disable it without the pi shutting down as soon a it boots

    • @quadcopteruploads6685
      @quadcopteruploads6685 8 лет назад

      CoolAsFinnBro sadly im attempting a fresh format as I couldnt keep the pi on to ssh with it to change anything and having a windows pc i couldnt edit anything. Thanks anyways

  • @GeorgeTJ
    @GeorgeTJ 6 лет назад

    Will this code work if I exchange sudo halt with sudo shutdown -h now ?

    • @LucSmall
      @LucSmall  6 лет назад +1

      Your change should work just fine. To be completely safe, I would recommend taking an image of your SD card before making the change; then make the change and test ... that way you can restore from the image if for some reason the change causes issues. But I'd say that if the script is working with sudo halt already then changing to shutdown -h now is a pretty safe move.

    • @GeorgeTJ
      @GeorgeTJ 6 лет назад

      Excellent! Thanks so much Luc for the comprehensive guide. I will try your script asap with that slight modification!

    • @andreamitchell4758
      @andreamitchell4758 6 лет назад

      did it work?
      and why not just do both
      first sudo halt and then
      sudo shutdown-h now
      also will this work on the zero 1.3 and zero w running lite builds like jessie and stretch lite?
      and do those lite builds have anything already built in that does the same thing as this?

  • @VovanP-ge9on
    @VovanP-ge9on 8 лет назад

    where u buy button

  • @bitmaster2000
    @bitmaster2000 9 лет назад

    WHAT?