Yatsehitter
Posts: 7
Joined: Mon Jun 16, 2014 4:57 pm

Installing a physical shutdown button

Thu Jul 03, 2014 10:46 am

Hi,

Apologies if this is in the wrong place - I wasn't sure where to post this. Mods please move if this is incorrect.

I am trying to get a shutdown button fitted as per this guide:

http://spaceblogs.org/2013/06/03/shut-d ... -function/

I know there are a number of other options involving GPIO pins and resistors but I chose this method because it only used parts I already have.

I have followed this guide to the letter. Restart works fine but the shutdown button doesn't do anything.

Literally the only thing I could think might be causing it was that I saved the shutdown.py script in notepad on windows and was wondering if maybe it wasn't compatible?

I don't want to leave the pi on and definitely want the shutdown button to work - has anyone got any advise?

Thanks

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Installing a physical shutdown button

Thu Jul 03, 2014 11:02 am

Is shutdown.py in the pi home directory?

What happens when you type this command:

Code: Select all

sudo python /home/pi/shutdown.py
I expect nothing will happen, but you will not return to the command prompt (because the program is an infinite loop). However, if no error messages appear then press the shutdown button...
...did it work?

If there were errors, post them here.

If this worked, then something is wrong with how you set up cron.

If it didn't work (but no errors), then something is wrong with your pushbutton or wiring.

Yatsehitter
Posts: 7
Joined: Mon Jun 16, 2014 4:57 pm

Re: Installing a physical shutdown button

Thu Jul 03, 2014 11:20 am

Hi mate,

thanks for the quick response.

The error I get is:

Traceback (most recent call last):
File "/home/pi/shutdown.py", line 9, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO

So something isn't right - I just copied the shutdown.py exactly from what the link in that guide said - is there a mistake in it or is it me being dense! (The latter is probably more likely!)

Many thanks

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Installing a physical shutdown button

Thu Jul 03, 2014 11:26 am

Yatsehitter wrote:Hi mate,

thanks for the quick response.

The error I get is:

Traceback (most recent call last):
File "/home/pi/shutdown.py", line 9, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO

So something isn't right - I just copied the shutdown.py exactly from what the link in that guide said - is there a mistake in it or is it me being dense! (The latter is probably more likely!)

Many thanks
I am sure you have it set up just right, but you are missing one piece. You need the GPIO library.

Try this, then try the script again:

Code: Select all

sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio

Yatsehitter
Posts: 7
Joined: Mon Jun 16, 2014 4:57 pm

Re: Installing a physical shutdown button

Thu Jul 03, 2014 11:53 am

hmm, i may be being stupid but I ran those commands and got errors about being unable to fetch the files, the pi suggested first running:

sudo apt-get update

So I did this, worked fine, I then ran:

sudo apt-get install python-dev - again this worked fine. But then when I ran:

sudo apt-get install python-rpi.gpio (ie the bit I'm actually after!) it gave me the following error:

pi@raspbmc:~$ sudo apt-get install python-rpi.gpio
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-rpi.gpio
E: Couldn't find any package by regex 'python-rpi.gpio'

I'm confused because this is a brand new install of raspbmc on the pi so there shouldn't be any corruption? Unless what I'm trying to do will only work on Raspbian?

Thanks mate

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Installing a physical shutdown button

Thu Jul 03, 2014 12:02 pm

Yatsehitter wrote:hmm, i may be being stupid but I ran those commands and got errors about being unable to fetch the files, the pi suggested first running:

sudo apt-get update

So I did this, worked fine, I then ran:

sudo apt-get install python-dev - again this worked fine. But then when I ran:

sudo apt-get install python-rpi.gpio (ie the bit I'm actually after!) it gave me the following error:

pi@raspbmc:~$ sudo apt-get install python-rpi.gpio
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-rpi.gpio
E: Couldn't find any package by regex 'python-rpi.gpio'

I'm confused because this is a brand new install of raspbmc on the pi so there shouldn't be any corruption? Unless what I'm trying to do will only work on Raspbian?

Thanks mate
Ah, quite possibly.

The python-rpi.gpio is available on my Pi (it's up-to-date with Raspbian). Perhaps you can request the raspbmc maintainers to add this package?

Try

apt-get upgrade

then try getting python-rpi.gpio, just in case.

Yatsehitter
Posts: 7
Joined: Mon Jun 16, 2014 4:57 pm

Re: Installing a physical shutdown button

Thu Jul 03, 2014 12:32 pm

Bugger yeah it seems that this is exactly what the issue is! Never mind. Will see if they will look at it and if not will see if there are any other options - including maybe running xbmc on top of raspbian. although this would obviously depend on performance.

Thanks a lot for all the help mate, that was spot on.

Cheers

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Installing a physical shutdown button

Thu Jul 03, 2014 12:48 pm

You're welcome.

You can do it the Hard Way if you want. Download the package from here:
https://pypi.python.org/pypi/RPi.GPIO

And try installing it yourself.

Return to “General discussion”