0% found this document useful (0 votes)
17 views

07 - Raspberry Pi

The document discusses implementing a Raspberry Pi computer as an IIoT module. It provides an overview of the Raspberry Pi architecture and functions, describes its variants, and discusses connecting sensors to the Raspberry Pi GPIO pins for programming and algorithm development to realize an IIoT application.

Uploaded by

manthanstd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

07 - Raspberry Pi

The document discusses implementing a Raspberry Pi computer as an IIoT module. It provides an overview of the Raspberry Pi architecture and functions, describes its variants, and discusses connecting sensors to the Raspberry Pi GPIO pins for programming and algorithm development to realize an IIoT application.

Uploaded by

manthanstd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Vishwakarma Government Engineering College

Department of Instrumentation and Control Engineering

PRACTICAL NO: 07

AIM: -To Implement Raspberry Pie Computer as IIoT Module

OBJECTIVES:
1. Overview of architecture and functions of Raspberry Pie Computer.

2. Variants of Raspberry Pie

3. Programming and algorithm development

4. Implementation of Raspberry Pie computer with available sensors as IIoT

Introduction
One of the buzzwords used heavily in the Automation and IT industry for the past couple of years is the
term IoT, which stands for Internet of Things. IoT refers to all of the things that are, well, connected to
the Internet, and that's how it got its name. With the maker movement which comes a host of DIY-Do it
itself) electronic platforms, IoT hardware developed.

Fig-1: Arduino and Raspberry PI board like DIY-Do it itself hardware.

64 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
IoT boards, also known as development boards or prototyping boards are basically hardware platforms
that are commonly used to build prototypes of manufacturer’s ideas. There’s a wide variety available
hardware and one can choose from between microcontroller-based boards, Single-Board Computers
(SBC) or even cellular-enabled IoT boards.

DIY electronic platform gifted us two main development boards such as Arduino and Raspberry Pi.
Arduino is a small and inexpensive electronic board that allows us to connect to various external
accessories such as sensors and create applications to use the data collected.
Another open-source hardware platform that has gotten very popular with hobbyists these days is
Raspberry Pi.

What is Raspberry Pi?


The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV,
and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to
explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of
doing everything you’d expect a desktop computer to do, from browsing the internet and playing high-
definition video, to making spreadsheets, word-processing, and playing games.
What’s more, the Raspberry Pi has the ability to interact with the outside world, and has been used in a
wide array of digital maker projects, from music machines and parent detectors to weather stations and
tweeting birdhouses with infra-red cameras. We want to see the Raspberry Pi being used by kids all
over the world to learn to program and understand how computers work.

1. Overview of architecture and functions of Raspberry Pie Computer.

The Raspberry Pi contains CPU (Central Processing Unit), RAM (Random Access Memory) or GPU
(Graphics Processing Unit) as a whole called System on Chip (SoC) unit. This is essentially the entire
computer on one chip.

The Raspberry Pi uses an ARM1176JZF-S 700MHz CPU which is also installed in a wide variety of
mobile phones, hand held games consoles and e-Readers. This CPU is single core, however it does
have a co-processor to perform floating point calculations. Many calculations required by a program
involve whole numbers (integers). These are easier for the CPU to handle. Integer calculations produce

65 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering

accurate results. Floating point or real numbers have a fractional part e.g. 1.5. They are more
demanding for the CPU to process.

Fig-2: Functional schematic of Raspberry Pi Board

2. Variants of Raspberry Pi:

Model B

The very first version of the Raspberry Pi created a big splash in the small single-board computers
(SBC) market. This device was both small, competent, and affordable. This version of the Raspberry Pi
set the baseline for its size for all future Pi devices. However, a couple of things you will notice are
quite different compared to the more modern Pi’s.

Model A

In February 2013, the Raspberry Pi model A was launched; it packed the same ARM single-core
processor and the GPU as model B with half of the RAM capacity at 256MB. Priced at Rs.40000 per
unit, the model A could be regarded as the cheaper and less powerful version of model B

66 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering

Fig-3: Variants of Raspberry Pi Boards

Fig-4: Variants of Raspberry Pi Boards

Raspberry Pi 3
Raspberry Pi 3 is the third generation of Raspberry Pi and it packs quite a formidable punch in its credit
card-sized package. Most notably, in addition to the standard features of the Raspberry Pi (such as four
USB 2.0 ports and built-in Ethernet), it has:
 A 1.2GHz 64-bit quad-core ARMv8 CPU

67 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
 802.11n Wireless LAN
 Bluetooth 4.1 Low Energy (BLE)
The powerful CPU coupled with Wireless LAN and Bluetooth 4.1 radio makes it an ideal candidate for
IoT projects, because multiple sensors can be connected to it simultaneously. In addition, the Raspberry
Pi has a 40-pin GPIO (General Purpose I/O) connector for interfacing with external sensors.
Powering the Raspberry Pi
One of the most popular OSs used for the Raspberry Pi is the Raspbian Operating system. The
Raspbian OS is based on the Debian OS, optimized for the Raspberry Pi hardware. The easiest way to
install the Raspbian OS for the Raspberry Pi is to download NOOBS from
https://www.raspberrypi.org/help/noobs-setup/.
NOOBS stands for New Out Of Box Software. The Raspbian OS boots off a micro-SD card and the
entire operating system runs off the card. A typical Class 4 8GB micro-SD card is sufficient for most
purposes, but you have the option to connect it to an external hard disk or flash drive for more storage.
Once the Raspbian OS is installed, you can proceed to log into it and see a full windowed system as
shown in figure -5. The default username is pi and the password is raspberry.

Fig-5: The Raspbian OS uses the LXDE (Lightweight X11 Desktop Environment)

68 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering

Connecting the Raspberry Pi to the Outside World - GPIO Pins


The Raspberry Pi has a 40-pin GPIO (General Purpose Input/output) connection, which makes it very
easy to connect to the outside world. To connect the GPIO to external sensors, we can:
Connect the sensors directly to the GPIO pins using jumper wires.
Connect the GPIO pins to a ribbon cable, which in turn connects it to a breadboard. The
Adafruit Pi T- Cobbler Plus - Breakout + Cable for Raspberry Pi A+/B+/Pi 2/Pi 3 (Figure-7) is
one such product.

Fig-7: Connecting the Adafruit Pi T-Cobbler Plus


Fig-6:The Raspberry Pi 40-pin GPIO
to the Raspberry Pi

The GPIO pins on the Raspberry Pi are divided into the following groups:
 Power: Pins that are labeled 5.0v supply 5 volts of power and those labeled 3V3 supply 3.3 volts of
power. There are two 5V pins and two 3V3 pins.
 GND: These are the ground pins. There are eight ground pins.
 Input/Output pins: These are the pins labeled with the # sign, for example, #17, #27, #22, etc.
These pins can be used for input or output.
 I2C: I2C is a serial protocol for a two-wire interface to connect low-speed devices like
microcontrollers, EEPROMs, A/D and D/A converters, I/O interfaces, and other similar peripherals
in embedded systems. These pins are labeled SDA and SCL.
 UART: The Universal Asynchronous Receiver/Transmitter allows your Raspberry Pi to be
connected to serial peripherals. The UART pins are labeled TXD and RXD.

69 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
 SPI: The Serial Peripheral Interface is a synchronous serial communication interface specification
used for short distance communication, primarily in embedded systems. The SPI pins are
labeled MOSI, MISO, SCLK, CE0, and CE1.
 ID EEPROM: Electrically Erasable Programmable Read-Only Memory is a user-modifiable read-
only memory that can be erased and written to repeatedly through the application of higher than
normal electrical voltage. The two EEPROM pins on the Raspberry Pi (EED and EEC) are also
secondary I2C ports that primarily facilitate the identification of Pi Plates (e.g., Raspberry Pi
Shields/Add-On Boards) that are directly attached to the Raspberry Pi.

3. Programming and algorithm development


This first stage is to implement the raspberry Pi board to sensor application and second stage is
programming and software development.
Connecting to a Sensor to Detect Motion

To demonstrate how to use the GPIO to connect to an external sensor, we'll now use a PIR motion
sensor to detect motion. For this, we use the Parallax PIR Motion Sensor (see Figure 9). The PIR
Sensor detects motion by measuring changes in the infrared (heat) levels emitted by surrounding
objects of up to three meters.

Fig-8:The Parallax PIR Motion Sensor Fig-9: A PIR Motion sensor connected to the
Raspberry Pi

70 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering

The Parallax Motion sensor has three pins (see Figure-8):

 GND: The ground pin. Connect this pin to the GND on the GPIO.
 VCC: The voltage pin. Connect this pin to one of the 5V pins on the GPIO.
 OUT: The output pin. Connect this to one of the Input/output pins on the GPIO.

When the PIR Motion sensor detects motion, it outputs a high signal on its output pin. We need to write
an application to read the value of this output pin. Figure-11 shows a PIR Motion sensor connected to
the T-Cobbler Plus.
Bonding the Raspberry Pi and the Sensors: The Python Programming Language
Now that the Raspberry Pi is connected to the PIR Motion Sensor, it's time to write the code to make
things work. In the Raspbian OS, Python is a first-class citizen, and the support for Python comes right
out of the box. With its clean syntax and ease of learning, Python is a first choice for hobbyists and
beginners to foray into the world of the Raspberry Pi. Coupled with the huge community support for
Python, it's no wonder that it's the language of choice for developers.

$ nano motiondetection.py
The above command uses the NANO text editor and creates a file named motiondetection.py . Enter the

statements as shown in Listing 1.


Listing 1. Source code for using a PIR Motion Sensor
import RPi.GPIO as GPIO #1

import time #2

pirsensor = 4 #3

GPIO.setmode(GPIO.BCM) #4

GPIO.setup(pirsensor, GPIO.IN, GPIO.PUD_DOWN) #5

previous_state = False #6

current_state = False

71 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
while True: #7

time.sleep(0.1) #8

previous_state = current_state #9

current_state = GPIO.input(pirsensor) #10

if current_state != previous_state: #11

if current_state: #12

print("Motion Detected!") #13

When you are finished typing in the code, exit the NANO editor by pressing Ctrl-X and then
pressing Y to save the file. Press Enter to save it to the current directory. To run the Python script, type
the following command in Terminal:

$ python motiondetection.py
Wave your hand in front of the PIR Motion Sensor. We should see the following output on Terminal:

Motion Detected!

Dissecting the Code


Now that we have written your first Python code, it's useful to understand what it does and how it
works. We'll dissect the code line-by-line:
The RPI.GPIO is a library that allows your Python application to easily access the GPIO pins on your
Raspberry Pi.
#1: The latest version of Raspbian includes the RPI.GPIO Python library pre-installed, so you can
simply import that into your Python code. The RPI.GPIO library allows your Python application to
easily access the GPIO pins on your Raspberry Pi. The as keyword in Python allows you to refer to the

RPI.GPIO library using the shorter name of GPIO.


#2: The application is going to insert some delays in the execution, so you need to import the time
module.
#3: You declare a variable named pirsensor to indicate the pin number for which the Output pin on the

PIR sensor is connected to the GPIO pin. In this example, it's GPIO pin #4.
#4: There are two ways to refer to the pins on the GPIO: either by physical pin numbers (starting from

72 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
pin 1 to 40 on the Raspberry Pi 2/3), or Broadcom GPIO numbers (BCM). Using BCM is very useful
with a ribbon cable (such as the Adafruit T-Cobbler Plus) to connect the Raspberry Pi to the
breadboard. The BCM numbers refer to the labels printed on the T-Cobbler Plus (see Figure 9). For
this example, we're using the BCM numbering scheme. That means that when we say we're getting the
input from pin 4, we're referring to the pin printed as #4 on the T-Cobbler Plus.
#5: Initialize the pin represented by the variable pinsensor as an input pin. Also, we use a pull-down

resistor (GPIO.PUD_DOWN) for this pin.


#6: There are two variables to keep track of the state of the sensor.
#7: We use an infinite loop to check the state of the sensor repeatedly.
#8: Inserts a slight delay of 0.1 second to the execution of the program
#9: Save the current state of the sensor.
#10: The GPIO.input() function reads the value of the GPIO pin (#4 in this case). When motion is

detected, it returns a value of true .

#11: Compare the previous state and the current state to see if the motion sensor has a change in state.
If there's a change, it means that either the sensor has just detected motion (when the state changes
from false to true ), or that the sensor is resetting itself (when the state changes from true to false ) a

few seconds after motion has been detected.


#12: If the current state is true , it means that motion has been detected.

#13: Print out the string “Motion Detected!”


When the PIR Motion Sensor detects motion, its output will be 1 ( true ), and a few seconds later, it's

automatically reset to 0 ( false ).

Acting on the Sensor Data


Now that the PIR Motion sensor is sensing motion, let's put it to good use. A good application of this
project is to install the Raspberry Pi and the motion sensor at home to monitor for unexpected
movement. You could mount the sensor near your door to detect movement outside the house when
there's no one at home.
Once motion is detected, the Raspberry Pi could send a push notification to an Android device via the
Google Cloud Messaging (GCM). A detailed description of Android and GCM is beyond the scope of
this article, but here's what's required for an Android app to receive a push notification:
73 | P a g e
3161716: Industry 4.0
Vishwakarma Government Engineering College
Department of Instrumentation and Control Engineering
 The developer of the Android application needs to apply for an API key
at https://console.developers.google.com.
 Once the Android application is installed on the device, it needs to register with Google
programmatically to obtain a registration ID. This registration ID uniquely identifies the
application on a particular device so that GCM can push a message to it.

Fig-10: How Google Push Notification works using Google Cloud Messaging (GCM)

Conclusion:

Assignments:
1. Brief the need of Pull up and Pull down resistors with Raspberry Pi GPIO Pins.

74 | P a g e
3161716: Industry 4.0

You might also like