By default a Raspberry Pi and therefore a Stratux Flarm 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.
Since Python becomes more popular, we will use this programming language.
Use PUTTY to enable SSH connection to your Stratux/ Raspberry Pi
- The operating system has already been flashed on a SD card.
- Download and install the latest version of PUTTY, a client to enable SSH connection
- Boot up your Stratux
- Stratux' Wifi should appear in your Laptop's network section.
- Execute PUTTY and use Stratux' default IP address as the Host Name:192.168.10.1
- Use the Raspberry PI's standard username "pi" and password "raspberry"
the screen should look like the following:
highlight the source code below, go to PUTTY and right click to paste the code
Creating the shut down button support
- We create a folder which we name "Scripts".
- Then a blank file named "shutdown_pi.py" gets created
- we edit the file and fill-in content into it.
(mark the code, click right in PUTTY console to paste the code, then press Enter)
mkdir Scripts cd Scripts touch shutdown_pi.py nano shutdown_pi.py
- Then fill-in the below code into the file:
#!/bin/python # Simple script for shutting down the raspberry Pi at the press of a button. # by Inderpreet Singh, modified by Dross:Aviation import RPi.GPIO as GPIO import time import os # Use the Broadcom SOC Pin numbers # Setup the Pin with Internal pullups enabled and PIN in reading mode. GPIO.setmode(GPIO.BCM) GPIO.setup(21, GPIO.IN, pull_up_down = GPIO.PUD_UP) # Our function on what to do when the button is pressed def Shutdown(channel): os.system("sudo shutdown -h now") # Add our function to execute when the button pressed event happens GPIO.add_event_detect(21, GPIO.FALLING, callback = Shutdown, bouncetime = 2000) # Now wait! while 1: time.sleep(1)
- Save the file by pressing CTRL+X then press y to confirm to overwrite and Enter
- The Python script now tries to access GPIO Pin GPIO pin 39 (Ground) and 40 (GPIO 21 – PCM_DOUT)
- 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)
sudo python shutdown_pi.py
- If the script works, you must close and re-open PUTTY again, by following steps 4. and 5.
- Now we have to enable that the script runs automatically every time the Raspberry Pi/ Stratux starts. Therefore we execute the following command:
sudo nano /etc/rc.local
- 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:
sudo python /home/pi/Scripts/shutdown_pi.py &
- Save the file by pressing CTRL+X and then y, Enter
- Connect the switch to GPIO pin 39 (Ground) and 40 (GPIO 21 – PCM_DOUT) and press it. The Stratux should now shutdown within 2 seconds.
- Too lazy or unsure how to establish the above? Buy your ready 2 fly Stratux Firmware SD card instead.
- Source: https://www.quartoknows.com/page/raspberry-pi-shutdown-button
- Instructions above are provided “as is” with no express or implied guarantee.