HowTo: Adding GPIO to OpenElec running on original series Raspberry Pi (Rev A, B, B+, Zero?)

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.

Why GPIO?

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:

  1. Connect your Pi to your local network and find it’s IP address .
  2. 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 root and password is openelec
  3. Get the library files by typing the following at the command prompt: wget http://www.barryhubbard.com/wp-content/uploads/2015/12/RPi.GPIO_flub.tar.gz
  4. Extract the contents of the RPi.GPIO file by doing tar -zxvf RPi.GPIO_flub.tar.gz This should create the /storage/lib folder holding the python library files.
  5. 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:

/usr/lib/python2.7/dist-packages/RPi

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.

One thought on “HowTo: Adding GPIO to OpenElec running on original series Raspberry Pi (Rev A, B, B+, Zero?)

  • December 16, 2015 at 1:19 pm
    Permalink

    Thanks Barry!

    I have search a lot and didnt find anything that could work with my openelec running on my old rpi 1 with single core. Without normal root previleges to use apt-get and unable to install the addon through GUI, your tutorial help me a lot!

    Regards!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *