Unit V - IoT
Unit V
Raspberry Pi
Basics
· Raspberry Pi is one of the best smaller
computing boards available in the market.
· It could be used for a
variety of applications like creating simple digital documents, learning programming, gaming, developing a temperature sensor,
as a learning tool for the visually impaired or augmented
reality systems
· This is what the
Raspberry Pi is.
· It is a single
board computer, measuring 85.60
mm × 56 mm × 21 mm, with its own ARM processor, RAM, several other
ports and peripherals and GPIO (general-purpose input−output) pins that facilitate the
connection of electronic components (Fig. A2.1).
· Raspberry Pi was first
released in the year 2012.
Architecture
·
The
first-generation Raspberry Pi uses Broadcom BCM2835 SoC (System on Chip)
hardware, while the second-generation comes with BCM2836
·
Figure A2.3 depicts top view of Raspberry Pi.
Figure A2.3 Top view of Raspberry Pi indicating the components.
The components are described as follows:
1. The Processor:
·
All the models of the first generation make use of a 32-bit, 700
MHz, single core chip that uses the ARM11 architecture.
·
Raspberry Pi 2, has a much improved
processor. It works with a 32-bit, 900 MHz, quad core ARM Cortex-A7.
·
This processor is based on ARM v7-A architecture.
·
The quad core processor of the second generation helps in increasing the speed by four times than that of the original generation.
·
The SDRAM used has been upgraded in each model.
·
The first-generation model A
uses
a 256 MB RAM, while in model B and B+ it is 512 MB. The second generation
has a 1 GB RAM.
2. USB 2.0 Ports:
·
Raspberry
Pi model A has one single USB port, while model B has
2 USB ports.
·
Raspberry Pi model B+ and Raspberry Pi 2
have four separate USB ports.
·
All devices also have a 5 V micro USB in addition.
·
Using the USB 2.0 ports, we could plug in a keyboard and a mouse
to interact with Raspberry Pi.
3. Ethernet Port:
·
Except model A, all other models are built
with a 10/100 RJ45 Ethernet port.
·
10/100 signifies that the devices are
compatible with the speeds 10 Mbps and 100 Mbps, respectively. I
·
t is also possible to access the Internet
using model A by connecting a Wi-Fi dongle into one of its USB ports.
·
Ability of the Raspberry Pi to access the
Internet is a great feature that facilitates it to be used in several smart
system designs.
4. SD Card Slot:
·
None of the Raspberry Pi models have a hard disk for memory storage.
·
There is a memory card slot into which the user can insert the
memory card.
·
Raspberry
Pi models A and B are compatible with SD (Secure
Digital) card, MMC (Multi Media Card) and SDIO (Secure
Digital Input Output) card.
·
The memory card is
loaded with the OS for Raspberry Pi. (Refer to Fig. A2.4 to have a look at the bottom view of the kit.)
Figure A2.4 Bottom view of Raspberry Pi indicating SD card slot.
5. Analog Audio
Output:
·
All the models of Raspberry Pi produce an
analog audio output through a 3.5 mm audio jack provided on the device board.
·
Digital audio output is also provided
by the Raspberry Pi through
an HDMI port.
6. Composite Video Output:
·
Analog video signal without the audio is
called as composite video.
·
The composite video output from Raspberry Pi
complies with PAL (Phase Altering Line) and NTSC (National Television System
Committee) standards.
·
PAL and NTSC provide certain resolution and
broadcast color standards for analog video
transmission.
·
The resolution of the composite video output is lesser than that of the HDMI output.
7. HDMI Port:
·
An HDMI (High Definition Multimedia
Interface) port in all Raspberry Pi models helps in providing a visual output
on a monitor or a TV screen and also in providing a digital audio output.
·
This could be brought about by the use of appropriate HDMI connectors, which maybe with HDMI to DVI (Digital Visual Interface) or HDMI
to VGA (Video Graphics Array).
·
The HDMI port in Raspberry Pi can provide
14 different resolutions.
·
To connect
the HDMI port to an analog TV, HDMI to RCA cables could be used which
are presented in Fig. A2.5.
8. Status LEDs:
• Raspberry Pi is
equipped with a set of five different LEDs that indicate the status
of the device to the user, regarding
the power supply,
network connectiv- ity, etc.
• ACT (Green)
– ON when SD card
is accessed.
• PWR (Red) – ON when there is 3.3 V power supply.
• FDX (Green) – ON for full duplex LAN.
• LNK (Green) – ON when there is network (LAN) activity.
• 100 (Yellow) – ON for 100 Mbps network connection.
9. Power Supply: In
all the models of Raspberry Pi, there
is a 5 V micro USB port through which
the device can be powered.
• Raspberry Pi 2 – 4.0 W
10.
GPIO
Pins:
·
The set of GPIO (general purpose
input−output) pins on the device makes Raspberry Pi different from regular
computers.
· These
pins could be connected to electrical and electronic components.
·
When Raspberry Pi is connected
to the Internet, it is
possible for the user to control the connected components from anywhere.
Compatible Peripherals, Add-Ons,
and Accessories
1. Power Supply Cable:
· It might seem that a
mobile phone charger, consisting of a typical USB to micro USB cable, would be sufficient to power Raspberry
Pi.
· When
Raspberry Pi is not fed with sufficient power, it will fail to function well.
2. SD Card:
· Generally, SD cards with class 4 speed are
recommended for use with Raspberry Pi.
· High-speed
SD cards with poor stability do not function well with Raspberry Pi.
· A
memory of at least 4 GB is required.
3. Camera Module:
·
A camera module
could be directly
connected to Raspberry Pi.
·
The camera
module when connected to Raspberry
Pi could be used for special effects
applications like slow motion video and time lapse video, apart from taking normal photographs and videos.
·
The camera
module
is similar to those available on mobile phones. (Figure A2.6 shows the camera
module for Raspberry Pi.)
Figure A2.6 Camera module for Raspberry Pi and camera module
connected to CSI port.
4. LCD Display:
·
To connect LCD display boards or OLED screens to Raspberry Pi, there is
a special connector called DSI (Digital Serial Interface) connector.
·
Connection is facilitated by a 15 pin flat
ribbon cable.
5. Real Time Clock:
·
Raspberry Pi does not have any built-in real-time clock in it.
·
When the user is connected to the Internet, it uses the date and
time information through the online sources.
·
However, when Raspberry Pi is operates
as a standalone system,
without accessing the Internet, different
arrangements have to be made for the device to be fed with time.
·
When operated under normal conditions, Raspberry Pi does not get heated up
as it is meant for mobile applications
·
When overclocking is done, a heatsink may have to be added.
·
Overclocking is the process of running the
processor at a speed higher than the one intended by the manufacturer.
·
The overclocking options could be enabled
by a certain command line.
·
The system continues to function at the increased
speed until the temperature exceeds 85oC.
· At this point, overclocking is automatically disabled by Raspberry Pi.
Operating System for Raspberry Pi
Before understanding the operating systems supported by Raspberry Pi, let us get acquaint- ed
with NOOBS (New Out Of the Box Software) which
makes the OS installation process in the SD card of Raspberry
Pi a simpler process.
NOOBS is an exclusive install
manager for OS installation in Raspberry Pi.
NOOBS can be downloaded
as a torrent or zip file from http://www.raspberrypi.org/ downloads/.
There are two versions of
NOOBS – NOOBS and NOOBS LITE.
The former offers offline
and network download
while the latter offers only network download.
SD cards pre-installed with NOOBS are also available. After downloading NOOBS,
extracting the required folders and installing it in the SD card, the SD
card could be inserted into the SD
card slot of Raspberry Pi.
In Raspberry Pi provided
with power supply and plugged in with a keyboard and mouse, inserting an SD
card will initialize the booting process. A
window listing out the different operating systems compatible with Raspberry Pi would appear (see Fig. A2.8). NOOBS is extremely useful for beginners as
it helps in easy OS installation without configuration process. Experienced
users could also download OS without using NOOBS.
The different operating systems that could be installed using NOOBS are:
1. Raspbian
2. OpenELEC
3. Pidora
4. RaspBMC
5. RISC OS
6. Arch Linux ARM
All the above-mentioned operating systems make use of Linux kernel.
·
Raspbian is the most common operating
system used with Raspberry Pi and is the most recommended one. Raspbian is the Debian operating system specifically designed for use with Raspberry Pi. Pidora is the Fedora
Remix for Raspberry
Pi. OpenELEC (Open
Embedded Linux Entertainment Center) is based on Kodi (XBMC earlier) software.
Figure A2.8 NOOBS window showing OS choices available.
Setting up Raspberry Pi
Follow the instructions given
below to set up your Raspberry Pi before you configure it or
before it gets booted up. Figure A2.9 depicts a set up Raspberry Pi.
1. Insert the SD card installed with NOOBS into the SD card slot of Raspberry
Pi. An 8 GB SD card is
recommended.
2. You will require a display screen
like a TV or monitor
to work with Raspberry Pi.
o Connecting
your chosen display unit to Raspberry Pi via the HDMI port would give better
display results.
o If
the display unit is old and is not compatible with the HDMI port, then there is an alternative video output
port available (RCA port or TRRS port).
Figure A2.9 Raspberry Pi connected to various peripherals.
3.
To control Raspberry Pi and provide
inputs to the device and give commands, you must connect a keyboard and a mouse to Raspberry Pi through
its USB ports.
4. Connect the micro USB of the Raspberry Pi to a 5 V power supply.
Ensure that the device gets the required
current; else the device might be underpowered.
5. If
you require Internet access when working with Raspberry Pi, connect it to the
Ethernet cable via the Ethernet . Internet
access is possible using a Wi-Fi
dongle and connecting it to a USB port.
6. Headphones
or powered speakers could be plugged into the audio output port for sound. When there is no audio
equipment in the display device,
then the audio
output port could be made use
of.
In the
above set of instructions, steps from 1 to 4 are necessary if the user wants to
work with Raspberry Pi. Steps 5 and 6 are optional.
Initial Configuration for Raspberry Pi
Raspberry Pi configuration tool (Fig. A2.10) is called as “Raspi-Config”. The configuration menu offers the
following options:
Figure A2.10 The Raspi-C
1. Expand File System:
Using NOOBS to install OS automatically expands
the file system. File system enables the installed files to
occupy entire SD card, thus making the entire SD card available for Raspberry Pi.
2. Change User Password: The default username
is “pi” and the default
password is “raspberry”. This
option allows to change the password.
3. Enable Boot to Desktop/Scratch: This option helps
the user to decide what he/she
wants after booting takes place,
that is, if the device should boot into the desktop or command line or Scratch.
4. Internationalization Options: Selecting this option and pressing enter key
provides the following setting options to the user:
a. Change locale.
b. Change time zone.
c. Change keyboard
layout.
5. Enable Camera: This
option should be selected if the user would like to use the camera module.
6. Add to Rastrack: Rastrack
is a Google-Map based application developed which indicates all Raspberry
Pi users on a heat map based on their location. Selecting this option
adds the user to the map.
7. Overclock: Selecting this option lets the user to use the processor at a speed higher than its processor speed.
Advanced
Options
1. Overscan: When we enable overscan a black border around the screen is
formed, so that none of the initial
text leaves the screen. If overscan is not enabled,
the entire image
is made to fit the entire screen and better resolution is obtained.
2. Hostname:
This option enables
the user to assign a name to his/her device (Raspberry Pi) for identification when connecting to
the Internet.
3. Memory Split: This option helps the user to fix the RAM memory to be allowed
for the GPU for graphics and multimedia.
4. SSH (Secure Shell): It
helps in accessing the command line of Raspberry Pi from another computer, when connected to the Internet.
5. Device Tree: It
allows for effective management of allocation of resources and auto-configuration of certain modules.
6. SPI: This configuration
option helps to enable or disable the SPI (Serial Peripheral Interface) bus and
related kernel modules from loading automatically.
7. I2C: This configuration
option helps to enable or disable the I2C (Inter-IC) bus and related kernel
modules from loading automatically.
8. Serial: This option helps to enable or disable the messages from kernel and shell on the serial connection.
9. Audio: This menu in the configuration window
helps to select either the HDMI port or
analog audio output port.
10.
Update: This option enables
or disables updates
to latest version.
At the end of the
configuration process, a message appears asking if the system should reboot.
There are some configuration settings which when enabled or disabled would
require a system reboot for them to be applied.
If the user wants to
access the configuration tool, Raspi-Config, after the first booting, the
instruction to be typed in the command line is
sudo raspi-config
When in the command line, graphical interface can be accessed using
the command startx.
Shutting Down Raspberry Pi
Raspberry Pi has no specific power button on the device. So, different
shutdown schemes for the graphical desktop environment and the command prompt environment have been developed.
When
using graphical interface, shutdown option can be selected
from the logout menu on the desktop.
With command
prompt, the following
command works for shutdown:
sudo shutdown –h now
Indiscriminately disconnecting the power chord is not advisable. This might even corrupt
the SD card.
Linux Based Softwares
in Raspberry Pi
The following are the Linux based software
available in Raspberry
Pi.
1. The File Manager (found in Accessories menu).
2. Midori (Web browser).
3. Omxplayer
(Video and Audio).
4. Leafpad, Nano (Text editors).
Table A2.1 presents the features of various Raspberry Pi versions
available in the market along with the cost.
|
Table A2.1 Summary of Raspberry – Pi kits
and corresponding features |
||||
|
Pi Zero |
Pi 1 Model A+ |
Pi 1 Model B+ |
Pi 2 Model B |
Pi 3 Model B |
|
1 GHz 32-bit Single Core processor |
700 MHz 32-bit Single Core processor |
700 MHz 32-bit Single Core processor |
900 MHz
32-bit Quad Core processor |
1.2 GHz
64-bit Quad Core processor |
|
512
MB RAM |
512 MB RAM |
512 MB RAM |
1 GB RAM |
1 GB RAM |
|
Broadcom VideoCore IV GPU |
Broadcom VideoCore IV GPU |
Broadcom VideoCore IV GPU |
Broadcom VideoCore IV GPU |
Broadcom VideoCore IV GPU |
|
Table A2.1 Summary of Raspberry – Pi kits
and corresponding features—Continued |
||||
|
Pi Zero |
Pi 1 Model A+ |
Pi 1 Model B+ |
Pi 2 Model B |
Pi 3 Model B |
|
2 micro USB ports |
1 micro USB ports |
1 micro USB ports |
1 micro USB ports |
1 micro USB ports |
|
No USB ports |
1
USB ports |
4
USB ports |
4
USB ports |
4
USB ports |
|
1 mini HDMI port, no HDMI |
1 HDMI port,
no mini HDMI |
1 HDMI port,
no mini HDMI |
1 HDMI port,
no mini HDMI |
1 HDMI port,
no mini HDMI |
|
1 microSD
slot |
1 SD/MMC
slot |
1 microSD
slot |
1 microSD
slot |
1 microSD
slot |
|
No dedicated
audio port |
3.5 mm audio out port |
3.5 mm audio out port |
3.5 mm audio out port |
3.5 mm audio out port |
|
No Wi-Fi,
No Ethernet |
No Wi-Fi,
No Ethernet |
No Wi-Fi,
Ethernet via USB Adapter |
No Wi-Fi,
Ethernet via USB Adapter |
Onboard Wi-Fi Ethernet port |
|
No Bluetooth |
No Bluetooth |
No Bluetooth |
No Bluetooth |
Bluetooth 4.1 |
|
65 ´ 30 mm (Half of Standard Pi Size) |
85.60 ´ 56.6 mm (Standard Pi Size) |
85.60 ´ 56.5 mm (Standard Pi Size) |
85.60 ´ 56.6 mm (Standard Pi Size) |
85.60 ´ 56.6 mm (Standard Pi Size) |
|
$5 |
$20 |
$25 |
$35 |
$35 |
Application Development
with Raspberry-Pi
– A
Quick Walk
Through
Like most of the boards, Python is supported programming option with
Raspberry – Pi too.
Raspberry Pi provides an excellent environment for learning Python
as well as executing
real-time applications using
Python. Raspberry Pi has the Python development application IDLE.
The main goal of the
Raspberry Pi Foundation was to make programming a fundamental part of regular
computing. Visual programming is
another interesting attribute of Rasp- berry
Pi. Raspberry Pi offers Scratch as a visual programming platform. It can be used to create animations and games
without actually writing a code. Figure A2.11 shows the Scratch window.
Figure A2.11 Scratch Window.
A2.8.1 Application − Web Lamp
This application demonstrates the use of the
GPIO pins and how devices connected to Rasp- berry Pi can be controlled over the Internet. This application uses Python and Flask. Flask is a web framework which
helps in tweaking Raspberry Pi into a dynamic web server. Here, Flask is used with Python libraries to make the web server more functional. This application will require a Raspberry Pi board, breadboard, power switch tail II relay,
female to male jumper wires and hookup wires.
Hardware Setup: Using hookup wires,
the “+in” terminal
of the power switch tail is connect- ed to pin 25 of Raspberry Pi and
the “−in” terminal is connected to the ground bus of the Raspberry Pi. A lamp is plugged into the power switch
tail. A second AC equipment could
also be controlled along with the lamp by using another power switch tail and
connecting it to pin 24.
In the home directory, create a new directory and name it “WEBlamp”. In this directory cre- ate
a file “weblamp.py” and in this file enter the following source code:
Pins = {
24 : {‘name’:‘fan’, ‘state’
: GPIO.LOW},
25 : {‘name’:‘lamp’, ‘state’
: GPIO.LOW}
}
for pin in pins:
GPIO.setup(pin,
GPIO.OUT( GPIO.output(pin, GPIO.LOW(
@app.route(“/”( def main((:
for pin in
pins:
pins[pin][‘state’] = GPIO.input(pin( templateData = {
‘pins’ : pins
}
return render_template(‘main.html’,**templateData(
@app.route(“/<changePin>/<action>”(
def action(changePin, action(:
changePin = int(changePin( deviceName = pins[changePin][‘name’]
if action == “on”:
GPIO.output(changePin, GPIO.HIGH( message = “Turned” + deviceName + “on.”
if action == “off”:
GPIO.output(changePin, GPIO.LOW(
message = “Turned”
+ deviceName + “off.”
if action == “toggle”:
GPIO.output(changePin, not GPIO.input(changePin(( message = “Toggled”
+ deviceName + “.”
for pin in pins:
pins[pin][‘state’] = GPIO.input(pin(
templateData = {
‘message’ : message, ‘pins’ : pins
}
return render_template(‘main.html’,
**templateData(
if _name_ == “_main_”:
app.run(host=’0.0.0.0’, port=80,
debug=True(
Now, create a directory within “WEBlamp” and name it “templates”. Inside this
directory, create the file “main.html” and enter the following source code in it.
In
the terminal, go to directory
WEBlamp and then start server
after ensuring all other
Flask servers are killed using ctrl+c. Use
the command line:
pi@raspberrypi ~/WEBlamp $ sudo python
weblamp.py
This application helps to control devices when away from home by staying connected via the Internet.







Comments
Post a Comment