Unit-4
Unit-4
Building IOT with RASPERRY PI- IoT Systems - Logical Design using Python –
IoT Physical Devices & Endpoints - IoT Device -Building blocks -Raspberry Pi -
Board - Linux on Raspberry Pi - Raspberry Pi Interfaces -Programming Raspberry
Pi with Python - Other IoT Platforms - Arduino.
Internet of Things
The Internet of Things (IoT) is a scenario in which objects, animals or people are
provided with single identifiers and the capability to automatically transfer and the
capability to automatically transfer data more to a network without requiring human-
to-human or human-to-computer communication. IoT has evolved from the meeting
of wireless technologies, micro-electromechanical systems (MEMS) and the
internet.
1
Five steps are used in web applications
Installing Apache Webserver
Create a My SQL database system
Developed web application For the GUI (Graphical User Interface)
Write lots of PHP, JAVA script, CSS and Python Programs for the Web
Application
Host Web application on our Web server
Raspberry Pi
The history of the Raspberry Pi was basically introduced in 2006. Its main concept
is based on Atmel ATmega644 which is particularly designed for educational use
and intended for Python. A Raspberry Pi is of small size i.e., of a credit-card-sized
single-board computer, which is developed in the United Kingdom(U.K) by a
foundation called Raspberry Pi. The main motto of this foundation is to promote the
teaching of basic computer science in the education institutes and also in developing
countries. The first generation of Raspberry (Pi 1) was released in the year 2012,
which has two types of models namely model A and model B.
2
• It has so-called GPIO pins (General Purpose Input/Output) for connection
sensors and other electronic components like LEDs, etc.
• Raspberry Pi is as well suited for prototyping, datalogging and different
electronics projects, a media center, etc.
• It can be used to learn programming, IT and other technical skills, etc.
• RP has limited power (CPU, RAM, etc.) so it cannot normally replace a
desktop computer or laptop for ordinary use
• The “Hardrive” is a Micro SD card
All models feature on a Broadcom system on a chip (SOC), which includes chip
graphics processing unit GPU(a Video Core IV), an ARM-compatible and CPU. The
CPU speed ranges from 700 MHz to 1.2 GHz for the Pi 3 and onboard memory range
3
from 256 MB to 1 GB RAM. An operating system is stored in the secured digital
SD cards and program memory in either the MicroSDHC or SDHC sizes. Most
boards have one to four USB slots, composite video output, HDMI and a 3.5 mm
phone jack for audio. Some models have WiFi and Bluetooth.
The Raspberry Pi Foundation provides Arch Linux ARM and Debian distributions
for download, and promotes Python as the main programming language, with
support for BBC BASIC, Java, C, Perl, Ruby, PHP, Squeak Smalltalk, C++, etc.
System on Chip
A system on chip is a complex IC that integrates the functional elements into a single
chip or chipset. It is a programmable processor on a chip memory, accelerating
function hardware, software, hardware, and analog components.
Benefits of SoC
Lower power consumption
Reduces size
Reduces overall system cost
Increases performance
4
Internet Gateway Device
Internet Gateway Device has the ability to route data approaching from the WSN
network to the internet and Send data coming from the internet to the WSN network.
It is like a Wi-Fi router for the Internet of Things. In the internet gateway device, we
use raspberry pi model B, it features a quad-core ARM Cortex- A7 CPU is running
at 900MHz (for a 6x presentation improve on the first generation Raspberry Pi
Model B+) and 1GB of LPDDR2 SDRAM (for a 2x memory increase). And yes,
there is total compatibility with Raspberry Pi1 we are secured. Broadcom’s new
SoC, the BCM2836, is the key factor.
Five steps we are using Internet Gateway Device
Port Linux operating system on Raspberry Pi
Modify Linux to work with Our Prototype
Developed Python Library for Communication of RPI with Xbee ZB
Wrote Program from sensors and Device controlling
Create WI-FI functionality on RPI for Internet Connection
WSN Nodes
A wireless sensor network (WSN) consists of three main components: nodes,
gateways, and software. The spatially dispersed measurement nodes interface with
the sensors to monitor assets or their surroundings. The acquired information is
wirelessly transmitted to the gateway, which provides a connection to the wired
globe where you can collect, procedure, analyze, and present your measurement
information using the software. Routers are an individual type of dimension node
that you can use to expand the distance and dependability in a WSN. Sensors can be
dispersed on the roads, vehicles, hospitals, buildings, people and allow dissimilar
applications such as medical services, battlefield operations, disaster response,
disaster relief, and environmental monitoring.
IoT Applications
Weather security and temperature cam
The working doctor who props with raspberry pi
Sensually an air quality monitoring hat
Beer and wine fridge of awesomeness
Raspberry pi Internet doorbell
Internet of things toilet
5
Train your rat behavioral science at home
Pebbly smart doorbell
The raspberry pi microwave
This is all about IoT using Raspberry Pi. Currently, IoT is made up of a loose
collection of different, purpose-built networks. Today’s cars, intended, for example,
have multiple networks to control engine function, safety features, communication
systems, and so on. Commercial and residential buildings also have various control
systems for heating, venting, and air condition (HVAC), telephone service, security,
and lighting.
As IoT evolves, these networks and a lot of others will be connected with additional
security, analytics, and management capabilities. This will allow IoT to become even
more powerful in what it can help people achieve. Furthermore, any queries
regarding this concept or electrical and electronics projects, please give your
valuable suggestions by commenting in the comment section below.
6
Python interpreter executes the program source code directly, statement by
statement, as a processor or scripting engine does.
• Interactive Language
Python provides an interactive mode in which the user can submit commands at
the Python
prompt and interact with the interpreter directly.
Python - Benefits
• Easy-to-learn, read and maintain: Python is a minimalistic language with
relatively few keywords, uses English keywords and has fewer syntactical
constructions as compared to other languages. Reading Python programs feels like
English with pseudo-code like constructs. Python is easy to learn yet an extremely
powerful language for a wide range of applications.
• Object and Procedure Oriented: Python supports both procedure-oriented
programming and object-oriented programming. Procedure oriented paradigm
allows programs to be written around procedures or functions that allow reuse of
code. Procedure oriented paradigm allows programs to be written around objects
that include both data and functionality
• Extendable: Python is an extendable language and allows integration of low-
level modules written in languages such as C/C++. This is useful when you want to
speed up a critical portion of a program.
• Scalable: Due to the minimalistic nature of Python, it provides a manageable
structure for large programs.
• Portable: Since Python is an interpreted language, programmers do not have
to worry about compilation, linking and loading of programs. Python programs can
be directly executed from source
• Broad Library Support: Python has a broad library support and works on
various platforms such as Windows, Linux, Mac, etc.
Python data types and data structures
i) Numbers: Number data type is used to store numeric values. Numbers are
immutable data types, therefore changing the value of a number datatype results in
a newly allocated object.
7
ii) Strings: A string is simply a list of characters in order. There are no limits to
the number of characters you can have in a string.
iii) Lists: List a compound data type used to group together other values. List
items need not all have the same type. A list contains items separated by commas
and enclosed.
iv) Tuples: A tuple is a sequence data type that is similar to the list. A tuple
consists of a number of values separated by commas and enclosed within
parentheses. Unlike lists, the elements of tuples cannot be changed, so tuples can
be thought of as read-only lists.
v) Dictionaries: Dictionary is a mapping data type or a kind of hash table that
maps keys to values. Keys in a dictionary can be of any data type, though numbers
and strings are commonly used for keys. Values in a dictionary can be any data
type or object.
vi) Control Flow:
a) if statement: The if statement in Python is similar to the if statement in other
languages.
b) for statement: The for statement in Python iterates over items of any sequence
(list, string, etc.) in the order in which they appear in the sequence. • This behavior
is different from the for statement in other languages such as C in which an
initialization, incrementing and stopping
c) while statement: The while statement in Python executes the statements within
the while loop as long as the while condition is true.
d) Range statement: The range statement in Python generates a list of numbers in
arithmetic progression.
e) Break and continue statements: The break and continue statements in Python are
similar to the statements in C.
Break • Break statement breaks out of the for/while loop
Continue • Continue statement continues with the next iteration.
f) Pass statement: The pass statement in Python is a null operation. • The pass
statement is used when a statement is required syntactically but you do not want
any command or code to execute.
8
g) Functions: A function is a block of code that takes information in (in the form
of parameters), does some computation, and returns a new piece of information
based on the parameter information. • A function in Python is a block of code that
begins with the keyword def followed by the function name and parentheses. The
function parameters are enclosed within the parenthesis. • The code block within a
function begins after a colon that comes after the parenthesis enclosing the
parameters. • The first statement of the function body can optionally be a
documentation string or doc string.
9
Basic Building Blocks of an IoT Device
Sensing
Sensors can be either on-board the IoT device or attached to the device.
Actuation
IoT devices can have various types of actuators attached that allow actions
to be performed upon the physical entities in the vicinity of the device.
Communication
Communication modules are responsible for sending the collected data to
other devices or cloud-based servers/storage and receiving data from other
devices and commands from remote applications.
Analysis and Processing
Analysis and processing modules are responsible for making sense of the
collected data.
10
Raspberry Pi -Board
Linux on Raspberry Pi
1. Raspbian:
Raspbian Linux is a Debian Wheezy port optimized for Raspberry Pi.
2. Arch:
Arch is an Arch Linux port for AMD devices.
3. Pidora:
Pidora Linux is a Fedora Linux optimized for Raspberry Pi.
4. RaspBMC:
RaspBMC is an XBMC media-center distribution for Raspberry Pi.
5. OpenELEC: OpenELEC is a fast and user-friendly XBMC media-center
distribution.
Raspberry Pi Interfaces
Serial port
• The serial interface on Raspberry Pi has received (Rx) and transmit (Tx) pins for
communication with serial peripherals.
Serial Peripheral Interface (SPI)
Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for
communicating with one or more peripheral devices.
In the SPI connection, there is one master device and One and more peripheral
devices.
There are 5 pins on Raspberry Pi for SPI interface: -
11
MISO (Master in and slave out):- master line for sending data to the peripherals.
MOSI (Master out slave in):- slave line for sending data to the master.
SCK (Serial clock):- clock generated by Master to synchronize data
transmission.
CE0 (Chip enable 0):- to enable or disable the device.
CE0 (Chip enable 1):- to enable or disable the device.
12