0% found this document useful (0 votes)
110 views

Module-4 RaspberryPi

This document discusses the pin configurations and interfaces of the Raspberry Pi 3 Model B including serial, SPI, and I2C interfaces. It provides details on the functions of pins used for each interface. It also provides Python code examples to blink an LED connected to a Raspberry Pi GPIO pin and control an LED using a switch connected to another GPIO pin.

Uploaded by

Rajesh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Module-4 RaspberryPi

This document discusses the pin configurations and interfaces of the Raspberry Pi 3 Model B including serial, SPI, and I2C interfaces. It provides details on the functions of pins used for each interface. It also provides Python code examples to blink an LED connected to a Raspberry Pi GPIO pin and control an LED using a switch connected to another GPIO pin.

Uploaded by

Rajesh Panda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Raspberry Pi

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)

I2C is a serial protocol for two-wire interface to connect low-


speed devices like microcontrollers, EEPROMs, A/D and D/A
converters, I/O interfaces and other similar peripherals in
embedded systems.
It was invented by Philips.
In Raspberry Pi I2C is supported by two pins: SDA (data line)
and SCL (clock line)
Some of the Functions for
interacting with Raspberry Pi
1. import Rpi.GPIO as GPIO ---> GPIO Library
2. GPIO.setmode(GPIO.BCM) --->set the pin numbering
3. GPIO.setup(pinno,GPIO.OUT/GPIO.IN) --->set GPIO pin 11 as output pin
4. GPIO.output(Pinno,value) --->To turn a GPIO pin on/off
 GPIO.output(11,True) #Turn on GPIO pin 11
 GPIO.output(12,1) #Turn on GPIO pin 12
 GPIO.output(11,False) #Turn off GPIO pin 11
5. GPIO.input (pinno) --->To read status of a GPIO pin
 in=GPIO.input(15) #Read status of GPIO pin 15 and store it to in
variable
6. time.sleep(time in sec) #delay/wait for 1 sec
Blinking LEDs
WAP to blink an LED connected to GPIO pin 11 of
Raspberry Pi.

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

You might also like