0% found this document useful (0 votes)
31 views12 pages

Unit-4

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)
31 views12 pages

Unit-4

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/ 12

Unit -IV

BUILDING IoT WITH RASPBERRY PI

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.

Building the Internet of Things (IOT) using Raspberry Pi


The idea wasn’t named until 1999; the Internet of Things has been in development
for decades. The first Internet appliance, for example, was a Coke machine at
Carnegie Melon University in the early 1980s. The programmers might connect to
the machine more to the internet, check the status of the machine and conclude
whether or not there would be a cold drink pending on them, should they decide to
make the trip down to the machine. This article gives an overview of IoT
using Raspberry Pi.

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.

IoT Design Methodology


All web application is developed natively in Java Programming Language. It
includes java technologies similar to JSP, servlets, hibernate, and web services, etc.,
the latest version of net beans IDE is basically used for web application
development. Additional technologies like bootstrap, javascript, jQuery, etc are used
to handle UI and client-side validations. Cisco provided APIs are used to develop
application related to Cisco IP phones.

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.

Raspberry Pi is a tiny (about 9x6cm), low-cost ($35+), single-board computer that


supports embedded Linux operating systems
The recommended Operating System is called Raspberry Pi OS (Linux based)

• The Raspberry Pi is a small computer that can do lots of things


• It has a small footprint (about 9x6cm) and it is cheap ($35+)
• You plug it into a monitor and attach a keyboard and mouse

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

• The first generation (Raspberry Pi 1 Model B) was released in February


2012. It was followed by a simpler and inexpensive model Model A.
• In 2014, the foundation released a board with an improved design in
Raspberry Pi 1 Model B+. These boards are approximately credit-card sized
and represent the standard mainline form-factor.
Raspberry Pi can be plugged into a TV, computer monitor, and it uses a standard
keyboard and mouse. It is user-friendly as it can be handled by all the age groups. It
does everything you would expect a desktop computer to do like word-processing,
browsing the internet spreadsheets, playing games to playing high definition videos.
It is used in many applications like in a wide array of digital maker projects, music
machines, parent detectors to the weather station and tweeting birdhouses with
infrared cameras.

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.

The following are essential to get started


 Video cable to suit the TV or monitor used
 SD card containing Linux Operating system
 Power supply (see Section 1.6 below)
 USB keyboard
 TV or monitor (with DVI, HDMI, Composite or SCART input)

Recommended optional extras include


 Internet connection, Model B only: LAN (Ethernet) cable
 USB mouse
 Powered USB hub
 Internet connection, Model A or B: USB WiFi adaptor

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.

Logical Design using Python


The logical design of using Python in IoT is easy enough to develop from the
standpoint of an IoT system architecture. Using modern frameworks for IoT and
modern protocols for transferring data from devices, you can effectively build
high-performing IoT systems.
Python is a general-purpose high level programming language and suitable for
providing a solid foundation to the reader in the area of cloud computing.
Python characteristics
• Multi-paradigm programming language
Python supports more than one programming paradigms including object-oriented
programming and structured programming
• Interpreted Language
Python is an interpreted language and does not require an explicit compilation
step. The

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.

IoT Physical Devices & Endpoints


IoT 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
a network (to other devices or servers/storage) or allow actuation upon the physical
entities/environment around them remotely.
IoT Device Examples
A home automation device that allows remotely monitoring the status of appliances
and controlling the appliances.
• An industrial machine which sends information about its operation and health
monitoring data to a server.
• A car which sends 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.

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.

Inter-Integrated Circuit (I2C)


 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) and SCL (clock line).
Serial Data (SDA) – Transfer of data takes place through this pin.
Serial Clock (SCL) – It carries the clock signal.

Programming Raspberry Pi with Python


Interfacing LED and switch with Raspberry Pi
from time import sleep
import RPi.GPIO as GPIO GPIO.set mode(GPIO.BCM)
#Switch Pin GPIO.setup(25,GPIO.IN)
#LED Pin
GPIO.setup(18, GPIO.OUT)
state=false
def toggle LED(pin):
state = not state GPIO.output(pin, state)
while True:
try:
if (GPIO.input(25) ==True):
toggle LED(pin) sleep (.01)
except Keyboard Interrupt:
exit ()

Other IoT Platforms


1. pcDuino
2. Beagle Boneblack
3. Cubieboard

12

You might also like