{"id":21035,"date":"2021-06-25T20:37:02","date_gmt":"2021-06-25T11:37:02","guid":{"rendered":"https:\/\/www.souichi.club\/?p=21035"},"modified":"2022-03-19T17:25:02","modified_gmt":"2022-03-19T08:25:02","slug":"shutdown-button","status":"publish","type":"post","link":"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/","title":{"rendered":"I added a button to the Raspberry Pi to shut it down with a long press."},"content":{"rendered":"<ul class=\"bogo-language-switcher list-view\"><li class=\"en-US en current first\"><span class=\"bogoflags bogoflags-us\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"en-US\" href=\"https:\/\/www.souichi.club\/en\/wp-json\/wp\/v2\/posts\/21035\/\" title=\"English\" class=\"current\" aria-current=\"page\">English<\/a><\/span><\/li>\n<li class=\"ja last\"><span class=\"bogoflags bogoflags-jp\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"ja\" href=\"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21035\/\" title=\"Japanese\">\u65e5\u672c\u8a9e<\/a><\/span><\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f0febbbbe0b\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #454e5c;color:#454e5c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #454e5c;color:#454e5c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f0febbbbe0b\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Shutdown_the_Raspberry_Pi\" >Shutdown the Raspberry Pi<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Button\" >Button<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Function\" >Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Model_Number\" >Model Number<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Wiring_Diagram\" >Wiring Diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Tested_environment\" >Tested environment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Program\" >Program<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Source_code\" >Source code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#supplementary_explanation\" >supplementary explanation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#Execution_result\" >Execution result<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.souichi.club\/en\/raspberrypi\/shutdown-button\/#At_the_end\" >At the end.<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shutdown_the_Raspberry_Pi\"><\/span>Shutdown the Raspberry Pi<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Since the Raspberry Pi is a Linux OS, it cannot be turned off suddenly.<\/p>\n\n\n\n<p>It is necessary to connect via ssh or connect a keyboard and monitor and use the shutdown command to shutdown the OS.<\/p>\n\n\n\n<p>However, the Raspberry Pi installed at the manufacturing site for IoT is not always able to shut down properly.<\/p>\n\n\n\n<p>I added a button for shutdown to my Raspberry Pi, and I&#8217;ll write an article about it as a reminder.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?resize=512%2C384&#038;ssl=1\" alt=\"I added a shutdown button to the Raspberry Pi.\" class=\"wp-image-20633\" width=\"512\" height=\"384\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?resize=1024%2C767&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?resize=768%2C575&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?resize=1536%2C1150&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-06.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Button\"><\/span>Button<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Function\"><\/span>Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>To avoid shutting down when a button is touched accidentally, shutdown is now done only when the button is &#8220;long pressed&#8221;.<\/li><li>Selected a button with LED light.<\/li><li>The LED light on the button turns on when the program is running and turns off when the program is shutdown by pressing and holding the button.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Model_Number\"><\/span>Model Number<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I bought an OMRON pushbutton switch (model number = A165L-JRM-5D-1).<\/p>\n\n\n\n<p>The meaning of the model number is as follows.<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>A16<\/p>\n<\/td>\n<td>\n<p>The type of the button.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>5<\/p>\n<\/td>\n<td>\n<p>IP standard grade of water resistance or protection.<\/p>\n<ul>\n<li>None: IP40 (protected from wires, etc., not protected against water ingress)<\/li>\n<li>5: IP66 (completely protected from dust ingress, not harmed by strong direct jets of water from any direction)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>L<\/p>\n<\/td>\n<td>\n<p>Whether it is illuminated or not<\/p>\n<ul>\n<li>None: Non-illuminated<\/li>\n<li>L: Illumination<\/li>\n<\/ul>\n<p>I wanted a button with an LED light, so I chose the illuminated type.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>J<\/p>\n<\/td>\n<td>\n<p>Button shape<\/p>\n<ul>\n<li>J: Rectangle<\/li>\n<li>A: Square<\/li>\n<li>T: Round<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>R<\/p>\n<\/td>\n<td>\n<p>Button color<\/p>\n<ul>\n<li>R: Red<\/li>\n<li>Y\uff1aYellow<\/li>\n<li>PY: Pure yellow<\/li>\n<li>G\uff1aGreen<\/li>\n<li>W\uff1aWhite<\/li>\n<li>A: Blue<\/li>\n<li>PW: Pure white<\/li>\n<li>B\uff1aBlack (non-illuminated only)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>M<\/p>\n<\/td>\n<td>\n<p>Button behavior when pressed<\/p>\n<ul>\n<li>M: Momentary (turns on only when the button is pressed)<\/li>\n<li>A: Alternate (remains on after the button is pressed and released)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>5D<\/p>\n<\/td>\n<td>\n<p>LED voltage<\/p>\n<ul>\n<li>None: Non-illuminated<\/li>\n<li>5D: 5V DC<\/li>\n<li>12D: AC\/DC12V<\/li>\n<li>24D: AC\/DC24V<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>1<\/p>\n<\/td>\n<td>\n<p>This shows the terminal arrangement.<\/p>\n<p>In terms of circuitry, I would have preferred to use an a-contact, but since the button I had available was a c-contact, I chose a type of button with only one contact.<\/p>\n<ul>\n<li>1: 1c (soldered terminal)<\/li>\n<li>2: 2c (soldered terminal)<\/li>\n<li>1P: 1c (printed circuit board terminal)<\/li>\n<li>2P: 2c (printed circuit board terminal)<\/li>\n<li>2S: 2C (quick connector)<\/li>\n<\/ul>\n<p>The terminal arrangement for 1c is as follows (<a href=\"https:\/\/www.fa.omron.co.jp\/data_pdf\/cat\/a16_ds_j_11_9.pdf?id=1101\" target=\"_blank\" rel=\"noopener\">from the OMRON manual<\/a>)<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-01.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"r_image alignnone wp-image-20623 size-full\" title=\"Bottom View\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-01.png?resize=308%2C280&#038;ssl=1\" alt=\"Bottom View\" width=\"308\" height=\"280\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-01.png?w=308&amp;ssl=1 308w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-01.png?resize=300%2C273&amp;ssl=1 300w\" sizes=\"auto, (max-width: 308px) 100vw, 308px\" \/><\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wiring_Diagram\"><\/span>Wiring Diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>I don&#8217;t use NC connector.<\/p>\n\n\n\n<p>It is used as a button with real a-contact.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?resize=768%2C610&#038;ssl=1\" alt=\"Add a shutdown button\" class=\"wp-image-21042\" width=\"768\" height=\"610\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?resize=1024%2C813&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?resize=300%2C238&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?resize=768%2C610&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-en-01.png?w=1360&amp;ssl=1 1360w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tested_environment\"><\/span>Tested environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The following environment was tested.<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>Raspberry Pi<\/p>\n<\/td>\n<td>\n<p>Raspberry Pi 4B<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>OS<\/p>\n<\/td>\n<td>\n<p>Raspberry Pi OS 32Bit<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Program\"><\/span>Program<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>I saved the following program in  &#8220;.local\/shutdown_test\/&#8221;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source_code\"><\/span>Source code<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>shutdown_button.py<\/p>\n\n\n<pre class=\"line-numbers\"><code class=\"lang-python\"># -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Jun  5 08:24:26 2021\n\n\u30fbPress and hold button to shut down\n\u30fbLED on during program operation, off during shutdown\n\n@author: Souichirou Kikuchi\n\"\"\"\n\nimport os\nimport RPi.GPIO as GPIO\nfrom time import sleep\n\nPIN_BUTTON_LED = 4 # LED on the button\nPIN_BUTTON_SD = 22 # shutdown button\n\ndef shut_down(channel): # Long Press to shutdown\n    if channel == PIN_BUTTON_SD:\n        sw = 0\n        for _ in range(15):\n            sleep(0.2) # 0.2 seconds x 15 times = 3 seconds\n            sw = GPIO.input(channel)\n            if sw == 0: # If there is even one LOW out of 15 times, it will not shutdown.\n                break\n        if sw == 1:\n            GPIO.output(PIN_BUTTON_LED, GPIO.LOW) # Button LED off\n            os.system('sudo shutdown -h now') # shutdown\n\nGPIO.setmode(GPIO.BCM)\nGPIO.setup(PIN_BUTTON_LED, GPIO.OUT)\nGPIO.setup(PIN_BUTTON_SD, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)\nGPIO.add_event_detect(PIN_BUTTON_SD, GPIO.RISING, callback=shut_down, bouncetime=200)\n\nif __name__ == \"__main__\":\n    try:\n        print('ShutDown Test Program Start') # Program start\n        GPIO.output(PIN_BUTTON_LED, GPIO.HIGH) # LED lights on the button\n        while True:\n            sleep(0.001)\n    except:\n        pass\n    finally:\n        GPIO.cleanup()\n        print('ShutDown Test Program End') # Program ended<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"supplementary_explanation\"><\/span>supplementary explanation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I&#8217;ve included some comments in the program, but I&#8217;ll add a few more.<\/p>\n\n\n<pre><code class=\"lang-python\">GPIO.setup(PIN_BUTTON_SD, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)<\/code><\/pre>\n\n\n<p>is the GPIO22 connected from the button NO, but I have specified a pull_down resistor.<\/p>\n\n\n\n<p>Also, the<\/p>\n\n\n<pre><code class=\"lang-python\">GPIO.add_event_detect(PIN_BUTTON_SD, GPIO.RISING, callback=shut_down, bouncetime=200)<\/code><\/pre>\n\n\n<p>In the same way, when the voltage of GPIO22 rises from LOW to HIGH (RISING), the shut_down function is called.<\/p>\n\n\n\n<p>Since the voltage does not rise in a straight line, the interval of 200 milliseconds between the next call to the shut_down function is left with bouncetime=200 to prevent the function from being called repeatedly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Execution_result\"><\/span>Execution result<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Run the program with the following command.<\/p>\n\n\n<pre><code class=\"lang-shell\">cd ~\/.local\/shutdown_test\npython shutdown_button.py<\/code><\/pre>\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?resize=512%2C319&#038;ssl=1\" alt=\"Run a shutdown test program.\" class=\"wp-image-20630\" width=\"512\" height=\"319\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?resize=1024%2C638&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?resize=300%2C187&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?resize=768%2C478&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-04.png?w=1026&amp;ssl=1 1026w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<p>The LED lights up, and I was able to confirm that long press it (for about 3 seconds) will shut it down.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?resize=512%2C373&#038;ssl=1\" alt=\"Long press the button to shutdown the OS.\" class=\"wp-image-20631\" width=\"512\" height=\"373\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?resize=1024%2C745&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?resize=300%2C218&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?resize=768%2C558&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?resize=1536%2C1117&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"At_the_end\"><\/span>At the end.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is the end of the article on shutdown by button.<\/p>\n\n\n\n<p>The reason why Raspberry Pi (Linux OS) can&#8217;t be shutdown suddenly is that various files used by the OS are written to the SD card while the OS is running.<\/p>\n\n\n\n<p>If you suddenly turn off the power while writing files, those files may be corrupted, which may affect the next time the OS boots and prevent it from booting.<\/p>\n\n\n\n<p>As a countermeasure for this, I&#8217;ve written an article on how to &#8220;add a shutdown button&#8221;.<\/p>\n\n\n\n<p>Other methods.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Set the file system to Read Only(SD Card)<\/li><li>Relay circuit to give grace until OS shutdown<\/li><\/ol>\n\n\n\n<p>I&#8217;ve heard that there is a way to do the above, and I&#8217;d like to try it soon.<\/p>\n\n\n<div class=\"postscript_balloon\">Finally.<\/div>\n\n\n<p>I hope this article will be useful to someone somewhere.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Since the Raspberry Pi is a Linux OS, it cannot be turned off suddenly.Need to shut down the OS with the shutdown command.<\/p>\n","protected":false},"author":5,"featured_media":20631,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/www.souichi.club\/?p=20609","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[136],"tags":[138],"class_list":["post-21035","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberrypi","tag-python","en-US"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/shutdown-button-05.jpg?fit=1920%2C1396&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/comments?post=21035"}],"version-history":[{"count":1,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21035\/revisions"}],"predecessor-version":[{"id":24537,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/21035\/revisions\/24537"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media\/20631"}],"wp:attachment":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media?parent=21035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/categories?post=21035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/tags?post=21035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}