Module-4 RaspberryPi
Module-4 RaspberryPi
with
Python
Pin Configuration of Raspberry Pi 3 Model B
Raspberry Pi Interfaces
1. Serial:
The serial interfaces on Raspberry Pi has receive (Rx) and Transmit (Tx)
pin for communication with serial devices.
2. Serial Peripheral Interface (SPI):
The Serial Peripheral Interface (SPI) is a synchronous serial
communication interface specification used for short distance
communication, primarily in embedded systems.
SPI devices communicate in full duplex mode using a master-slave
architecture with a single master.
The SPI bus can operate with a single master device and with one or
more slave devices.
Raspberry Pi Interfaces
There are five pins on Raspberry Pi for SPI interface.
1. SCLK: (Serial Clock)
Clock generated by Master to synchronize data transmission.
2. MOSI: (Master Output Slave Input)
data output from master device
3. MISO: (Master Input Slave Output)
data output from slave device
4. CE0: (Chip Enable 0)
To enable or disable devices.
5. CE1: (Chip Enable 1)
To enable or disable devices.
Raspberry Pi Interfaces
3. I2C (Inter Integrated Circuit)
Step-1
Include GPIO Library:
RPi.GPIO
Step-2
Use the functions describe in the previous slide.
Circuit diagram for Blinking LED
Blinking LEDs Program
import Rpi.GPIO as GPIO #GPIO Library
import time
GPIO.setmode(GPIO.BCM) #set the pin numbering
GPIO.setup(11,GPIO.OUT) #set GPIO pin 11 as output pin
while True:
GPIO.output(11,True) #Turn on GPIO pin 11
time.sleep(1) #wait for 1 sec
GPIO.output(11,False) #Turn off GPIO pin 11
time.sleep(1) #wait for 1 sec
Controlling LED using Switch
WAP to control an LED connected to GPIO pin 11
with the help of a switch connected to GPIO pin 15
of Raspberry Pi.
(Circuit Diagram)
Controlling LED using Switch
import Rpi.GPIO as GPIO #GPIO Library
import time
GPIO.setmode(GPIO.BCM) #set the pin numbering
GPIO.setup(15,GPIO.IN) #set GPIO pin 15 as input pin
GPIO.setup(11,GPIO.OUT) #set GPIO pin 11 as output pin
while True:
in= GPIO.input(15) #Take switch input from GPIO pin 15
if (in == 0):
GPIO.output(11,1) #Turn on GPIO pin 11
else:
GPIO.output(11,0) #Turn off GPIO pin 11