RPi.GPIO

Just a quicky… An easier way than this/ to access the Raspberry Pi GPIO pins.

The Python module RPi.GPIO should be installed by default on Raspbian so go ahead and create a new Python script from LXTerminal (just so everyone knows, I am a fan of SSH):
nano gpio.py

Paste in:
import RPi.GPIO as GPIO
print GPIO.VERSION

Save it (CRTL+X then y)
Execute it with:
sudo python gpio.py
You should see a version number printed out in your terminal!
Then connect the long leg (positive) of a LED to pin 3 on your Pi and the other leg (negative) to ping 6 (gnd) – use this layout to work out your pin numberings.

Put in:
import RPi.GPIO as GPIO
from time import sleep
print GPIO.VERSION
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3,GPIO.OUT)

GPIO.output(3, True)
sleep(1)
GPIO.output(3, False)
sleep(1)
print "done"

What happens?

Advertisements

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