This post is about explaining how GPIO works on Raspberry Pi
GPIO – General-purpose input/output (GPIO) is a generic pin on an integrated circuit (commonly called a chip) whose behavior (including whether it is an input or output pin) can be controlled (programmed) by the user at run time. –wikipedia
GPIO on Raspberry Pi is 26-pin generic input/output that can be controlled/commanded using most of programming scripts/languages with built-in library to communicate with hardware.
Python GPIO library (RPi.GPIO 0.2) – Download
RPi.GPIO 0.2 is a module to control Raspberry Pi GPIO channels.
Installing GPIO module to Python library
Installation is pretty easy, once you download package you will have “RPi.GPIO-0.2.0.tar.gz” package.
Extract it and install it
cd /tmp sudo wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.2.0.tar.gz sudo tar -zxvf RPi.GPIO-0.2.0.tar.gz cd RPi.GPIO-0.2.0 sudo python setup.py install
After running all the above 5 commands you will have GPIO module installed.
Using GPIO library in Python
import RPi.GPIO as GPIO
GPIO Pins in detail
GPIO usage Sample code
import RPi.GPIO as GPIO # 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, True) # the same script as above but using Raspberry Board GPIO =numbers GPIO.setmode(GPIO.board) GPIO.setup(17, GPIO.IN) GPIO.setup(18, GPIO.OUT) input_value = GPIO.input(17) GPIO.output(18, True)