Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

UNIT 4

SHORT ANSWERS:

1. Write short on Raspberry Pi Features?


Ans:

 Raspberry Pi is a small single board computer. By connecting peripherals like Keyboard,


mouse, display to the Raspberry Pi, it will act as a mini personal computer.
 Raspberry Pi is popularly used for real time Image/Video Processing; IoT based
applications and Robotics applications.
 Raspberry Pi is slower than laptop or desktop but is still a computer which can provide all
the expected features or abilities, at low power consumption.
 Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they
provide NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS
like Ubuntu, Archlinux, RISC OS, Windows 10 IOT Core, etc.
 Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi.

2. Write a Short note on Raspberry Pi Pin number declaration?


Ans:

Pin Numbering Declaration

After including the RPi.GPIO module, the next step is to determine which of the two pin-
numbering schemes 

• 1. GPIO.BOARD : Board numbering scheme. The pin numbers follow the pin numbers
on header P1.

 2. GPIO.BCM : Broadcom chip-specific pin numbers. These pin numbers follow the
lower-level numbering system defined by the Raspberry Pi's Broadcom-chip brain.

• To specify in your code which number-system is being used, use


the GPIO.setmode() function.

Example:

GPIO.setmode(GPIO.BCM)# will activate the Broadcom-chip specific pin numbers.

Note: Both the import and setmode lines of code are required, if you want to use Python.


3. Write short notes on Raspberry Pi PIN mode configuration.

Setting a Pin Mode:

• In Raspberry Pi to set a pin mode, use the 

GPIO.setup(pin number, pinmode) function.

• Example: if you want to set pin 18 as an output, write:

• GPIO.setup(18, GPIO.OUT)

GPIO.setmode(GPIO.BCM); Using pins BCM numbers

Basic Commands

• GPIO.setup(pin, GPIO.IN); Determines the pin as input

• GPIO.setup( pin, GPIO.OUT); Determines the pin as an output

• GPIO.input(pin): Reading input pin

• GPIO.output( pin, state): Writing on the output pin.

4. Write short notes on Light Dependent Resistor (LDR)

Ans: Light Dependent Resistor (LDR)

 A photoresistor (also known as a light-dependent resistor, LDR, or photo-conductive cell)


is a passive component that decreases resistance with respect to receiving luminosity
(light) on the component's sensitive surface.
 The resistance of a photoresistor decreases with increase in incident light intensity.
 It exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector
circuits and light-activated and dark-activated switching circuits acting as a
resistance semiconductor. In the dark, a photoresistor can have a resistance as high as
several megaohms (MΩ), while in the light, a photoresistor can have a resistance as low
as a few hundred ohms.

LDR Symbol
5: write short notes on Raspberry Pi audio & Video Outputs:
Ans:
HDMI Output: The HDMI port on Raspberry Pi provides both video and audio output. We can
connect the Raspberry Pi to a monitor using an HDMI cable. For monitors that have a
DVI(Digital Video interface) port but no HDMI port, we can use an HDMI to DVI adapter/cable.

Composite Video Output: Raspberry Pi comes with a composite video output with an RCA jack
that supports both PAL and NTSC video output. The RCA jack can be used to connect old
televisions that have an RCA input only.

LONG ANSWERS:

1. Explain implementation of IoT by using DHT22 Sensor?


OR

Explain socket programming to implement IoT with Raspberry Pi?

Ans:

 IoT can be implemented with Raspberry Pi using Socket Program

Sockets?

 Sockets are the endpoints of a bidirectional communications channel. Sockets


may communicate within a process, between processes on the same machine,
or between processes on different continents.
 Sockets may be implemented over a number of different channel types: Unix
domain sockets, TCP, UDP, and so on. The socket library provides specific
classes for handling the common transports as well as a generic interface for
handling the rest.
Socket Programming:
 Creates a two-way communication between two nodes in a network
 The nodes are termed as Server and Client

Creating a socket:
s = socket.socket (SocketFamily, SocketType, Protocol=0)
 SocketFamily can be AF_UNIX or AF_INET
 SocketType can be SOCK_STREAM or SOCK_DGRAM
 Protocol is set default to 0
DHT22: Digital Humidity Temperature sensor

 The DHT-22 (also named as AM2302) is a digital-output relative humidity and


temperature sensor. It uses a capacitive humidity sensor and a thermistor to measure the
surrounding air, and spits out a digital signal on the data pin.

PRE REQUISTE library Installations:

1. Before we get started with programming a script for the Raspberry Pi humidity sensor, we must first
ensure that we have the latest updates on our Raspberry Pi.

We can do this by running the following two commands to update both the package list and installed
packages.

2. Now using pip, we will go ahead and install Adafruit’s DHT library to the Raspberry Pi.

We will be using this Python library to interact with our DHT22 Humidity/Temperature sensor.

As a bonus, the library also supports the DHT11 and AM2302 humidity/temperature sensors
making it a great library to learn how to utilize.

Run the following command to install the DHT library to your Raspberry Pi.
CODE:

Server Program

 import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ("192.168.0.2",2000)
sock.bind(server_address)
while True:
data,address = sock.recvfrom(4096)
with open("Datalog.txt","a") as f:
mess=str(data)
f.write(mess)
print(mess)
f.close()

Client Program:

import socket
import sys
import RPi.GPIO as GPIO
from time import sleep
import Adafruit_DHT

def sensordata():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Sensor=Adafruit_DHT.DHT22
humidity, temperature = Adafruit_DHT.read_retry(Sensor,4)
return(humidity, temperature)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #create UDP socket


server_address = ("192.168.43.234",2000)
try:
while (1):
h,t = sensordata()
message = str(h)+','+str(t)
#Send data
print (sys.stderr, 'sending "%s"' % message)
sent = sock.sendto(message.encode(), server_address)
finally:
print (sys.stderr, 'closing socket')
sock.close()
OUTPUT:

SERVER Receiving Data:

Client Sending Data:


2. Explain about Raspberry Pi interfaces UART,I2C?

Ans:

Raspberry Pi UART Communication

Introduction

UART (Universal Asynchronous Receiver/Transmitter) is a serial communication


protocol in which data is transferred serially i.e. bit by bit. Asynchronous serial
communication is widely used for byte oriented transmission. In Asynchronous
serial communication, a byte of data is transferred at a time.

UART serial communication protocol uses a defined frame structure for their data
bytes. Frame structure in Asynchronous communication consists:

 START bit: It is a bit with which indicates that serial communication has
started and it is always low.
 Data bits packet: Data bits can be packets of 5 to 9 bits. Normally we use 8-
bit data packet, which is always sent after the START bit.
 STOP bit: This usually is one or two bits in length. It is sent after data bits
packet to indicate the end of frame. Stop bit is always logic high.

Usually, an asynchronous serial communication frame consists of a START bit (1 bit)


followed by a data byte (8 bits) and then a STOP bit (1 bit), which forms a 10-bit
frame as shown in the figure above. The frame can also consist of 2 STOP bits
instead of a single bit, and there can also be a PARITY bit after the STOP bit.

Raspberry Pi UART

Raspberry Pi has two in-built UART which are as follows:


 PL011 UART
 mini UART

PL011 UART is an ARM based UART. This UART has better throughput


than mini UART.

In Raspberry Pi 3, mini UART is used for Linux console output whereas PL011 is
connected to the On-board Bluetooth module.

And in the other versions of Raspberry Pi, PL011 is used for Linux console output.

Mini UART uses the frequency which is linked to the core frequency of GPU. So as
the GPU core frequency changes, the frequency of UART will also change which in
turn will change the baud rate for UART. This makes the mini UART unstable which
may lead to data loss or corruption. To make mini UART stable, fix the core
frequency. mini UART doesn’t have parity support.

The PL011 is a stable and high performance UART. For better and effective
communication use PL011 UART instead of mini UART.

I2C:Introduction

 I2C (Inter Integrated Circuit) is a synchronous serial protocol that


communicates data between two devices.
 It is a master-slave protocol which may have one master or many master and
many slaves whereas SPI has only one master.
 It is generally used for communication over short distance.
 The I2C device has 7-bit or 10-bit unique address. So, to access these devices,
master should address them by the 7-bit or 10-bit unique address.
 I2C is used in many applications like reading RTC (Real time clock), accessing
external EEPROM memory. It is also used in sensor modules like gyro,
magnetometer etc.
 It is also called as Two Wire Interface (TWI) protocol.
Raspberry Pi I2C

 Raspberry Pi has Broadcom processor having Broadcom Serial Controller


(BSC) which is a master, fast-mode (400Kb/s) BSC controller. The BSC bus is
compliant with the Philips I2C bus.
 It supports both 7-bit and 10-bit addressing.
 It also has BSC2 master which is dedicatedly used with HDMI interface and
should not be accessed by user.
 I2C bus/interface is used to communicate with the external devices like RTC,
MPU6050, Magnetometer, etc with only 2 lines. We can connect more devices
using I2C interface if their addresses are different.

STEPS OF I2C DATA TRANSMISSION

1. The master sends the start condition to every connected slave by switching the SDA line
from a high voltage level to a low voltage level before switching the SCL line from high to
low:
2. The master sends each slave the 7 or 10 bit address of the slave it wants to communicate
with, along with the read/write bit:
3. Each slave compares the address sent from the master to its own address. If the
address matches, the slave returns an ACK bit by pulling the SDA line low for one bit.
If the address from the master does not match the slave’s own address, SDA line
high.
4. The master sends or receives the data frame:

5. After each data frame has been transferred, the receiving device returns another ACK bit
to the sender to acknowledge successful receipt of the frame:

6. To stop the data transmission, the master sends a stop condition to the slave by switching
SCL high before switching SDA high:

3. Explain the interfacing of an LED with Raspberry Pi neat Schematic diagram and
implement the same using Python programming.

Ans:

Interfacing LED with Raspberry Pi

LED:
 The LED is a special type of diode and they have similar electrical characteristics
to a PN junction diode. Hence the LED allows the flow of current in the forward
direction and blocks the current in the reverse direction.
LED Symbol
 The LED symbol is similar to a diode symbol except for two small arrows that
specify the emission of light, thus it is called LED (light-emitting diode). The LED
includes two terminals namely anode (+) and the cathode (-). The LED symbol is
shown below.

Figure:LED Symbol

Figure: Interfacing
LED with Raspberry Pi Connections
EXAMPLE 1: LED ON/OFF

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18,GPIO.OUT)

while True:

GPIO.output(18,True)

time.sleep(2)

GPIO.output(18,False)

time.sleep(2)

OUTPUT:

Figure: Led OFF

Figure: Led ON

4. Explain in detail Interfacing PUSH BUTTON SWITCH & LED with Raspberry Pi
Ans: Interfacing PUSH BUTTON SWITCH & LED with Raspberry Pi.

Push Button is simplest of devices and it is the basic input device that can be connected to any
controller or processor like Arduino or Raspberry Pi.A push button in its simplest form consists
of four terminals. In that, terminals 1 and 2 are internally connected with each other and so are
terminals 3 and 4. So, even though you have four terminals, technically, you have only two
terminals to use.

Figure: Interfacing PUSH BUTTON SWITCH & LED with Raspberry Pi.

Example:

import RPi.GPIO as GPIO

import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.OUT)

GPIO.setup(4,GPIO.IN)

# input of the switch will change the state of the LED

while True:
GPIO.output(18,GPIO.input(4))

time.sleep(0.05)

OUTPUT:

Figure 1: LED ON When Switch is PRESSED

Figure 2: LED OFF When Switch is released

5. Draw the basic Architecture of Raspberry Pi and list out spefications:

Ans: What is Raspberry Pi?


It is basically micro sized computer or commonly in common terms it is said as a computer in
your palm more specifically it is a single board computer which is very low cost device and
which is very easy to access.

 Raspberry pi compared to Arduino is more powerful, it is more powerful in terms of the


computation or processing power.
 Additionally it has better memory capacity and also it can integrate different types of
sensors and actuators and this part is more attractive than compared to the similar kind of
feature of Arduino.
 We can have different types of sensors integration in Raspberry pi and due to the feature
that it can process more compared to Arduino it has better processing capabilities and
more features and so on.
 We can configure Raspberry pi as a web server, as an edge device and so on.

This is the basic functional architecture of a raspberry pi. The center you have a CPU or GPU
you have various input output ports connected to it you have a RAM you have a USB hub from
which you can connect an Ethernet as well as you have various USB ports to which you can
connect regular USB devices.

You might also like