IOT Unit IV
IOT Unit IV
As deseribedearlier, a"Thing" in Internet of Things (loT) can be any object that has aunigipe
icdentitier and which cansend/receive data (including user data) over a network (e.g. sman
phone, smart TV, computer, refrigerator, car, etc. ). loT devices are connected to the Intermet
and send informationabout themselves or about their surroundings (e.g. information sensed
by the connected sensors) over a network (to other devices or servers/storage) or allow
cluation upon the physical entities/environment around them remotely. Some examples of
loT devices are listed below:
" Ahome automation device that allows remotely monitoring the status of appliances
and controlling the appliances.
" An industrial machine which sends information abouts its operation and health
monitoring data to a server.
A car which sends information about its location to a cloud-based service.
" Awireless-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.
this book are just as applicable to other (including proprietary) loT endpoints, in addition to
Raspberry Pi. Before we look at the specifics of Raspberry Pi, let us first look at the building
blocks ofageneric single-board computer (SBC) based loT device.
Figure 7.1 shows a generic block diagram of a single-board computer (SBC) based
IoT device that includes CPU, GPU, RAM, storage and various types of interfaces and
peripherals.
RCA video
UART SD NAND/NOR
SPI MMC DDR1/DDR2/DDR3
12C SDIO
CAN
Figure 7. shows the Raspbery Pi board with the various components/peripherals labeled.
" Processor &RAMl: Raspbemy Pi is based on an ARM processor. The latest version of
Raspbery Pi (Model B. Revision 2) comes with 700 MHz Low Power ARMI176JZ-F
prvessor and 512 MBSDRAM.
" USB Ports : Raspbery Pi comes with two USB 2.0 ports. The USB ports on
Raspbery
Pican provide a current upto l00mA. For connecting devices that draw current more
than 100mA,an extermal USB powered hub is required.
" Ethernet Ports : Raspberry Pi comes with a standard RJ45
Ethernet port. You can
connect an Ethernet cable or a USB Wii adapter to provide Internet connectivity.
" HDMI Output : The HDMl port on Raspberry Pi
provides both video and audio
output. You can connect the Raspberry Pi to a monitor using an HDMl cable. For
monitors that have a DVI port but no HDMI port. you can use an HDMI to DVI
adapter/cable.
" Composite Video Output: Raspberry Picomes with a composite video output with
an RCA jack that supports both PAL and NTSCvideo
used to connect old televisions that have an RCA
output. The RCA jack can be
input
Audio Output : Raspberry Pi has a 3.5mm audio outputonly. jack. This audio jack is used
for providing audio output to old televisions along with the
audioquality from this jack is inferior to the HDMI RCA jack for video. The
" GPIO Pins: Raspberry Pi comes output.
with a number of general purpose
Figure 7.3 shows the Raspbery Pi GPIO headers. inputouput pins.
There are four types
Raspberry Pi - true GPIO pins, 12C interface pins, SPl interface pins and of pins on
Tx pins. serial Rx and
" Display Serial Interface (DSI) :The DSI interface can be
panel to Raspberry Pi. used to connect an LCD
Camera Serial Interface (CSI):The CSI
module to Raspberry Pi. interface can be used to connect a camert
" Status LEDs: Raspberry Pi has
five status LEDs. Table 7.1 lists
LEDs and their functions. Raspberry Pi status
"SD Card Slot:
Raspberry Pidoes not have a built in operating system and
You can plug-in an SD card loaded
withaLinux image to the SD card slot. storaye
provides instructions on setting up New Out-of-the-Box Appendix-A
Raspberry Pi. You willrequire atleast an 8GB SD card for Software (NOOBS) on
. Power Input : Raspberry Pi has a setting up NOOBS.
micro-USB connector for power input.
Bahga &Madisetti, O 201
7.4 Linuxon Raspberry Pi 181
12111
DSIConnector
Display
USB 2.0
SD Card
Slot
Ethernet
Micro USB
Power nUn
CSI Connector
HDMI
Camera
3V3
GPIO 4
GPIO 14 (UART TXD)
GPIO 17 GPIO 18
GPIO 27 GROUND
GPIO 22 GPIO 23
3V3 GPIO 24
Detiar Serachi
Peferes
hon Berves
1
Pafere e
Ss
oCR
Mlor
DLE
NSTcotOReia 31
NONE_URL="http://.ra spbian.org/
sUPPORT_URL=*http://.respbian.org/RaspbianForums"
BUG REPORT_URLhttp:/Iw. raspbian.org /Raspb ian Bugs*
PRETTYy NANE=Deb ian 0SNAME 7 (hee2y }e
NANE= Deb ian 0SNAME
VERSION_ID
heey*
JANSI_COLORI 31®
HNE URL=*http:l/w.debian,org/*
sUPPORT URL=http://w.debian ,org/support /
BUC REPORT_URL=httg//ugs.debian .org7*
ey
or disable SSH server and change boot behavior. It is recommended to expand the root
file-systemso that you can use the entire space on the SD card.
Though Raspberry Pi comeswith an HDMIoutput, it is more convenient to access the
device with a VNC connection or SSH. This does away with the need for a separate display
for Raspbery Pi and you can use Raspberry Pi from your desktop or laptop computer.
Appendix-A provides instructions on setting up VNC server on Raspberry Pi and the
instructions to connect to Raspberry Pi with SSH. Table 7.2 lists the frequently used
commands on Raspberry Pi.
Command Function Example
cd Change directory cd home/pi
cat Show file contents cat file.txt
Pvd
Print name of present working pwd
directory
mkdir Make directory mkdir /home/pi/new
mv sourceFile.txt destinationFile.txt
mv Move (rename) file
Remove file rm file.txt
sudo reboot
reboot Reboot device
sudo shutdown -h now
shutdown Shutdown device
grep Print lines matching apattern grep -r "pi" home/
df Report file system disk space df -Th
usage
ifconfig Configure a network interface ifconfig
Print network connections, netstat -lntp
netstat
routing tables, interface statistics
tar Extract/create archive tar -xzf foo.tar.gZ
Non-interactive network wget http:/lexample.com/file.tar.gz
wget
downloader
7.5.2 SPI
Serial Peripheral Interface (SPI) is a synchronous serial data protocol used for communicating
with one or more peripheral devices. In an SPI connection, there is one master device and
one or more peripheral devices. There are five pins on Raspberry Pi for SPI interface:
" MISO (Master In 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 devices.
" CE0(Chip Enable 1): To enable or disable devices.
7.5.3 I2C
The I2C interface pins on Raspberry Piallow you to connect hardware modules. I2C interface
allows synchronous data transfer with just two pins - SDA (data line) and SCL (clock line).
he LED on/off from command line. In this example the LED is connected to GPIO pin 18.
You can connect the LED to any other GPIO pin as well.
Box 7.2 shows a Python program for blinking an LED Connected to Raspberry Pi every
second. The program uses the RPi. GPIO module to control the GPIO on Raspberry Pi. In
this program we set pin 18direction tooutput and then write TruelFalse alternatively after a
delay of one second.
GND
27GND
Model
(R2) B
A,GND
GND
GPIO
ETHERNET
OK
PUR
USB 2x FDX
RLNK
L0M
GPIO.setmode (GPIO.BCM)
GPIO.setup (18, GPIO.OUT )
while True:
GPIO.output (18, True)
time.sleep (1)
GPIO.output (18, False)
time.sleep (1)
#Switch Pin
GPIO. Setup (25, GPIo.IN)
#LED Pin
GPIO.Ssetup (18, GPIO.OUT)
state=false
while True:
try:
if (GPIO. input (25) == True):
toggleLED (pin)
sleep (.01)
except KeyboardInterrupt:
exit ()
GNDC
GPIO
Video-0ut
(V83UY) IS)
ETHERNET
ROK
PWR
uSB 2x FDX
LNK
L0M
press
Box 7.4: Python program for sending an email on switch
import smtplib
from t ime import sleep
import RPi.GPIO as GPIO
from sys import exit
from_email = <my-email>
receipient s_list = ('<receipient-email>']
cc_list = )
subject = Hello
message = ' Switch pressed on Raspberry Pi!
username <Gmail-username>
passwOrd = <password> !
Server = smtp. gmail.com:587'
while True:
try:
if (GPIO. input (25) == True):
sendemail (from_email, receipients_list,
cc_list, subject, message,
username, password, server)
sleep(.01)
except KeyboardInterrupt :
exit ()
Box 7.5: Python program for switching LEDLight based on reading LDR reading
import RPi.GPIO as GPIO
import time
while True:
ldr_reading = readLDR (LDR_PIN)
if ldr_reading < ldr_threshold:
switchOnLight (LIGHT_PIN)
else:
switchoffLight (LIGHT_PIN)
time.sleep (1)
1 1
5V
DSI (DISPLAY)
GND
GND
127GND
avaTe
GNDC
GPIO
vWUY) IS)
ETHERNET
OK
PUR
USA 2 FDX
LNK
LOM
Bahga &Madiseti,
7.7Other loT Devices 193
N
012/121
A10
H-1
U3
SSTM-5
94V.0
A4335x
et
C.
LINK-PP
HOMI
7.7.1 pcDuino
pcDuino
1 GHz . [105] is an Arduino-pin compatible single board mini-computer that comes with a
ARM Cortex-A8
processor. pcDuino is a high performance and cost effective device
nernet of Things - A
Hands-On Approach
loT Physical Devices &
194 Endpoints
that runs PC like OS such as Ubuntu and Android ICS. Like, Raspberry Pi, it has an
HDMI
video/audio interface. pcDuino supports various programming languages including C. Ct+
(with GNUtool chain). Java (with standard Android SDK) and Python.
BeagleBone Black[ 106] is similar to Raspberry Pi, but a more powerful device. It
with a 1GHz ARM Cortex-A8 processor and comes
supports both Linux and
systems. Like Raspbery Pi, it has HDMIvideo/audio interface, USB Android operaiis
and Ethernet ports
7.7.3 Cubieboard
Summary
o this chapter you learned about
Raspberry Pi which is a low-cost mini-computer. Raspberry
Pi supports various flavors of Linux
operating
evstem is Raspbian Linux. RaspberTy Pihas ansystem. The official recommended operating
ARM processor, 512MB RAM, two USB
norts, HDMI, RCA and audio outputs, Ethernet port, SD card slot
and DSI and CSI interfaces.
Raspberry Pi has serial, SPl and 12C interfaces for data transfer.
Python. You learned how to develop Pythonprograms that run on Raspberry Pi supports
how to interface LED, Switch and LDR with Raspberry Pi. You learned
Raspberry Pi.
Review Questions
1. How is Raspberry Pidifferent from a desktop
2. What is the use of GPIO pins?
computer?
3. What is the use of SPI and I2C interfaces on Raspberry Pi?
196 loT Physical Devices &Endpoints
BeagleBone
Raspherry Pi pcDuino Black Cubieboard
700 MHz ARM AM335x 1GHz Dual core 1GHZ
1GHZ
CPU ARMI176JZ-F ARM Cortex-A8 ARM Cortex-A7
Cortex A8
Processor
Dual Core
VideoCore IV PowerVR Dual core ARM
GPU Mali 400 SGX530 Mali 400 MP2
Multimedia
Co-Processor
512MB IGB 512MB 1GB
Memory
2GB Flash 2GB on-board
4GB NAND Flash
Storage (ATmega328) flash storage
10/100M 10/100M 10/100M 10/100M Ethernet
Networking Ethernet Ethernet Ethernet
2 USB, SD, 2 USB, MicroSD
4+1 USB. slot, SATA, IR
Input/Output MMC, SDIO
MicroSD slot
card slot sensor
96 extend
interface.
pin
69 pin GPIO,
SPI, I2C, 4 including I2C.
Serial, ADC,
GPIO, SPI, I2C, serial, CAN, SPI, RGB/LVDS.
Interfaces
serial
PWM, GPIO, FM-IN.
I2C, SPI GPMC, AIN, CSI/TS.
ADC, CVBS, VGA.
MMC, XDMA
SPDIF-OUT, R-TP
Rasbian, Pidora,
Ubuntu, Angstrom Linux, Android, Officia
OS RISC OS, Arch Android
Linux distribution
Android, Ubuntu
Linux
HDMI,
Video Composite HDMI HDMI HDMI
RCA (PAL and
NTSC)
3.5mm jack, HDMI
Audio HDMI HDMI
HDMI
5VDCI700mA 5VDCI2A
Power 5V/2A 5VDC/460mA