IoT Physical Devices and End Points.pdf

7,142 views 41 slides Aug 11, 2023
Slide 1
Slide 1 of 41
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41

About This Presentation

Basic building blocks of an IoT Device
• Exemplary Device: Raspberry Pi
• Raspberry Pi interfaces
• Programming Raspberry Pi with Python
• Other IoT devices


Slide Content

Unit IV
IoTPhysicalDevices&Endpoints

Outline
•Basicbuilding blocksof anIoTDevice
•ExemplaryDevice:RaspberryPi
•RaspberryPi interfaces
•ProgrammingRaspberryPi withPython
•OtherIoTdevices

WhatisanIoTDevice
•A "Thing" in Internet of Things (IoT)canbe anyobjectthathasa
uniqueidentifierandwhichcan send/receivedata(includinguser
data)overa network(e.g., smartphone, smart TV, computer,
refrigerator, car,etc.).
•IoTdevicesareconnectedtotheInternetandsendinformation
aboutthemselvesorabouttheirsurroundings(e.g.information
sensedbytheconnectedsensors)overa network(tootherdevicesor
servers/storage) or allow actuation upon the physical
entities/environmentaround themremotely.

IoTDeviceExamples
•Ahomeautomationdevicethatallowsremotelymonitoringthe
status of appliancesand controllingthe appliances.
•Anindustrialmachinewhichsendsinformationaboutsitsoperation
and health monitoring data toaserver.
•Acarwhichsendsinformationaboutits locationto acloud-based
service.
•Awireless-enabledwearabledevice thatmeasuresdataabouta
personsuchasthenumberofstepswalkedandsendsthedatatoa
cloud-basedservice.

Basicbuilding blocksofan IoT Device
•Sensing
•Sensorscanbeeitheron-boardtheIoTdeviceorattachedtothedevice.
•Actuation
•IoTdevicescanhavevarioustypesofactuatorsattachedthatallowtaking
•actionsuponthephysicalentitiesinthevicinityofthedevice.
•Communication
•Communicationmodulesareresponsibleforsendingcollecteddatatoother
devicesorcloud-basedservers/storageandreceivingdatafromotherdevices
and commandsfromremoteapplications.
•Analysis&Processing
•Analysisandprocessingmodulesareresponsibleformakingsenseofthe
collected data.

Blockdiagram of anIoT Device

ExemplaryDevice:RaspberryPi
•RaspberryPiis a low-costmini-computerwith thephysicalsize ofa
credit card.
•RaspberryPirunsvariousflavorsofLinuxandcanperformalmostall
tasks thatanormaldesktop computer can do.
•RaspberryPialsoallowsinterfacingsensorsandactuatorsthrough
thegeneralpurpose I/O pins.
•SinceRaspberryPirunsLinuxoperatingsystem,itsupportsPython
"out of the box".

ExemplaryDevice:RaspberryPi
•RaspberryPiis a low-costmini-computerwith thephysicalsize ofa
credit card.
•RaspberryPirunsvariousflavorsofLinuxandcanperformalmostall
tasks thatanormaldesktop computer can do.
•RaspberryPialsoallowsinterfacingsensorsandactuatorsthrough
thegeneralpurpose I/O pins.
•SinceRaspberryPirunsLinuxoperatingsystem,itsupportsPython
"out of the box".

RaspberryPi

LinuxonRaspberryPi
•Raspbian
•Raspbian Linuxis aDebianWheezy port optimizedfor RaspberryPi.
•Arch
•ArchisanArchLinux port forAMDdevices.
•Pidora
•PidoraLinuxisaFedora Linuxoptimizedfor RaspberryPi.
•RaspBMC
•RaspBMC isanXBMC media-center distribution for Raspberry Pi.
•OpenELEC
•OpenELECisafastanduser-friendlyXBMCmedia-centerdistribution.
•RISCOS
•RISCOSisaveryfastandcompactoperatingsystem.

RaspberryPiGPIO

RaspberryPiGPIO
WhenusingtheRPi.GPIOlibraryinPythonwehavetocall
importRPi.GPIOasGPIO
andthen
GPIO.setmode(GPIO.BOARD)
or
GPIO.setmode(GPIO.BCM)
Whatisthedifferencebetweenthesetwooptions?

RaspberryPiGPIO
•TheGPIO.BOARDoptionspecifiesthatyouarereferringtothepinsbythenumber
ofthepinontheplug-i.ethenumbersprintedontheboard(e.g.P1)andinthe
middleofthediagramsbelow.
•TheGPIO.BCMoptionmeansthatyouarereferringtothepinsbythe"Broadcom
SOCchannel"number,thesearethenumbersafter"GPIO"inthegreenrectangles
aroundtheoutsideofthebelowdiagrams

RaspberryPiGPIO
•UnfortunatelytheBCMnumberschangedbetweenversionsofthePi1ModelB,and
you'llneedtoworkoutwhichone.SoitmaybesafertousetheBOARDnumbersifyou
aregoingtousemorethanoneRaspberryPiinaproject.
•TheModelB+usesthesamenumberingastheModelBr2.0,andaddsnewpins(board
numbers27-40).
•TheRaspberryPiZero,Pi2B,Pi3B,andPi4BusethesamenumberingastheB+.

RaspberryPiGPIO

RaspberryPiGPIO

RaspberryPiGPIO

RaspberryPiGPIO
•IdentificationofthepinnumberingsviaLinuxcommand
•ThereisaLinuxcommandtofindoutwhichnameisforwhichGPIOpin.Soin
thatcase,wedonothavetoworryaboutatutorialoracheatsheettohaveby
oursidetocheckoutthepinnumberingsoftheRaspberryPiallthetime.
•Type the following command in the terminal,
pinout

RaspberryPiGPIO

RaspberryPiInterfaces

RaspberryPiInterfaces
Serial
•TheserialinterfaceonRaspberryPihasreceive(Rx)andtransmit(Tx)pins
forcommunicationwithserialperipherals.
•GPIO14–UARTTx
•GPIO15–UARTRx

RaspberryPiInterfaces
SerialInterface-UART
•UART(UniversalAsynchronousReceiver/Transmitter)isaserial
communicationprotocolinwhichdataistransferredseriallybitbybit.
•Asynchronousserialcommunicationiswidelyusedforbyteoriented
transmission.
•Inasynchronousserialcommunication,abyteofdataistransferredata
time.

Frame Structure of UART

Raspberry Pi UART

RaspberryPiInterfaces
SPI
•SerialPeripheralInterface(SPI)isasynchronousserialdataprotocolused
forcommunicatingwithoneormoreperipheraldevices.
•In an SPI connection, there is one master device and one or more
peripheral devices.

RaspberryPiInterfaces
•There are five pins on Raspberry Pi for SPI interface.
•MISO (Master In Slave Out) : Master Line for sending data to peripherals (GPIO 9).
•MOSI (Master Out Slave In) : Slave line for sending data to master (GPIO 10).
•SCK (Serial Clock) : Clock generated by master to synchronize data transmission (GPIO
11).
•CEO (Chip Enable 0) : To enable or disable devices (GPIO 8).
•CE1 (Chip Enable 1): To enable or disable devices (GPIO 7).

RaspberryPiInterfaces
I2C(InterIntegratedCircuit)
•Itisasynchronousserialprotocolthatcommunicatesdatabetweentwo
devices
•Itisamasterslaveprotocolwhichmayhaveonemasterormanymaster
andmanyslaveswhereasSPIhasonlyonemaster
•Itisgenerallyusedforcommunicationovershortdistance.

RaspberryPiInterfaces
I2C(InterIntegratedCircuit)
•TheI2CinterfacepinsonRaspberryPiallowstoconnecthardwaremodules.
•I2Cinterfaceallowssynchronousdatatransferwithjusttwopins–
SDA(I2Cdataline)GPIO2andSCL(I2Cclockline)GPIO3.
•ItisusedinmanyapplicationslikereadingRTC(RealTimeClock),assessingexternal
EEPROMmemoryanditisalsousedinsensormoduleslikegyrometerand
magnetometer.

Programming RaspberryPiwith Python
•RaspberryPirunsLinuxandsupportsPythonOutofBoxsoftware.
•Therefore,wecanrunanypythonprogramthatrunsonanormalcomputer.
•GPIOpinsprovidescapabilityonRaspberryPithatmakesusefuldevicesforIoT.
•Awidevarietyofsensorsandactuatorscanbeinterfacedwithraspberrypiusingthe
GPIOpinsandtheSPI,I2Candserialinterfaces.
•Inputfromthesensorsconnectedtoraspberrypicanbeprocessedandvariousactions
canbetaken,sendingdatatoaserver,sendinganemail,triggeringarelayswitch.

RaspberryPiExample:
Interfacing LEDandswitchwithRaspberry Pi
•InthisexampleLEDisconnectedtoGPIOpin18andswitchisconnectedtopin25.
•Intheinfinitewhileloopthevalueofpin25ischeckedandthestateofLEDistoggledif
theswitchispressed.
•ThisexampleshowshowtogetinputfromGPIOpinsandprocesstheinputandtakes
action.
•TheactioninthisexampleistogglingthestateofanLED.

RaspberryPiExample:
Interfacing LEDandswitchwithRaspberry Pi
fromtimeimportsleep
importRPi.GPIOasGPIO
GPIO.setmode(GPIO.BCM)
#SwitchPin
GPIO.setup(25,GPIO.IN)
#LEDPin
GPIO.setup(18,GPIO.OUT)
state=false
deftoggleLED(pin):
state=notstate
GPIO.output(pin,state)
whileTrue:
try:
if(GPIO.input(25)==True):
toggleLED(pin)
sleep(.01)
exceptKeyboardInterrupt:
exit()

Python Program for Sending an Email on Switch Press

Python Program for Sending an Email on Switch Press

Python Program for Sending an Email on Switch Press

Interfacing Light Sensor (LDR) with RPi
•ConnectonesideofLDRto3.3Vandothersidetoa1μFcapacitorandalsotoa
GPIOpin(pin18inthisexample).
•AnLEDisconnectedtopin18whichiscontrolledbasedonthelight-levelsensed.
•ThereadLDR()functionreturnsacountwhichisproportionaltothelightlevel.
•InthisfunctiontheLDRpinissettooutputandlowandthentoinput.

Interfacing Light Sensor (LDR) with RPi
•Atthispointthecapacitorstartschargingthroughtheresistor(andacounteris
started)untiltheinputpinreadshigh(thishappenswhencapacitorvoltage
becomesgreaterthan1.4V).
•Thecounterisstoppedwhentheinputreadshigh.
•Thefinalcountisproportionaltothelightlevelasgreatertheamountoflight,
smalleristheLDRresistanceandgreateristhetimetakentochargethe
capacitor.

Interfacing Light Sensor (LDR) with RPi
import RPi.GPIOas GPIO
import time
GPIO.setmode(GPIO.BCM)
ldr_threshold= 1000
LDR_PIN = 18
LIGHT_PIN = 25
def readLDR(PIN):
reading = 0
GPIO.setup(LIGHT_PIN, GPIO.OUT)
GPIO.output(PIN, false)
time.sleep(0.1)
GPIO.setup(PIN, GPIO.IN)
while (GPIO.input(PIN) ==Flase):
reading=reading+1
return reading
def switchOnLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, True)
def switchOffLight(PIN):
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN, False)
while True:
ldr_reading= readLDR(LDR_PIN)
if ldr_reading< ldr_threshold:
switchOnLight(LIGHT_PIN)
else:
switchOffLight(LIGHT_PIN)
time.sleep(1)

Interfacing Light Sensor (LDR) with RPi

Interfacing Light Sensor (LDR) with RPi

OtherDevices
•pcDuino
•BeagleBoneBlack
•Cubieboard

Comparison of Single Board Mini Computers
Tags