Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 34

Unit II

IoT Physical Devices and Endpoints


Unit II
PART II
• IoT Physical Devices and Endpoints - Introduction
to Raspberry PI, Interfaces (serial, SPI, I2C).
• Programming Raspberry PI with Python
• Controlling LED,
• Interfacing an LED and Switch,
• Interfacing a Light Sensor with Raspberry Pi.
IOT physical Device
• A "Thing" in Internet of Things (IoT) can be any object that has a
unique identifier and which can send/receive data (including user
data) over a network (e.g., smart phone,smart TV, computer,
refrigerator, car, etc. ).
• IoT devices are connected to the Internet and send information about
themselves or about their surroundings (e.g. information sensed by
the connected sensors) over network
Examples
• A home automation device that allows remotely monitoring the
status of appliances and controlling the appliances.
•A car whichsends information about its location to a cloud-based
service.
• A wireless-enabled wearable device that measures data about a
person such as the number of steps walked and sends the data to a
cloud-based service
Basic building blocks of an IoT Device

1. Sensing: Sensors can be either on-board the IoT device or attached to the
device.
2. Actuation: IoT devices can have various types of actuators attached that
allow taking actions upon the physical entities in the vicinity of the device
3. Communication: Communication modules are responsible for sending
collected data to other devices or cloud-based servers/storage and
receiving data from other devices and commands from remote
applications
4. Analysis & Processing: Analysis and processing modules are responsible
for making sense of the collected data.
Introduction to raspberry pi
• Raspberry pi is developed in UK by Raspberry pi foundation to promote
the teaching of basic computer science inschools and developing
countries.
• Raspberry pi is micro processor that can be plugged into a computer.
• It is also called as SOC(System on chip)
• It is similar to general purpose computer.
• It can perform all operations from browsing the internet ,playing high-
definition video, to making spreadsheets, word-processing, and playing
games like compter.
• It runs on its own operating system(Raspbian).
• It supports all operatin systems(windows,ubuntu,firefox os,pidora etc).
• An SD card inserted into the slot on the board to host the operating system.
• Rpi has no internal storage and it does not have hard drive or inbuilt memory
card.we need to insert SD card or memory card.
• The Raspberry Pi is a low cost, credit-card sized computer.
• It is a capable little device that enables people of all ages to explore
computing, and to learn how to program in languages like Scratch and Python.
• Raspberry Pi  has the ability to interact with the outside world.
• It consumes very less power(less than 5W)
How does Raspberry Pi work?

• Raspberry Pi is a programmable device. It comes with all the critical features


of the motherboard in an average computer but without peripherals or
internal storage.
• To set up the Raspberry computer, you will need an SD card inserted into the
provided space.
• The SD card should have the operating system installed and is required for
the computer to boot.
• Raspberry computers are compatible with Linux OS. This reduces the
amount of memory needed and creates an environment for diversity.
• After setting up the OS, one can connect Raspberry Pi to output devices like
computer monitors or a High-Definition Multimedia Interface (HDMI)
television. Input units like mice or keyboards should also be connected 
Raspberry pi 4 B
Raspberry pi Hardware
• A powerful feature of the Raspberry Pi is the row of GPIO (general-
purpose input/output) pins along the top edge of the board.
• Two 5V pins and two 3.3V pins are present on the board, as well as a
number of ground pins (0V), which are unconfigurable.
• The remaining pins are all general purpose 3.3V pins, meaning
outputs are set to 3.3V and inputs are 3.3V-tolerant.
Configuring your Raspberry Pi
Interfaces
Interfaces
• Camera — enable the Raspberry Pi Camera Module
• SSH — allow remote access to your Raspberry Pi from another computer using SSH
• VNC — allow remote access to the Raspberry Pi Desktop from another computer
using VNC
• SPI — enable the SPI GPIO pins
• I2C — enable the I2C GPIO pins
• Serial — enable the Serial (Rx, Tx) GPIO pins
• 1-Wire — enable the 1-Wire GPIO pin
• Remote GPIO — allow access to your Raspberry Pi’s GPIO pins from another
computer
Raspberry Pi Interfaces

• Serial(UART)
• I2C
• SPI
Parallel and serial communication(01000011)
• Raspberry pi has Serial, SPI and I2C interfaces for data transfer.
• Serial(UART) :
• Universal Asynchronous receiver/transmitter
• It is a serial communication protocol in which data is transferred serially i.e
bit by bit.
• Asynchronous communication is widely used for byte oriented transmission
•  The Serial interface on Raspberry Pi has receive (Rx) and transmit (Tx) pins
for communication with serial peripherals.
• Data flows from the Tx pin of the transmitting UART to the Rx pin of the
receiving UART:
• In asynchronous serial communication byte of data is ransferred at a time.
UART Data frame

When the receiving UART detects a


start bit, it starts to read the incoming
bits at a specific frequency known as
the baud rate. Baud rate is a measure
of the speed of data transfer, expressed
in bits per second (bps). Both UARTs
must operate at about the same baud
rate
working
SPI
Serial Peripheral Interface (SPI) is a synchronous serial data protocol
It is a communication protocol used to transfer data between micro
computers like raspberry pi and peripherals(sensors,actuators)
• Devices communicating via SPI are in a master-slave relationship.
• The master is the controlling device (usually a microcontroller), while the slave
(usually a sensor, display, or memory chip) takes instruction from the master.
• The simplest configuration of SPI is a single master, single slave system, but one
master can control more than one slave (more on this below).
• SPI is a synchronous communication protocol that transmits and receives
information simultaneously with high data transfer rates and is designed for board-
level communication over short distances.
SPI
SPI uses 4 separate connections to communicate with target device.
In SPI connection, there are five pins on Raspberry Pi for SPI interface
• MOSI (Master Output/Slave Input) – Line for the master to send data to the slave.
• MISO (Master Input/Slave Output) – Line for the slave to send data to the master.
• SCLK (Clock) – Line for the clock signal.
• The clock signal is generated by the master device to a specific frequency and is used to
synchronize the data being transmitted and received between devices.

• SS/CS (Slave Select/Chip Select) – Line for the master to select which slave to send data to.
• Chip enable 0(ch0)
• Chip enable 1(ch1)
SPI
SPI
• One unique benefit of SPI is the fact that data can be
transferred without interruption. Any number of bits can be sent or
received in a continuous stream.
• With I2C and UART, data is sent in packets, limited to a specific
number of bits. Start and stop conditions define the beginning and
end of each packet, so the data is interrupted during transmission.
I2C

• I2C is short name for Inter integrated circuit.


• I2C combines the best features of SPI and UARTs. With I2C, you can connect multiple slaves to a single
master (like SPI) and you can have multiple masters controlling single, or multiple slaves. This is really useful
when you want to have more than one microcontroller logging data to a single memory card or displaying
text to a single LCD.
• Like UART communication, I2C only uses two wires to transmit data between devices:
• It is a synchronous serial protocol that communicates data between 2 devices
• It is a master slave protocol which may have one or many master or many slaves where as spi has only one
master
• It is generally used for communication over short distances.
• The I2C interface pins on Raspberry Pi allow you to connect hardware modules.
• I2C interface allows synchronous data transfer with just two pins – SDA (data line) an SCL (Clock Line).
• SDA (Serial Data) – The line for the master and slave to send and receive data.
• SCL (Serial Clock) – The line that carries the clock signal.
HOW I2C WORKS

• With I2C, data is transferred in messages. Messages are broken up into frames of data. Each message has
an address frame that contains the binary address of the slave, and one or more data frames that contain
the data being transmitted. The message also includes start and stop conditions, read/write bits, and
ACK/NACK bits between each data frame:
• Start Condition: The SDA line switches from a high voltage level to a low voltage level before the SCL line
switches from high to low.
• Stop Condition: The SDA line switches from a low voltage level to a high voltage level after the SCL line
switches from low to high.
• Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the slave when the master
wants to talk to it.
• Read/Write Bit: A single bit specifying whether the master is sending data to the slave (low voltage level)
or requesting data from it (high voltage level).
• ACK/NACK Bit: Each frame in a message is followed by an acknowledge/no-acknowledge bit. If an address
frame or data frame was successfully received, an ACK bit is returned to the sender from the receiving
device.
I2C message format
Controllin LED

Requirement:s
 Raspberry pi
 LED
 100 ohm resistor
 Bread board
 Jumper cables
Blinking LED (contd..)
Installing GPIO library:
 Open terminal
 Enter the command “sudo apt-get install python-dev” to install
python development
 Enter the command “sudo apt-get install python-rpi.gpio” to install
GPIO library.
Blinking LED (contd..)

Connection:
 Connect the negative terminal
of the LED to the ground pin of
Pi
 Connect the positive terminal
of the LED to the output pin of
Pi
Blinking LED (contd..)
Basic python coding:

 Open terminal enter the command


sudo nano filename.py
 This will open the nano editor where you can write your
code
 Ctrl+O : Writes the code to the file
 Ctrl+X : Exits the editor
LED

• To control an LED connected to GPIO17, you can use this code:


from gpiozero import LED
from time import sleep
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
Blinking LED (contd..)
The LED blinks in a loop with
delay of 1 and 2 seconds.

You might also like