Controlling Input and Output Pins:
The Raspberry Pi2
is designed with a 40-pin connector that can be controlled by software.
The 40-pin
header is made-up of many general purpose input and output(GPIO) pins.
Below is the
complete pin diagram of Raspberry Pi2 GPIO Header.
Lessons learnt form chapter:
·
Electronic circuits: Closed circuit, Open
circuit, Short Circuit.
·
Current in a circuit, Voltage around the
circuit, Resistance of the circuit.
·
Light emitting diode (LED)
·
Breadboard and its layout, connection of
raspberry pi to breadboard.
·
GPIO Header:
pin numbers and their configuration.
·
GPIO pin as basic output.
·
GPIO pin as basic input.
·
Pull-up and Pull-down resistors.
My Experiments:
1. Using Pi as power supply to LED:
Things Needed:
· R-Pi
· 40
pin GPIO Ribbon Cable with T-Shaped Breakout Board/ female to male wires
· Power
Supply
· LED
· Resistor
(330 ohms)
·
Jumper wires
Process:
First connected the
GPIO header to T-Shaped Breakout Board using the 40 pin female to female GPIO
Ribbon Cable. Next inserted the T-Shaped Breakout Board on the breadboard with
the pins on either side of the center division on the breadboard. Instead of
female to female to GPIO Ribbon Cable with T-Shaped Breakout Board, can also
use female to male wires directly. Connected a wire from pin1 of the GPIO
header with 3.3 V to anode (+ve terminal) of the LED. Other end of LED is
connected to resistor. The other end of the resistor is connected to GND (any
GND pin of GPIO header). The circuit connection is completed.
Switched on
Power supply to Pi, LED turned ON.
2. Controlling GPIO2 Pin as Basic Output:
Things Needed:
· R-Pi
· 40
pin GPIO Ribbon Cable with T-Shaped Breakout Board/ female to male wires
· Power
Supply
· LED
· Resistor
(330 ohms)
·
Jumper wires
Process:
The
pin3 or the GPIO2 pin of Pi can be used as the Input/Output.
The
functionality of the pin is controlled by python program. Before that in order
to test the functionality first modified the above circuit by simply connected
the anode of LED to the GPIO2 pin instead of the 3.3V pin. Then switched on the
power supply and executed the below python program from terminal. The LED is
now blinking.
Program:
import
RPi.GPIO
import
time
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.setup(2,RPi.GPIO.OUT)
while
True:
RPi.GPIO.output(2, True) # RPi.GPIO.output(2,
RPi.GPIO.HIGH)
time.sleep(1)
RPi.GPIO.output(2, False)
#RPi.GPIO.output(2, RPi.GPIO.LOW)
time.sleep(1)
Wrote the program, to make the LED glow for 1 second then stop. This is because, alternatively made the GPIO2 pin high and low.
Done varies experiments by different series and parallel connection and also used different I/O pins for the experiments.
Experiment Results:
The I/O pins of Pi can be used as basic output source.
With different Combinations of the input like serial and parallel connection LED brightness varied due to different voltages in different connection.
In parallel connection all the LED glow with same brightness and vice versa in series due to varied voltages.
3. Controlling GPIO2 Pin as Basic Input:
Things Needed:
· R-Pi
· 40
pin GPIO Ribbon Cable with T-Shaped Breakout Board/ female to male wires
· Power
Supply
· LED
· Resistor
(330 ohms)
· Jumper
wires
·
Momentary Push Button
Process:
The pin3 or the
GPIO2 pin of Pi can be used as the Input/Output.
The
functionality of the pin is controlled by python program. Before that in order
to test the functionality first need to construct the circuit as below.
Connected the VCC point to pin1 for power supply and resistance from it and
other end to GPIO2 pin. Then connected the Button between GPIO2 and GND.
Program:
import RPi.GPIO
import time
RPi.GPIO.setmode(RPi.GPIO.BCM)
RPi.GPIO.setup(2,RPi.GPIO.IN,pull_up_down=RPi.GPIO.PUD_UP)
while True:
if RPi.GPIO.input(2) == RPi.GPIO.LOW:
print("switch pressed.")
break
RPi.GPIO.cleanup()
Wrote the program, to check the GPIO2 pin value. When switch pressed the GPIO2 pin gets low and release its high again.
Experiment Results:
The I/O pins of Pi can be used as basic input source. Tested the experiment by using LED too.
In this case used the internal resistance of the pi too.