#273

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • If you pull the plug on a Raspberry Pi during operation, it is well possible that it will never boot up again, because its SD card is corrupted. This is what we will change today. And I will show you a few other useful tricks you might not find right away.
    Or if you use Node-red, InfluxDB and Grafana your RPI can block.
    And I show how you can set up a headless RPI
    Links:
    Commands: www.sensorsiot.org/raspberry-p...
    Empty shells: s.click.aliexpress.com/e/cbDQzmKG or bit.ly/2J7GPDm
    Button switch: s.click.aliexpress.com/e/JFnviks
    Supporting Material and Blog Page: www.sensorsiot.org
    Github: www.github.com/sensorsiot
    My Patreon Page: / andreasspiess
    My Bitcoin address: 19FSmqbBzb5zsYB1d8Bq4KbxVmezToDNTV
    If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission (of your purchases the next 24 hours) to buy new stuff for the channel
    For Banggood bit.ly/2jAQEf4
    For AliExpress: bit.ly/2B0yTLL
    For ebay.com: ebay.to/2DuYXBp
    profile.php?...
    / spiessa
    www.instructables.com/member/...
    Please do not try to Email me or invite me on LinkedIn. These communication channels are reserved for my primary job
    #Raspberry Pi #how-to #electronics
  • Věda a technologie

Komentáře • 355

  • @ChrisMuncy
    @ChrisMuncy Před 5 lety +7

    Going to build some shutdown/startup buttons today. Thanks for sharing Andreas.

  • @Iceteavanill
    @Iceteavanill Před 5 lety

    The headless setup is really useful already. Just tried it and it worked very nice. THX for sharing!

  • @877cms
    @877cms Před 3 lety

    Finally got around to trying this, and it works! Thank you.
    I might investigate how to make it reboot instead of shutdown.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety +1

      For rebooting you just have to switch power off and on...

  • @PhG1961
    @PhG1961 Před 5 lety +2

    Interesting tricks and tips. Great stuff !

  • @gerritkuilder2309
    @gerritkuilder2309 Před 3 lety

    Thank you for the best and simplest solution for a shutdown button

  • @CyclingSteve
    @CyclingSteve Před 5 lety +3

    Finally a proper headless Pi tutorial!

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +2

      :-)

    • @unusualpost6953
      @unusualpost6953 Před 4 lety

      I can't seem to find any of these tutorials that will work on a Pi 4. I fear I'm making things worse by following all of these various tutorials for a stupid shutdown switch and nothing works.

  • @ATLaboratory
    @ATLaboratory Před 5 lety +1

    Great!!! I'm just playing with a Raspberryand a similar situation, so you saved my system from broken!! ;)

  • @tv175s3
    @tv175s3 Před 10 měsíci

    That works fine on my PI 3B+. I saw other solutions with large script to be executed, but that is so simple and functional.

  • @nicklaspersson4687
    @nicklaspersson4687 Před 5 lety +1

    Thanks for another great video and great tips. I would like to add a recommendation to type "man top" to get the 'man'ual for the 'top' command it is quite extensive.
    I now have a Rasp3B+ and a Wemos with some 18DS20's and a DHT22(humid +temp sensor). The video #255 was a great inspiration. The DHT22 has caused me some pain as it kept stopped working after 5-15 hours. The reason is probably because i used cheap unshielded wire of 5 meters(not recommended). But I resolved these annoying stopps by connecting the DHT22's 5v supply to a high GPIO on the Wemos and added code to go shortly go false (delay(100) ) on the GPIO if I receive a 'not a number' (if isnan(value)) this resets the DHT22 and it starts working again. The DHT22 is low cost and therefore quite very popular I have my doubts about it surviving Swedish winter it remains to be seen.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      Thanks for the tip with "man".
      Resetting was already a good trick in the old Windows times ;-)

  • @dorianeric
    @dorianeric Před 3 lety

    Thank you so much, the reset button trick works so well and it was so easy.

  • @BruceJSkelly
    @BruceJSkelly Před 5 lety

    Thanks for the hints. The swap space probably explains why I had so many problems with my original Raspberry Pi B with 256MB of memory. The first time I did an apt-get upgrade on wheezy, it kept locking up. I just kept rebooting it until I got through all the upgrades.

  • @lubeda04
    @lubeda04 Před 5 lety

    I am using PIs for a long time, didnt know that shutdown is so easy. I will solder one button like shown! Thanx

  • @WacKEDmaN
    @WacKEDmaN Před 5 lety +1

    great tips Andreas...there is some there ive never heard of that ill definitely
    be using!

  • @toastrecon
    @toastrecon Před 4 lety +1

    Great ideas and useful info! Thank you!

  • @dd0356
    @dd0356 Před 5 lety +28

    in my case, swap on the sdcard made the situation worse, by constant rewrite cheap sdcard "wearoff". better to make the sdcard readonly, use usb ssd (older ones which are on sale with smaller capacity) for the data write and swap. by the way, GPIO start method was particularly interesting. so maybe we could connect an esp8266 (with sonoff clone firmware) and use MQTT/Thingspeak or some other clound enabled method! and the cheapest use case is when the 5V lipo ups is atleast 40% charged, turn the pi on and and when it is below 15% charged, turn it off!

    • @twmbarlwmstar
      @twmbarlwmstar Před 5 lety

      I have SATA SSD. I could have NVMe SSD but that would be wasteful as the Pi woudn't benefit because ultimately whatever you do you meet USB 2 as far as I can see/ work out/ understand- and that appears for everything- everything to one USB 2. There are benefits to a SATA SSD, it completely sturates USB2 obviously, you'd really want USB3 which I have in a partial sense but I haven't created anny cache and for many files whatever cache I did create would not be enough. No the benefit is resilence compared to cards or sticks. Big storage at very cheap prices (120Gb is under£20, 250 is £30, 500 is £50) and it can be my boot drive. I haven't done it, or even know if it can be done but if the sMC could be used as a sort of scratch card that might be cool- what ever I think it should be able to be used as a card reader, which would be handy for copying ile from the Pi to give to someone else.

    • @dd0356
      @dd0356 Před 5 lety +1

      @@twmbarlwmstar I think it is old news, for example watch prof Christopher's video from 2 years ago: czcams.com/video/ubnwvxF3Klc/video.html I was talking about old ssd sold on ebay or possibly if you decide to upgrade your laptop ssd from 128GB to 1Tb as they are now more affordable than they were 2 years ago. for ssd vs sd card, have a look at linus tech tips video, czcams.com/video/3frnBoqqI_Q/video.html ssd have a computer inside, sd cards are somewhat dumber. hence the difference in price. there are so many discussions on ssd vs sd card. For example, have a look at the review of the newly launched cheaper (but slower) qvo ssd from Samsung by anandtech: www.anandtech.com/show/13633/the-samsung-860-qvo-ssd-review and one of the popular nvme 970 evo vs 970 evo "plus" www.anandtech.com/show/13761/the-samsung-970-evo-plus-ssd-review

    • @nashaut7635
      @nashaut7635 Před 5 lety

      There are excellent tutorials on how to make the Raspberry Pi boot off a read-only card (e.g. hallard.me/raspberry-pi-read-only/ ). I tried that method in a heavily polluted industrial environment (e.g. tig welders, heavy motors aso) and I never had an SD card corruption, even though I had written a script to store data on a periodical basis. The trick is to enable write access only when actually writing to the card, to minimize corruption risks. Also, a GPIO can be used with an LED to indicate when the Pi writes to the SD card - although this is already done through the small, green board LED. All that matters is to have the *operating system* read-only, which Linux can do without an issue.

  • @fegoins
    @fegoins Před 4 lety

    Perfect video and writeup on SENSORSIOT , a huge help to me.

  • @limtbk
    @limtbk Před 5 lety +4

    My 4 raspbery's work 2+ years as security cameras, and they have no problem you described - because they have read only filesystem. All files that need to be temporary stored was written to usb-stick drive (with fat32 to reduce rewrite cycles), and they synchronized with cloud storage. So I recommend to try RO filesystem.

    • @bwack
      @bwack Před 5 lety

      This is what most wifi router vendors do too. Read only Squashfs and a small writeable storage area for settings.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Interesting idea. but is the problem not only shifted to the USB stick?

    • @limtbk
      @limtbk Před 5 lety

      @@AndreasSpiess only for temporary data. USB storage is not used for booting, so I can handle that errors.

  • @NoxmilesDe
    @NoxmilesDe Před 5 lety +1

    Wow - that are really new Tricks! Thanks a lot and Grüezi!

  • @darrinpearce9780
    @darrinpearce9780 Před 5 lety

    Hey Andreas, thanks for the tips. I have a fleet of RPI's here and this will save me heaps of time.

    • @Conservator.
      @Conservator. Před 5 lety

      Just curious: what is you ‘fleet’ used for?

    • @darrinpearce9780
      @darrinpearce9780 Před 5 lety

      @@Conservator. Hi Andrea's. Streaming server for LiveATC another for LoRaWAN on TTN (thanks for those video's), web server and node for portable FT8.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      You are welcome!

    • @Conservator.
      @Conservator. Před 5 lety

      Darrin Pearce
      Impressiv! 👍

  • @jjordan73115
    @jjordan73115 Před 3 lety

    Power button works great on pi zero! Thanks for the easy steps!

  • @MartinBgelund
    @MartinBgelund Před 5 lety +24

    I typically use I2C in my Raspberry Pi projects, so GPIO3 is far from ideal for this purpose for me, since it's the RPi 's I2C Clock pin.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +10

      Good to know. I did not know that and I do not know why they used this pin then. At least for safe shutdown, I showed a second possibility. And maybe with an open collector transistor in parallel, you could even restart it without harming i2c

    • @CesarDanielLopez
      @CesarDanielLopez Před 5 lety

      me too

    • @svenscheil902
      @svenscheil902 Před 3 měsíci

      ​@@AndreasSpiess Could you please show a small schematic for the pin 3 workaround with a transitor?

  • @GlennHamblin
    @GlennHamblin Před 5 lety

    Great tips. Thank you!

  • @HariWiguna
    @HariWiguna Před 5 lety

    Andreas, could a resistor in series with the switch work as a safety precaution so we won't completely short 3V and 5V? It would make the switch a bit taller though. Also, I wonder how low the resistance needs to be to set the pin LOW and yet "open" enough when shorting 3V3 and 5V. 1K?

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      Yes, but maybe mechanically less elegant. For me, it was not necessary as I usually know what I do ;-) (I grew up when mistakes destroyed things and we had to think twice).

  • @felixh.7501
    @felixh.7501 Před 5 lety +2

    Very good video. Do you think about a video on enabling grafana and influxdb on pizero? Everyone says it doesn't work long term, and hassio blocks it.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Watch my earlier videos. There, both run on a pi zero. But it is not an ideal solution. If you can afford, go for a bigger one.

  • @shuyangan3892
    @shuyangan3892 Před 5 lety

    was in Switzerland last month for first time, and wow, this is the land that Swiss accent guy living and making experiment !

  • @avejst
    @avejst Před 5 lety

    Impressive tutorial
    Thanks for sharing :-)

  • @jeremeyweeks5069
    @jeremeyweeks5069 Před 5 lety

    Great video. Thanks!

  • @sharedinventions
    @sharedinventions Před 5 lety +2

    Please note, that with the GPIO start/stop method, after recovering from a power-loss the pi will start up regardless it was ON or OFF before the power loss. (At least in my experience.)

  • @send2gl
    @send2gl Před 5 lety +1

    Useful, thank you.

  • @belenhedderich3330
    @belenhedderich3330 Před 5 lety

    Thank you Andreass I tried to apply it to the Octoprint without luck I wonder what is wrong

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Maybe an old Firmware/operating system (This feature seems to be quite new)

  • @joachimbaumann731
    @joachimbaumann731 Před 5 lety

    Dear Andreas, thanks for another nice video. Regarding the swap space configuration:
    First, you do not need to uncomment the swap file name, the name shown is the default and will be used if the line is still commented. This is cosmetic though.
    But you should also uncomment the last line of the config file to limit the maximum growth of the swap file using CONF_MAXSWAP. Otherwise you have no guarantees that the file does not grow too large.
    I personally also start with a CONF_SWAP_FACTOR of 1 instead of 2 but that depends on the Pi used and the amount of space you want to initially provide.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Thank you for your hints.
      Since I always have plenty of SD space I did not care about the (too big) swap size. Do I have to fear anything?

    • @joachimbaumann731
      @joachimbaumann731 Před 5 lety

      Hm, depending on the number of processes and their respective memory needs your swap space can grow - in theory - without bounds. In all practicality there‘s most probably nothing to fear, but for „production“ systems it is a conservative approach to nail down everything that might move.
      Ok, let me reformulate: For systems you use for experimenting, including e.g. tensorflow and other memory-costly apps, your approach might be the best. But if you have something that runs a well-defined number of applications in your home automation system installed somewhere you can‘t reach easily, you should use MAX_SWAP after you have watched the memory consumption of all your apps for some days. Calculate the maximum memory needed and use a factor of 2 or 3. That would be my approach, but ymmv.

  • @mordinkainen1844
    @mordinkainen1844 Před 5 lety +1

    thank you for this.

  • @chuxxsss
    @chuxxsss Před 5 lety

    Hi, no gold the week for me. But gold for you mate. Have a good week.

  • @typxxilps
    @typxxilps Před 5 lety +2

    Great, but
    the pi 3 has a bit more than the 1 MB you mentioned though great way to remember FREUD by a Freudscher Versprecher 😉
    switch button has turned dead ... sold out by vor blocked by the amount of traffic your video had "caused"

  • @KunalGautam
    @KunalGautam Před 5 lety +1

    Memory Split option (Under raspi-config advaced option) set to 16MB might also help

  • @rondamon4408
    @rondamon4408 Před 4 lety

    Great video!! Have you ever done a video about pine 64 and pine phone?

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety +1

      I am no SBC guy and because I am a Linux noob I stick with the Raspberry because of its community

  • @meinsda5983
    @meinsda5983 Před 5 lety

    Always nice your Videos ;) One simple shutdown is to connect a power bank between the usb port and look if the original power goes down you will shutdown the Raspberry. if the power Comes back you can restart the Raspberry.I hope over the summer i have time to build a rack System with poe suppert with the same switch you have ;)

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      The shutdown has to start before the power goes down ;-)

    • @michim5661
      @michim5661 Před 5 lety

      Most power banks are not useable as USV/UPS, because they do not allow simultaneous charging and discharging.

    • @meinsda5983
      @meinsda5983 Před 5 lety

      yes i know! But i use one how can charge and running my pi at the same time. Some pi is running with the poe heat and powered over a switch with a ups behind.

  • @LAGUY88
    @LAGUY88 Před 5 lety +1

    WiFi issue with Raspberry PI 3B+ can see the AP.LibreELEC with Kodi 18.1 and Xenon Already subscribed

  • @ThaRealChuckD
    @ThaRealChuckD Před 3 lety

    You the man!!! 👍

  • @MGKday
    @MGKday Před 5 lety

    thanks for this video ! is trick1 considered as a graceful shutdown ? i.e. will it save the status or something ? if no, is it at least considered as totally harmless (if done connected the right way) ?

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      It is the same as if you type „shutdown „

  • @FhargaZ
    @FhargaZ Před 5 lety

    Whitout the scripts to turn it on was to use a outside switch. Now that i put a hifinerry i can't use those pins like i used to 😒
    After trying so many things, bevause i have Recalbox i just use a wifi switch to cut power after the shutdown and to turn it on again.

  • @veryboringname.
    @veryboringname. Před 5 lety

    If your case allows it, you can use a 4-pin shell and leave the first column of pins hanging off the end of the Pi header. Fill the unused column that's hanging off the edge with hot glue or something similar. That way you can't connect it the wrong way round.

  • @svenboske844
    @svenboske844 Před 4 lety

    The gpio-shutdown won't work for me on Rasbian Buster any more; at first i blamed the Pi4 but after an Update of Moode on a Pi Zero theres the same problem (strangely enough starting via GPIO still works). Couldn't find anything on this Topic till now.
    Nonetheless a big Thanks to Andres for this Channel

  • @danielkohwalter5481
    @danielkohwalter5481 Před 5 lety

    To be more safe, you can connect in series with the button a resistor. Probably an 1k resistor will work. Usually the internal pullup resistors are much higher and it still should provide the low voltage necessary to the IO pin. This way if you connect 5V and 3V3 and push the button the current should be around 1.7mA. It will not cause harm to the 5V part of the board, but I don't know the effect on the 3V3 regulator circuit. Probably (and I mean probably - I'm not sure) it will be ok.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I think it will be sure. But mechanically a little more challenging...

    • @danielkohwalter5481
      @danielkohwalter5481 Před 5 lety

      @@AndreasSpiess You can use a SMD resistor even below the button. Or a regular one if you partially breaks the top plastic part of the connector to fit it in.

  • @x.X.x_.
    @x.X.x_. Před 3 lety +1

    Hi all,good afternoon.
    Can you help me, please?
    I have a Raspberry Pi Zero W, I bought it yesterday and used the shutdown command to turn off and it won't turn on anymore.
    I watched your video, but if doesn't turn on, how else am I going to set it up for Putty? (sudo nano /boot/config.txt)
    I know that power is passing through the card, because the USB is leaving electrical current.
    If you can help I would be very grateful,
    Thank so much.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      Raspberries do not switch on again after shutdown. You have to remove power first and then they boot

  • @prebenborg
    @prebenborg Před 5 lety

    I have just experienced a major sd-card crash due to power failure twice in a day. A question: Is it hard to make a small UPS power supply for a RPI? It should just power the RPI with 5 v. which is rather minor and if a power occurs the UPS should trigger the shutdown command

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      You can buy such devices if you want. I also made videos concerning this topic.

  • @dj1encore
    @dj1encore Před 2 lety

    Do you know how to add a shutdown command to influxdb during reboot or shutdown.

    • @AndreasSpiess
      @AndreasSpiess  Před 2 lety

      I never did something like that. I trust that it is shutdown automatically (gets a signal from the OS). But I do not know. So far I never had problems.

  • @AndrewBorrill1
    @AndrewBorrill1 Před 5 lety +1

    Hi Andreas, check out the Linear Technology LTC2954. This is a push button controller with uP interrupt. It can be used to start/shutdown an RPI as well as enable/disable the power supply to the RPi. Very useful for a headless RPi and ideally suited to an automotive application.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I looked at it and I am not sure. You do not need debouncing of the GPIO3 pin, and the power has to be cut off by the RPI after safe shutdown, not by an external IC, I think.

    • @AndrewBorrill1
      @AndrewBorrill1 Před 5 lety

      @@AndreasSpiess The bush button control is debounced, so no false triggering. The LTC2954 has an enable pin that is used for controlling the RPI's psu either on/off. Starting the RPi up, the press of the pushbutton re-enables the RPI's psu and this starts up the RPi. On shutdown, arrange for the KILL pin to be set low and the LTC2954 will disable the RPI's psu. Setting this pin has to be done as late as possible. I managed to do this by creating a delay from when the RPi o/s signals a terminate and then set the KILL pin low after about 10 seconds. This could be adjusted to a longer/shorter delay if required. The crucial component is having a PSU that has an enable/disable facility, I used an LM2596, which has enable/disable and provides 5v at up to 3 amps. I think the LTC2954 is a very usable device as it has a very efficient 6uA supply current so is ideal for battery use. The ability to switch off the RPI's psu is great as both the RPI and its psu are both effectively switched off. I believe the LM2596 will only consume around 80uA when in standby.

  • @ajaybnl
    @ajaybnl Před 5 lety

    Very Good Video. Please make a video on new esp32-s2.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      For the moment it is not available. And I have to wait till it is supported by the Arduino IDE

  • @DavoShed
    @DavoShed Před 2 lety

    Seem like making the pin header 3 pins wide creates as many problems as it solves?
    You also didn’t mention why you used those two pins. That is it will also wake the pi when pressed again while in a halt state.
    I only recently stumbled across this information and it works way back to the original pi version 1.

    • @AndreasSpiess
      @AndreasSpiess  Před 2 lety

      I thought I mentioned the reason (connector is flush to the end). And I also mentioned the rebooting.

  • @phizicks
    @phizicks Před 5 lety

    I completely turn off swap on mine (no Pi zero though) and remove syslog, I can unplug every time without corruption as it barely writes now. syslog is sent to another server so no issues with logs.
    your website says "Save Shutdown" did you mean "Safe Shutdown"

  • @Devin82m
    @Devin82m Před 4 lety

    So why would sudo shutdown not work via SSH as opposed to using a keyboard? I've been doing this for years, am I missing something?

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety

      I to not think you missed anything. But if you switch the power off, you have no time for that.

  • @AndyPue
    @AndyPue Před 5 lety +2

    That GPIO to shutdown thing is interesting, did not know about it until now. Thank you!
    However, I see the shutdown process initiated by the GPIO pin, but how is it supposed to restart the PI with the same button? (I think you mentioned it, but I cannot see where the functionality for this is implemented, I did not try it either yet, so maybe I am missing something obvious.)

    • @silasparker
      @silasparker Před 5 lety +3

      You can get help on the overlay using the "dtoverlay -h gpio-shutdown" command. This also mentions the power on function: "This overlay only handles shutdown. After shutdown, the system can be powered up again by driving GPIO3 low. The default configuration uses GPIO3 with a pullup, so if you connect a button between GPIO3 and GND (pin 5 and 6 on the 40-pin header), you get a shutdown and power-up button."

    • @AndyPue
      @AndyPue Před 5 lety

      @@silasparker So that restart works only after shutdown, I read that part in the documentation and assumed both functions are not enabled at the same time. (Force restart while shutting down would increase the danger of corruption, but makes sense its only active once the system is idle after shutdown.)
      Thank you!

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +2

      They were both enabled in my case. I push the button once and it shuts down. After shutdown, I push it again and it restarts.

    • @MartinBgelund
      @MartinBgelund Před 5 lety

      I searched and found some discussion on Stackoverflow on this: raspberrypi.stackexchange.com/questions/77905/raspberry-pi-3-model-b-dtoverlay-gpio-shutdown
      As mentioned by others, the behaviour is dependent on GPIOs setup wrt being default high or low.

  • @thibaultbacle3609
    @thibaultbacle3609 Před 4 lety

    Can one use the button trick to wake noobs (multi boots) and shutdown in every installed OS ?
    I plan on running manjaro and retropie using noobs

  • @Alan_UK
    @Alan_UK Před 4 lety

    Hi Andreas. I enjoy your videos: well put together, clear & informative. The power off button looks an essential addition but how to remotely restart the Pi?
    Have you thought about making a video on NUT "Network UPS Tools" for the Rasp Pi? I'm thinking about this but I was wondering what happens after the Pi shutsdown should power be restored to the UPS before it has shut down. Presumably the Pi will not restart as it's power has not been lost. Or to put is another way, how to power up a Pi remotely - a sort of WOL?

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety

      If the Pi is without power and gets power it automatically starts. If you want to start a powered Pi you can do that as shown in hte video. And if you want to do that remotely you have to find a way to toggle this GPIO from remote. This can be done in many ways, for example with an ESP8266 or a 433 MHz button.

    • @Alan_UK
      @Alan_UK Před 4 lety

      @@AndreasSpiess Thanks Andreas. One then shifts the problem to the ESP8266. How does the ESP8266 know that the UPS has lost power & the Pi has powered down (easy bit: the Pi NUT send a MQTT message to the ESP8266 before shutting down).
      Next the ESP8266 needs to know the UPS has not shut down as power has been restored so the ESP8266 can toggle the GPIO.
      Maybe the USP can tell the ESP8266 that power has been restored and then the ESP8266 can toggle the GPIO - but how can the UPS communicate this to the ESP8266?
      However, if the UPS has shut down (prolonged outage) then hasn't the ESP8266 also shut down?
      Maybe the ESP8266 is battery powered. Or maybe the ESP8266 has a start up routine when power is restored that checks if the PI had previously shut down (record written somewhere).
      Maybe the ESP8266 interrogates the Pi and if the Pi responds it knows the Pi has auto restarted after a prolonged power outage so there is no need to toggle the GPIO.
      I'm thinking aloud here but I think the key thing is that the logic has to be bullet proof for all scenarios.

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety +1

      An ESP has input pins to measure voltage or digital signals.

  • @kwazar6725
    @kwazar6725 Před 5 lety

    Good starter hints. Listen to Andreas folks.

  • @MeisterQ
    @MeisterQ Před 5 lety

    Hello Andreas,
    is there a way with this commands to reduce the lag of motion on the zero? i want a security cam with a zero W and its stream is very very laggy.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I have to admit I am a Linux noob. Maybe somebody else knows it?

    • @laverdanick
      @laverdanick Před 5 lety

      I use Motioneye OS and for my purposes it runs very well on a Zero W. The author has specific images for the different versions of Pi.

  • @geirthorud6581
    @geirthorud6581 Před 5 lety

    I have considered using influxdb, but I do not know how robust it is. Does anyone know if Influxdb survives a sudden power interupt, assuming the SD-card or ssd survives. I do not mind loosing a couple of the last measurements, but older ones (ie most of the data) should survive. Can anything be done to increase the probability of survival?

  • @lmarloe
    @lmarloe Před 5 lety

    Just dtoverlay=gpio-shutdown will be enough, in old firmware there was dtoverlay=gpio-poweroff,active_low=y for low power consumption in stand by including turning off the LED, it seems this doesn't work anymore and RPi3B+ consume ~100mA after shutdown

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Thank you for the tip. I did not measure the current when the RPI was off

  • @rsmaster5637
    @rsmaster5637 Před 2 lety

    why is it the case that with gpio 21 to gnd the raspberry will not boot anymore ?

    • @AndreasSpiess
      @AndreasSpiess  Před 2 lety

      I assume because the engineers at the Pi foundation or at Broadcom decided to be like that

  • @benhetland576
    @benhetland576 Před 5 lety +1

    For the button hack I suggest you could make that a 4-pin long header instead of the 3p. Still make the connection at the 3rd pair, but now if you turn this around you don't hit the 3.3+5 shorts! well, provided you don't misalign the holes of course, but I understand you have already learnt to never do such a mistake again... ,;-)
    You could also ad one or two extra holes at the end, which you key shut so they can only be pushed down beyond the end of the Pi's connector, and then you cannot insert it the wrong way at all.

  • @MrFurriephillips
    @MrFurriephillips Před 5 lety +2

    I was expecting some sort of momentary, rudimentary UPS, using a chunky capacitor and something to sense loss of the incoming power supply, that initiates an automatic shutdown, by bridging pins 5+6 :(

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +3

      Maybe you watch my other videos about this topic. There you even find supercaps, if I remember right ;-)

  • @wd269
    @wd269 Před 3 lety

    Can someone advise if the switch used for this project is momentary or held closed for power on?

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      I think it should be open, but I never tested what happens if closed during power-up.

    • @wd269
      @wd269 Před 3 lety

      @@AndreasSpiess Thanks - I did also find a few other sources that suggested a normally-open, momentary switch--apparently a normally-close switch can be used as well but the code would be a bit different.

  • @twmbarlwmstar
    @twmbarlwmstar Před 5 lety

    Handy vidjeo as I have to finish a Pi today, not a steak and kidney pi, with some chips and maybe some peas and a bit of extra gravy. Oh no, a Raspeberry Pi, fully loaded with SATA SSD, plenty of cooling and overclocked, plenty of power (up to 5, Amps), lots of USB even somewhat useless USB3, and a hardware safe shutdown but I still need the software safe shutdown. And I have to fit the UPS which has a few other features I can't currently recall, but it smooths the supply and based on testing should give me about 4 hours on battery. Again I will need to find some code because really I want the option to safely shut down like my grown-ups UPS from HP that looks after x86 stuff.

  • @aamiddel8646
    @aamiddel8646 Před 5 lety

    Nice tip, But did i miss something. In the introduction you said the system will restart (with the switch). But lateron you mention that after you use the switch it will not reboot..

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +2

      It will only reboot if you use GPIO3. All other pins only shutdown

  • @rupjyotihazowary3384
    @rupjyotihazowary3384 Před 3 lety

    can I use same power button install in pi4/pi3

  • @fuzzy1dk
    @fuzzy1dk Před 5 lety

    add the gpio-poweroff driver and an LED so you can see when the shut down is finished and it is safe to remove power

  • @patrichausammann
    @patrichausammann Před 5 lety +9

    5:28 I guess Mr. Spiess meant one gigabyte of RAM, not a megabyte.

  • @chucktaylor5878
    @chucktaylor5878 Před 3 lety

    This worked for me on a PI 4B for octoprint. But I could not read what to change the code to at 3:18 from the video. Here is what to change it to...
    dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      As usual, there is a link in the video description to the commands. It is the same as above.

  • @olafbode7490
    @olafbode7490 Před 5 lety +1

    sorry, don't get it: why is PIN21 okay for shutdown but doesn't reboot the Pi?

  • @Giggity4242
    @Giggity4242 Před 3 lety

    What was wrong with using pin 21? I used it on a rpi 3b+ running stretch.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      I was no more able to boot the Pi with pressing the button. With GPIO3 you should be able to boot the Pi without re-powering it.

    • @Giggity4242
      @Giggity4242 Před 3 lety

      @@AndreasSpiess Ah I see, with 3 pushing the button can turn it back on? That’s extremely handy

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      If I remember right: Only the Pi4. But I am not sure.

  • @mattivirta
    @mattivirta Před 4 lety

    tell me, why my HDD go broken if i make sudo apt get update and upgradem then raspi not start any more only black screen, my setup have x830 subtronic board has HDD no use SD card, config text have usb boot mode 1. start nice whit HDD but if upgrade and update then no start only black screen, why no work ? what need do, i no can update my raspi trech now. and and need me add button to gpio 21 and this video coe and then have safe shutdown? now i has shutdown only software shutdown and when display shut take power off.

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety

      Unfortunately I cannot perform remote debugging. This behavior of your RPI should not happen.

  • @mcflapper7591
    @mcflapper7591 Před 5 lety +1

    one meg of ram???

  • @prakashdutt1520
    @prakashdutt1520 Před 5 měsíci +1

    suppose I am using Rusberry Pi 5 as a Ubuntu PC.. What will happen if suddenly it loose power from adapter...
    And what will happen if this happen many time....
    As in our area there is limited time of power supply available...

    • @AndreasSpiess
      @AndreasSpiess  Před 5 měsíci +1

      It can corrupt your SD card.

    • @prakashdutt1520
      @prakashdutt1520 Před 5 měsíci

      @@AndreasSpiess what about my Rusberry pi will it damage?

    • @AndreasSpiess
      @AndreasSpiess  Před 5 měsíci

      Usually not. If your power supply does not produce spikes when power comes back.

  • @hoggif
    @hoggif Před 5 lety

    I didn't know about gpio shutdown. Now I think if 3.3V could be buffered with a super capasitor and when 5V disapears, RPI could shut down automatically. Something like that would give a clean shutdown when power fails. Now solve automatic restart after power recovery somehow and it would make a great setup.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I once made a video about this (without the gpio solution, but with super caps)

    • @hoggif
      @hoggif Před 5 lety

      @@AndreasSpiess I know. I think super caps at the input could simplify the system more especially with gpio shutdown. No need for lithium chargers or battery monitoring circuits. Perhaps a diode and a resistor would be enough to sense power loss.

  • @linuxgamer2147
    @linuxgamer2147 Před 5 lety

    danke für das Video

  • @africantwin173
    @africantwin173 Před 3 lety

    So can i use gpio21 and gnd . Does this Execute the command: sudo shutdown -h now.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      As said: You can use it to shutdown, But it does not boot anymore.

    • @africantwin173
      @africantwin173 Před 3 lety

      @@AndreasSpiess Roger on that. Thnx

  • @pinox61
    @pinox61 Před 4 lety

    Where can I find "Video description" ? 73 de ZP4KFX

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety

      If you search for the links: They are in the comment below each video

  • @tozinfo6448
    @tozinfo6448 Před 5 lety

    reboot intead of shutdown possible? Is there a command to reboot? not only shutdown?

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I do not know.

    • @tozinfo6448
      @tozinfo6448 Před 5 lety

      as far as i googled, the "dtoverlay=gpio-shutdown" uses gpio-keys driver to trigger a "power-key event", explanation here: www.stderr.nl/Blog/Hardware/RaspberryPi/PowerButton.html i think you can drive it further an map all gpios (github.com/notro/fbtft-spindle/wiki/GPIO-keyboard) to normal keyboard keys and trigger events with triggerhappy (raspberrypi.stackexchange.com/questions/15337/gpio-button-to-control-backlight-on-pitft) . at the end, there must be a way to do any script, i.e. reboot instead shutdown ... @andreas: thanks for inspiration :-)

  • @bringamosa8480
    @bringamosa8480 Před 5 lety +6

    Have you ever had a corrupt sd card situation? I pulled the plug at least 50 times but still boots like a charm, maybe i am lucky? Will try the switch anyway, thanks!

    • @Electronieks
      @Electronieks Před 5 lety +2

      Bringamosa 2times yes

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      I had issues but was not able to find the root cause. If you search the internet you for sure were lucky!

    • @zvpunry1971
      @zvpunry1971 Před 5 lety +5

      Most filesystems try to avoid unsafe states at all time. Some write new changes as planned changes into a journal, execute the changes on the real data and only if these changes are completed, they are removed from the journal. If a crash/poweroff happens in between, then it will just re-apply the changes that were written to the journal or it doesn't do anything to the data. This allows to always have a well defined state of the filesystem. This is called a journaling filessystem. Example: ext3/ext4/xfs
      Another variant is, if data is modified, to write a complete new data structure that references parts of the old data structure. If you change one byte of a large file, the following happens: It copies the block that contains the modified byte and applies the modification. Then it copies the data-structure that points to the many blocks of the large file, but it replaces the pointer to the modified block. And in a final atomic write operation, the new data-structure is written to some other data structure. This is called copy on write filesystem. Example: btrfs/zfs
      Both methods have some drawbacks. Journaling filesystems need to write data twice. Copy on write filesystems tend to be CPU-intensive when randomly accessing data in large files (Databases).
      So people sacrificed data integrity to speed. The typical solution is, to disable journaling or copy on write for data. These techniques are still used for meta-data, so your filesystem structure stays intact. File content can still be messed up. On ext4 this is the default, every write to data goes directly into the file. It is the responsibility of the program that writes files to do this safely. Data-journaling can be enabled with the mount option "data=journal". On btrfs, the default is data-integrity. Everything goes through the copy-on-write mechanism. But it is possible to set the 'C' attribute with chattr/lsattr to some specific directory prior to creating files in it, this disables the copy-on-write mechanism for the files in the directory. Typical directories für this are /var/lib/libvirt/images/ or /var/lib/mysql/. On ext4 you could mount / with data=journal and have a separate filesystem for the database that uses the faster defaults.
      Anyways, the filesystem metadata is relatively safe and data corruption is not directly visible. Programs like mysql can often repair their data files, but it is better to avoid these situations.
      Also, this has nothing to do with the SDCard. The SDCard can also be corrupted, some SDCards used unsafe methods for wear leveling (redirection of addresses depending on write cycles) and corrupted their own database where some block was stored. After power-loss they were unusable. I never had such a SDCard but I have read about these problems. If something like that happens, no filesystem wizardry will help you to recover your data. ;)

    • @macdroid53
      @macdroid53 Před 5 lety +1

      I have several pi's that have been shut down by power off regularly for years, no problems. But, I have also built others with an overlay and also no issues pulling the plug.

    • @bringamosa8480
      @bringamosa8480 Před 5 lety +1

      Thanks for the response. This button is so easy to be made it is almost stupid if i don't and risk the card to get corrupted

  • @OndrejPopp
    @OndrejPopp Před 3 lety

    Tx for the power button solution, however I am also looking for a solution to detect a proper shutdown. This to control a rpi from a microcontroller which will after detecting a proper shutdown of the rpi power down the whole system. Similar to what is happening on a PC motherboard where after the shutdown sequence the power supply is automatically switched off. Maybe this has something to do with the init script? I have actually never looked into that, so if anyone knows that would be great otherwise I am going to dive into this myself.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      Maybe you watch the last video. There we try to build a UPS with such a function. And you can use a switch to GPOI3 to properly shutdown the Pi4

    • @OndrejPopp
      @OndrejPopp Před 3 lety

      @@AndreasSpiess Ok tx Andreas I am going to watch it!

  • @dave07drummer
    @dave07drummer Před rokem

    i used the code in the vid, except i changed pin=25 and gpio works fine as a shutdown button on gpio pin 25 👌

  • @mattivirta
    @mattivirta Před 4 lety

    hmm,only need gpio pin 21 and ground connect switch can safe shutdown, i understand this need only and code gpio21 shutdown..

  • @jeffschroeder4805
    @jeffschroeder4805 Před 3 lety

    Tried safe shutdown button and it didn't work....until I thought to check whether I2C was enabled....disabled it and the button worked as intended. Now how to use I2C without disabling restart feature?

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety

      I do not know. So far, I never used I2C on a Raspberry. I use MCUs for my sensors.

  • @crayzeape2230
    @crayzeape2230 Před 5 lety

    If you can set GPIO2 to output low and use that instead of ground, you'll be much safer in the case of accidental 180 degree rotation (both sides of the link then become 5v).

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I am not sure. The real problem is pin 1 and 2.

    • @crayzeape2230
      @crayzeape2230 Před 5 lety +1

      @@AndreasSpiess I'm referring to using GPIO2 set to 0v output in place of the ground pin. You'd still use GPIO3 the same way so you'd be using pins 3,5 instead of 5,6. If accidentally reversed, the switch would connect pins 2,4 which are both at the same 5v potential so no problem. Pin 1 (reverses pin 6) no longer comes into the equation, so again, no problem.

  • @Hasitier
    @Hasitier Před 5 lety

    If I understood correctly you said that the button also can boot up the raspberry. Can you explain how this works? I did not try it yet but I would like to understand how it would work.
    Thanks for the great video.
    Greetings from Germany
    Michael

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      I do not know how it works. I just pressed the button and it booted. Must’ve part of Raspbian

    • @Hasitier
      @Hasitier Před 5 lety

      Andreas Spiess ok. So if anyone else knows why please let us know. I will try it myself in the next days.

  • @AndrewAHayes
    @AndrewAHayes Před 5 lety

    can this be implemented to LibreElec?

  • @QuasarRedshift
    @QuasarRedshift Před 5 lety

    Comdyna GP- 6 analog computer ?

  • @miriamramstudio3982
    @miriamramstudio3982 Před 4 lety +1

    Well, instead of using a 2x3 header, you could use a 2x4 header. If you put it the wrong way you will simply connect GPIO3 to 5V. Safe on the other side too (GPIO16-GPIO19 or GPIO20-GPIO26). Just my 2 cents. Anyway, great video. Thanks.

  • @skvalen
    @skvalen Před 5 lety

    Here is an idea I had: add an capasitor bank and a comparator that trip the shutdown when the power goes down. The capasitor bank (or a battery) must be large enough to power rPi during the shutdown sequence, it probably doesn't need to be very large.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety +1

      I think I made a video about that.

    • @skvalen
      @skvalen Před 5 lety

      @@AndreasSpiess Do you remember which?

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      No

    • @rickoosteen4943
      @rickoosteen4943 Před rokem

      @@AndreasSpiess Can you research and let everyone know? Would be helpful, thanks!

  • @kevin_delaney
    @kevin_delaney Před 3 lety

    I tried adding just an ssh file in my boot directory but it didn't work, what did work was an empty ssh.txt file. Was this changed in newer releases? I just find it odd that i needed a .txt file extension to make it work and it is something that i just said "f*ck it, let's try this." and it worked. So, for anyone that tries this and an empty ssh file with no extension does not work, try it again with an empty ssh.txt file. IDK why it worked for me, but it did.

    • @AndreasSpiess
      @AndreasSpiess  Před 3 lety +1

      Strange. ssh without extension works everywhere else.

  • @johnblack6134
    @johnblack6134 Před 5 lety

    just one thing, do not add any files like ssh or wpa_supplicant.conf on a sd card that you have just copied from an img file until after the first boot. in my experience raspbian checks the file structure and thinks that it is corrupt and so will not boot. Some builds are ok about this and some are not.. of course after the first headless boot you can only switch it off but this seems to be ok only do wait a bit while it extends the partition and the green light has stopped flashing.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      So far I did not experience those issues (I add the files on my PC)

  • @siskodata
    @siskodata Před 5 lety

    The shutdown button powers off the Pi or just shuts down the OS? Cause how would you know when to power it down after you press the shutdown button?

    • @zaprodk
      @zaprodk Před 5 lety

      The Pi has no way of doing that. You need external circuitry to have that functionality.

    • @siskodata
      @siskodata Před 5 lety

      @@zaprodk I thought so then its useless to me at least I need an indication for powering it off.

    • @zaprodk
      @zaprodk Před 5 lety +1

      @@siskodata Google "ATXRaspi" - Yeah, ATX is completely wrong in this context as it has nothing to do with the ATX configuration, but someone made a module that does what you want.

    • @tozinfo6448
      @tozinfo6448 Před 5 lety

      @@zaprodk : lowpowerlab.com/guide/atxraspi/ lowpowerlab has some interesing things to give, andreas did present something from there before, i guess...

    • @albertosapiens1
      @albertosapiens1 Před 5 lety +1

      You can notice by seeing that the Ethernet LEDs, if it's connected, and the green led next to the red power one are not blinking after a few seconds

  • @michaelgraff6978
    @michaelgraff6978 Před 5 lety

    I really wish there was a simple way to boot from SD, and then change to a fully in-RAM filesystem where the SD card is re-mounted in a read only mode.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      You can boot from a regular USB drive if you want. I made a video on how to do it.

  • @totoskiller
    @totoskiller Před 10 měsíci +1

    Sali du 😊

  • @robatoto
    @robatoto Před 5 lety +2

    Shorting the 3.3V and 5V Pin on the latest Raspberry Pi models 3B+ and 3A+ will destroy the power management IC (PMIC), a custom chip unavailable from any seller. So better be careful with the orientation of the button.

    • @AndreasSpiess
      @AndreasSpiess  Před 5 lety

      Thank you for your information!

    • @dd0356
      @dd0356 Před 5 lety

      I think that ic was there on AliExpress. I once killed the ic and looked for it on the internet. luckily it was loose solder so did not have to buy that.

    • @zaprodk
      @zaprodk Před 5 lety

      @@dd0356 The chip is on Aliexpress. Problem is that it's not the correct one.

    • @robatoto
      @robatoto Před 5 lety

      It’s not the standard version of the MXL7704 chip even tough the label doesn’t indicate it. Just google it. You’ll find plenty of stories about it...

    • @robatoto
      @robatoto Před 5 lety

      Hackaday, 4 days ago: hackaday.com/2019/06/12/shorting-pins-on-a-raspberry-pi-is-a-bad-idea-pmic-failures-under-investigation/#more-355336

  • @cmorda11
    @cmorda11 Před 5 lety

    If you use 5 pin shell, the pins will be in the center, and you can never be wrong! :)

  • @coin777
    @coin777 Před 2 lety

    The button doesnt work form me. It only powers on the pi.

    • @AndreasSpiess
      @AndreasSpiess  Před 2 lety

      Strange. Do you use GPIO3? Maybe they changed something in the OS.

  • @icphoto007
    @icphoto007 Před 4 lety

    this works on raspberry pi 4? grateful

    • @AndreasSpiess
      @AndreasSpiess  Před 4 lety +1

      I do not know. However you easily can try it.

    • @icphoto007
      @icphoto007 Před 4 lety

      @@AndreasSpiess I ended up testing it and it works like a wonder;) grateful

  • @electronic7979
    @electronic7979 Před 5 lety +1

    👍👍👍