If you have OpenElec running a Raspbery Pi with one of the original ARM processors and wish to play with the GPIO, you may be having some trouble recommended you read. This applies to the Raspberry Pi Revisions A, B, B+. I think it should also work on the Raspberry Pi Zero, but I don’t have one to test.
GPIO can be useful for many things, but specifically for an OpenElec isntallation, GPIO can be useful if you wish to use any buttons for input, particularly a button for an on/off switch.
Raspberry Pi – Version 2
If you are using a Raspberry Pi V2, there is an addon available to easily add GPIO functions. The add-on is available from the Unofficial repository and full instructions are available here.
How to Add GPIO for a first generation Raspberry Pi
Unfortunately, OpenElec does not offer apt-get or standard install libraries. However, I do have a SD card from a previous Pi installation on the original Pi that had the appropriate GPIO libraries installed.
The Easy Way
I’ve attempted to do some of the heavy lifting once, by copying the files from a working Raspbian distribution. You can download the files here and copy them onto your sd card, but the process below downloads the files directly to your Pi.
Here are the steps:
- Connect your Pi to your local network and find it’s IP address .
- SSH into your Pi at the IP address indicated. If you are using windows, you can use PuTTY as an SSH client. The default username is
rootand password is
- Get the library files by typing the following at the command prompt:
- Extract the contents of the RPi.GPIO file by doing
tar -zxvf RPi.GPIO_flub.tar.gzThis should create the /storage/lib folder holding the python library files.
- Add the following to your script that uses GPIO
Code to add:
import sys sys.path.append('/storage/lib') import RPi.GPIO as GPIO
This should be all that you need to do to use the GPIO in your code. If you would like to see an example of the shutdown script, take a look at my post on creating a wake up / shutdown button, here. Just remember to make the necessary changes to shutdown.py.
The Hard Way
If you do not wish to copy the zip file shown above, you can retrieve the library files from your own install.
The library files should be stored in:
At least in my distribution, the
__init__.py was a symbolic link to a zero length file. The symbolic link would cause trouble since the main file isn’t present. Therefore, you should remove the
__init__.py file and use nano to create a new file with nothing in it.
Finally, copy these onto your SD card into a lib folder or some other convenient place to reference in your script.