{"id":2052,"date":"2021-08-04T10:43:36","date_gmt":"2021-08-04T08:43:36","guid":{"rendered":"https:\/\/dross.net\/aviation\/?page_id=2052"},"modified":"2023-06-17T08:33:50","modified_gmt":"2023-06-17T06:33:50","slug":"how-to-add-a-safe-shutdown-button-to-stratux","status":"publish","type":"page","link":"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-add-a-safe-shutdown-button-to-stratux\/","title":{"rendered":"How to add a safe shutdown button to Stratux (or Raspberry Pi)?"},"content":{"rendered":"<div id=\"pl-2052\"  class=\"panel-layout\" ><div id=\"pg-2052-0\"  class=\"panel-grid panel-no-style\" ><div id=\"pgc-2052-0-0\"  class=\"panel-grid-cell\" ><div id=\"panel-2052-0-0-0\" class=\"so-panel widget widget_sow-editor panel-first-child panel-last-child\" data-index=\"0\" ><div class=\"panel-widget-style panel-widget-style-for-2052-0-0-0\" ><div\n\t\t\t\n\t\t\tclass=\"so-widget-sow-editor so-widget-sow-editor-base\"\n\t\t\t\n\t\t><h2 class=\"widget-title\">Overview<\/h2>\n<div class=\"siteorigin-widget-tinymce textwidget\">\n\t<p><a title=\"DIY Component\/ Part List for Stratux (OGN) Flarm\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/#stratux-component-list\">Component List<\/a><br \/>\n<a title=\"Stratux (OGN) Flarm first time set-up instructions\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/stratux-first-time-setup-instructions\/\">Set up Instructions<\/a><br \/>\n<a title=\"How to install Stratux EU\/ US Firmware on SD Card?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-install-stratux-firmware\/\">Install Firmware<\/a><br \/>\n<a title=\"How to install Open FlightMap Europe\/ VFR Sectional Charts US?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-install-open-flightmap-europe-vfr-sectional-charts-us\/\">Install FlightMap<\/a><br \/>\n<a title=\"How to add a physical shutdown button to Stratux?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-add-a-safe-shutdown-button-to-stratux\/\">Add shutdown button<\/a><br \/>\n<a title=\"How to flash a TTGO T-Beam (ESP32) from LilyGo?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-flash-a-ttgo-t-beam-esp32-from-lilygo\/\">Flash a T-Beam<\/a><br \/>\n<a title=\"How to flash a softRF TTGO T-Motion (STM32) from LilyGo?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-flash-a-softrf-ttgo-t-motion-from-lilygo\/\">Flash a T-Motion<\/a><br \/>\n<a title=\"How to add a barometric pressure altitude sensor to a TTGO T-Beam (ESP32)?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-add-a-barometric-pressure-altitude-sensor-to-a-ttgo-t-beam-esp32\/\">Altitude Sensor to T-Beam<\/a><br \/>\n<a title=\"How to add a barometric pressure altitude sensor to a softRF\/ T-Motion (STM32)?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-add-a-barometric-pressure-altitude-sensor-to-a-softrf-t-motion-stm32\/\">Altitude Sensor to T-Motion<\/a><br \/>\n<a title=\"How to add an AHRS or pressure altitude sensor to Stratux?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-add-an-ahrs-or-pressure-altitude-sensor\/\">Add AHRS Sensor<\/a><br \/>\n<a title=\"How to upgrade Stratux with Transmitting capability?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-upgrade-stratux-with-transmitting-capability\/\">Upgrade Stratux<\/a><br \/>\n<a title=\"How to submit your Stratux to OGN (Open Glider Network)?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-submit-your-stratux-to-ogn-open-glider-network\/\">Submit to OGN<\/a><br \/>\n<a title=\"Support needed for Stratux, T-Beam or softRF\/ T-Motion?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/support\/\">Support needed?<\/a><\/p>\n<\/div>\n<\/div><\/div><\/div><\/div><div id=\"pgc-2052-0-1\"  class=\"panel-grid-cell\" ><div class=\"panel-cell-style panel-cell-style-for-2052-0-1\" ><div id=\"panel-2052-0-1-0\" class=\"so-panel widget widget_sow-editor panel-first-child panel-last-child\" data-index=\"1\" ><div\n\t\t\t\n\t\t\tclass=\"so-widget-sow-editor so-widget-sow-editor-base\"\n\t\t\t\n\t\t>\n<div class=\"siteorigin-widget-tinymce textwidget\">\n\t<p>By default a Raspberry Pi and therefore a <a title=\"Overview of all Stratux (OGN) Flarm versions\" href=\"https:\/\/dross.net\/aviation\/shop\/category\/stratux\/\">Stratux Flarm<\/a> does not have a physical switch to shut down the operating system. Just cutting the power of a Raspberry (or any computer) will result in RAM issues in the long term. Therefore, this section explains how we use a button which triggers the command to shut down a Raspberry Pi\/ Stratux safely.<\/p>\n<p>Since Python becomes more popular, we will use this programming language.<\/p>\n<figure id=\"attachment_1904\" aria-describedby=\"caption-attachment-1904\" style=\"width: 300px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1904\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/06\/safe-shutdown-switch-for-stratux-300x300.jpg\" alt=\"Stratux firmware by Dross:Aviation supports safe shutdown switch for Stratux FLARM\" width=\"300\" height=\"300\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/06\/safe-shutdown-switch-for-stratux-300x300.jpg 300w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/06\/safe-shutdown-switch-for-stratux-150x150.jpg 150w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/06\/safe-shutdown-switch-for-stratux-600x600.jpg 600w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/06\/safe-shutdown-switch-for-stratux.jpg 650w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-1904\" class=\"wp-caption-text\">Enable Stratux firmware to support shutdown switch<\/figcaption><\/figure>\n<p><a title=\"buy your ready 2 fly Stratux Firmware here\" href=\"https:\/\/dross.net\/aviation\/shop\/sd-card-with-stratux-firmware\/\">Buy your ready 2 fly Stratux Firmware SD card instead.<\/a><\/p>\n<hr \/>\n<h2>Pre-work to be done when using firmware version 026 or newer<\/h2>\n<ol>\n<li>Since the <a title=\"download latest firmware version for Stratux\" href=\"https:\/\/github.com\/b3nn0\/stratux\/releases\" target=\"_blank\" rel=\"noopener\">firmware version 026<\/a> or newer does no longer allow to write logs to micro SD card, a quick change in the Stratux web interface (open your browser and type-in <a href=\"http:\/\/192.168.10.1\/\" target=\"_blank\" rel=\"noopener\">http:\/\/192.168.10.1\/<\/a>) &gt; Settings &gt; <a title=\"open Stratux web interface\" href=\"http:\/\/192.168.10.1\/#\/settings\" target=\"_blank\" rel=\"noopener\">Diagnostics<\/a> is needed.<\/li>\n<li>Go to Diagnostics and set \"persistent logging\" to enabled. this will allow us to modify the firmware.\n<figure id=\"attachment_2772\" aria-describedby=\"caption-attachment-2772\" style=\"width: 410px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2772 size-full\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/10\/Stratux-persistent-logging.jpg\" alt=\"Stratux persistent logging: write logs to micro SD card instead of RAM\" width=\"410\" height=\"237\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/10\/Stratux-persistent-logging.jpg 410w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/10\/Stratux-persistent-logging-300x173.jpg 300w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><figcaption id=\"caption-attachment-2772\" class=\"wp-caption-text\">Stratux persistent logging: write logs to micro SD card instead of RAM<\/figcaption><\/figure>\n<\/li>\n<li>follow steps below. Once the modifications to support a physical safe shutdown switch has been completed, change the persistent logging back to \"disabled\"<\/li>\n<\/ol>\n<h2>Use PUTTY to enable SSH connection to your Stratux\/ Raspberry Pi<\/h2>\n<ol>\n<li>The operating system has already <a title=\"How to install Stratux EU Firmware on SD Card?\" href=\"https:\/\/dross.net\/aviation\/how-to-and-where-to-start-with-stratux\/how-to-install-stratux-firmware\/\">been flashed on a SD card<\/a>.<\/li>\n<li>Download and install the latest version of <a title=\"This page contains download links for the latest released version of PuTTY\" href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html\" target=\"_blank\" rel=\"noopener\">PUTTY<\/a>, a client to enable SSH connection<\/li>\n<li>Boot up your Stratux<\/li>\n<li>Stratux' Wifi should appear in your Laptop's network section.<\/li>\n<li>Execute PUTTY and use Stratux' default IP address as the Host Name: 192.168.10.1\n<figure id=\"attachment_2129\" aria-describedby=\"caption-attachment-2129\" style=\"width: 457px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2129 size-full\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/putty-enable-ssh-connection-to-raspberry-pi-and-stratux-flarm.jpg\" alt=\"PUTTY - enable SSH connection to Raspberry PI and Stratux (OGN) Flarm\" width=\"457\" height=\"447\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/putty-enable-ssh-connection-to-raspberry-pi-and-stratux-flarm.jpg 457w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/putty-enable-ssh-connection-to-raspberry-pi-and-stratux-flarm-300x293.jpg 300w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><figcaption id=\"caption-attachment-2129\" class=\"wp-caption-text\">PUTTY - enable SSH connection to Raspberry PI and Stratux (OGN) Flarm<\/figcaption><\/figure>\n<\/li>\n<li>Use the Raspberry PI's standard username \"pi\" and password \"raspberry\"<br \/>\nthe screen should look like the following:<\/p>\n<figure id=\"attachment_2132\" aria-describedby=\"caption-attachment-2132\" style=\"width: 757px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2132 size-full\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/PUTTY-SSH-welcome-page.jpg\" alt=\"PUTTY SSH welcome page\" width=\"757\" height=\"694\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/PUTTY-SSH-welcome-page.jpg 757w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/PUTTY-SSH-welcome-page-300x275.jpg 300w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/PUTTY-SSH-welcome-page-600x550.jpg 600w\" sizes=\"auto, (max-width: 757px) 100vw, 757px\" \/><figcaption id=\"caption-attachment-2132\" class=\"wp-caption-text\">PUTTY SSH welcome page<\/figcaption><\/figure>\n<hr \/>\n<p><strong>highlight the source code below, go to PUTTY and right click to paste the code<\/strong><\/p>\n<hr \/>\n<\/li>\n<\/ol>\n<h2>Creating the shut down button support<\/h2>\n<ol>\n<li>We create a folder which we name \"Scripts\".<\/li>\n<li>Then a blank file named \"shutdown_pi.py\" gets created<\/li>\n<li>we edit the file and fill-in content into it.<br \/>\n(mark the code, click right in PUTTY console to paste the code, then press Enter)<\/p>\n<pre class=\"python\">mkdir Scripts  \ncd Scripts  \ntouch shutdown_pi.py\nnano shutdown_pi.py<\/pre>\n<\/li>\n<li>Then fill-in the below code into the file:\n<pre class=\"python\">#!\/bin\/python  \n# Simple script for shutting down the raspberry Pi at the press of a button.  \n# by Inderpreet Singh, modified by Alexander Dross - Dross:Aviation \n\u00a0\nimport RPi.GPIO as GPIO  \nimport time  \nimport os  \n\u00a0\n# Use the Broadcom SOC Pin numbers  \n# Setup the Pin with Internal pullups enabled and PIN in reading mode.  \nGPIO.setmode(GPIO.BCM)  \nGPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP)  \n\u00a0\n# Our function on what to do when the button is pressed  \ndef Shutdown(channel):  \n    os.system(\"sudo shutdown -h now\")  \n\u00a0\n# Add our function to execute when the button pressed event happens  \nGPIO.add_event_detect(21, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)  \n\u00a0\n# Now wait!  \nwhile 1:  \n    time.sleep(1)<\/pre>\n<\/li>\n<li class=\"python\">Save the file by pressing CTRL+X then press y to confirm to overwrite and Enter<\/li>\n<li>The Python script now tries to access GPIO Pin \u00a0<a title=\"GPIO pin layout to add Physical Shut-Down Switch\" href=\"https:\/\/www.raspberrypi.org\/documentation\/usage\/gpio\/\" target=\"_blank\" rel=\"noopener\">GPIO pin 39 (Ground) and 40 (GPIO 21 \u2013 PCM_DOUT)<\/a><\/li>\n<li>To test if the script works, please simply enter the following lines into PUTTY (again, mark the code, and do a right click in the console to paste)\n<pre class=\"python\">sudo python shutdown_pi.py<\/pre>\n<\/li>\n<li>If the script works, you must close and re-open PUTTY again, by following steps 4. and 5.<\/li>\n<li>Now we have to enable that the script runs automatically every time the Raspberry Pi\/ Stratux starts. Therefore we execute the following command:\n<pre class=\"python\">sudo nano \/etc\/rc.local<\/pre>\n<\/li>\n<li>We need to add our python command before the last line which closes the if loop. Therefore, add the following line before the #fi at the end of the file:\n<figure id=\"attachment_2141\" aria-describedby=\"caption-attachment-2141\" style=\"width: 666px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2141 size-full\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/add-the-following-line-before-the-fi-at-the-end-of-the-file.jpg\" alt=\"add the following line before the #fi at the end of the file\" width=\"666\" height=\"419\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/add-the-following-line-before-the-fi-at-the-end-of-the-file.jpg 666w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/add-the-following-line-before-the-fi-at-the-end-of-the-file-300x189.jpg 300w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/08\/add-the-following-line-before-the-fi-at-the-end-of-the-file-600x377.jpg 600w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><figcaption id=\"caption-attachment-2141\" class=\"wp-caption-text\">add the following line before the #fi at the end of the file<\/figcaption><\/figure>\n<pre class=\"python\">sudo python \/home\/pi\/Scripts\/shutdown_pi.py &amp;<\/pre>\n<\/li>\n<li>Save the file by pressing CTRL+X and then y, Enter<\/li>\n<li>go back to bullet point 2. -&gt; Go to <a href=\"http:\/\/192.168.10.1\/#\/settings\" target=\"_blank\" rel=\"noopener\">Diagnostics and set \"persistent logging\"<\/a> to disabled.<\/li>\n<li>Connect the switch to GPIO pin 39 (Ground) and 40 (GPIO 21 \u2013 PCM_DOUT) and press it. The Stratux should now shutdown within 2 seconds.\n<figure id=\"attachment_2644\" aria-describedby=\"caption-attachment-2644\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2644 size-large\" src=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO-1024x555.jpg\" alt=\"Connect Shutdown Switch to Raspberry PI3B GPIO Pins\" width=\"1024\" height=\"555\" srcset=\"https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO-1024x555.jpg 1024w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO-300x163.jpg 300w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO-768x416.jpg 768w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO-600x325.jpg 600w, https:\/\/dross.net\/aviation\/wp-content\/uploads\/2021\/09\/Raspberry-pi3-GPIO.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-2644\" class=\"wp-caption-text\">Connect Shutdown Switch to Raspberry PI3B GPIO Pins<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<hr \/>\n<ul>\n<li>Too lazy or unsure how to establish the above? <a title=\"buy your ready 2 fly Stratux Firmware here\" href=\"https:\/\/dross.net\/aviation\/shop\/sd-card-with-stratux-firmware\/\">Buy your ready 2 fly Stratux Firmware SD card instead.<\/a><\/li>\n<li>Source: https:\/\/www.quartoknows.com\/page\/raspberry-pi-shutdown-button<\/li>\n<li>Instructions above are provided \u201cas is\u201d with no express or implied guarantee.<\/li>\n<\/ul>\n<\/div>\n<\/div><\/div><\/div><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Component List Set up Instructions Install Firmware Install FlightMap Add shutdown button Flash a T-Beam Flash a T-Motion Altitude Sensor to T-Beam Altitude Sensor to T-Motion Add AHRS Sensor Upgrade Stratux Submit to OGN Support needed? By default a Raspberry Pi and therefore a Stratux Flarm does not have a physical switch to shut down [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1905,"parent":1996,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2052","page","type-page","status-publish","has-post-thumbnail","hentry","post"],"_links":{"self":[{"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/pages\/2052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/comments?post=2052"}],"version-history":[{"count":1,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/pages\/2052\/revisions"}],"predecessor-version":[{"id":3531,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/pages\/2052\/revisions\/3531"}],"up":[{"embeddable":true,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/pages\/1996"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/media\/1905"}],"wp:attachment":[{"href":"https:\/\/dross.net\/aviation\/wp-json\/wp\/v2\/media?parent=2052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}