Configuring GPIO

The GPIO pins can be used as both digital outputs and digital inputs. As digital outputs, you can write programs that turn a particular pin HIGH or LOW. Setting it HIGH sets it to 3.3V setting it LOW sets it to 0V. To drive an LED from one of these pins, you need a 1kΩ resistor in series with the LED as the GPIO pins can only manage a small amount of power.

If you use a pin as a digital input, then you can connect switches and simple sensors to a pin and then be able to check whether it is open or closed (that is, activated or not)

Some Adafruit projects that use just GPIO.

To program the GPIO ports in Python, we need to install a very useful Python 2 library called Rpi.GPIO. This module gives us a simple to use Python library that will let us control the GPIO pins.

The installation process for this is the same whether you are using Raspbian or Occidentalis. In actual fact, some versions of Raspbian include this library, but these instructions will also have the effect of updating to the latest version, which is worth doing.

sudo apt-get update

To install RPi.GPIO, you first need to install the Python Development toolkit that RPi.GPIO requires.

To do this enter the following command into LXTerminal:

sudo apt-get install python-dev

Then to install Rpi.GPIO itself type:

sudo apt-get install python-rpi.gpio

You will probably be prompted to confirm by entering 'Y'.

Thats all there is to it. You are ready to try some of the projects I mentioned at the top of this section.

Last updated on 2015-05-04 at 04.27.11 PM Published on 2012-12-14 at 09.28.57 AM