Hello,
I'm trying to install a Shutdown buttons to my Raspberry pi 3B, I followed a few forums and here is what I did;
1. mkdir /storage/.Scripts
2. nano /storage/.scripts/shutdown_pi.py
In "/storage/.scripts/shutdown_pi.py" I have the following instructions;
#!/bin/python
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh
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(18, 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(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
# Now wait!
while 1:
time.sleep(1)
Display More
3. nano /storage/.config/autostart.sh
in "/storage/.config/autostart.sh" I have the following instructions:
3. I went in the libreELEC UI and did the following;
Program ---> Get more ... ---> Raspberry Pi Tools ---> install
4. reboot
when I tested the buttons nothing happened so I tried;
LibreELEC:~/.Scripts # python shutdown_pi.py
here is what I got:
Traceback (most recent call last):
File "shutdown_pi.py", line 5, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO
Is there a step I forgot?, or is there another thing I need to install?
Thanks for your help.