Install RPi.GPIO Library In Raspbian

The RPi.GPIO Python library allows you to easily configure and read-write the input/output pins on the Pi’s GPIO header within a Python script. In order to use it you need to install the package as this isn’t usually included in SD card images.

First of all Install Python Development Software.
Python development software is worth installing as there are many examples on the internet using this language for the Raspberry Pi

Enter the following at the command line
Follow the prompts to download and install the python package

sudo apt-get install python-dev

Step 1 – Download the library

wget http://raspberry-gpio-python.googlecode.com/files/python-rpi.gpio_0.3.1a-1_armhf.deb

Step 2 – Install the library

sudo dpkg -i python-rpi.gpio_0.3.1a-1_armhf.deb

Example Usage
Copy the following script into a text file called “gpio_test.py” :

import RPi.GPIO as GPIO

# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

# set up the GPIO channels - one input and one output
GPIO.setup(11, GPIO.IN)
GPIO.setup(12, GPIO.OUT)

# input from pin 11
input_value = GPIO.input(11)

# output to pin 12
GPIO.output(12, GPIO.HIGH)

# the same script as above but using BCM GPIO 00..nn numbers
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.OUT)
input_value = GPIO.input(17)
GPIO.output(18, GPIO.HIGH)

To run this script you can use the following command :

sudo python gpio_test.py

You need to include “sudo” in front of this command as the GPIO library requires root privileges.

About these ads

3 thoughts on “Install RPi.GPIO Library In Raspbian

  1. Hey There. I found your blog using msn. This is an extremely well written article.
    I will be sure to bookmark it and come back to read more of your useful info.
    Thanks for the post. I’ll definitely return.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s