Io T Practical Journal Mumbai Universitys BSC It Semester V Course Includes Iot Subject Uploaded

Download as pdf or txt
Download as pdf or txt
You are on page 1of 87

lOMoARcPSD|27781631

Io T Practical Journal - Mumbai University's Bsc IT Semester


V Course includes IoT. Subject
Uploaded
Bsc. Information Technology (University of Mumbai)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by C Kalpana ([email protected])
lOMoARcPSD|27781631

TY Bsc IT Sem V
Internet of Things
Practical

Downloaded by C Kalpana ([email protected])


lOMoARcPSD|27781631

B. Sc. (Information Technology) Semester – V


Subject :Internet of Things Practical
Pract No Details
0 Starting Raspbian OS, Familiarising with Raspberry Pi Components and
interface, Connecting to ethernet, Monitor, USB. https://youtu.be/
FxbgnofVInY

1 Displaying different LED patterns with Raspberry Pi. https://youtu.be/


6cDuxtgDqOU

2 Displaying Time over 4-Digit 7-Segment Display using Raspberry Pi


https://youtu.be/OA_pSU3xN5w

3 Raspberry Pi Based Oscilloscope


https://youtu.be/TfzFjh3htKI

4 Controlling Raspberry Pi with Telegram App https://youtu.be/


rRJ6H5gxaNA

5 Setting up Wireless Access Point using Raspberry Pi https://youtu.be/


aRwyy9WQgLs

6 Fingerprint Sensor interfacing with Raspberry Pi https://youtu.be/


BHvrTy1dYX8

7 Raspberry Pi GPS Module Interfacing https://youtu.be/oaLPZbAA8E8

8 IoT based Web Controlled Home Automation using Raspberry Pi


https://youtu.be/BEIkHwjl3F0

Visitor Monitoring with Raspberry Pi and Pi Camera


9 https://youtu.be/3Rxk1JmigPM

Interface Raspberry Pi with Pi Camera and write a program to capture


image and video. Save the image and video and then display image and play
video.
https://youtu.be/T6otquwzRKE

10 Interfacing Raspberry Pi with RFID. https://


youtu.be/x2AG79TMxI8

11 Building Google Assistant with Raspberry Pi.


https://youtu.be/9XwRkN9HsiQ

How to Record and Playback Audio https://youtu.be/mu-Ghn-aeO8


12 Installing Windows 10 IoT Core on Raspberry Pi
https://youtu.be/xmu_z1eXDW0
Using GPIO blink LED using sample program with Windows 10 IoT.
https://youtu.be/58nFnt2Y4Rg
lOMoARcPSD|27781631

Prepare and Setup RASPBERRY PI

Hardware preparation and Installation

Hardware Requirements

 A Raspberry Pi Model A/B/B+


 A good quality, micro USB power supply that can provide at least 700mA at 5V
 8 GB Class 10 SD card (or better) and a Card Reader
 An Ethernet cable / Wi-Fi
 USB Keyboard and Mouse
 HDMI video cable to connect with HDMI-capable monitor/television Screen OR
 HDMI to VGA connector to Connect with VGA-capable monitor

Software Requirements

 Raspbian image
 SD Card formatter
 Windows32 Disk Imager

Pre-requisites
 Download SD card formatter Application
https://sd-card-formatter.en.uptodown.com/windows
 Download Windows32 Disk Imager Application
https://sourceforge.net/projects/win32diskimager/

Step 1: Prepare Your SD Card

1. Format SD card using SD card formatter software

2. Download the latest version of Raspbian and unzip the .img file

3. Make bootable image for Raspbian OS using Win32DiskImager software


lOMoARcPSD|27781631

1) Format your SD card using SDFormatter :-


2) Select the drive & click on Option.

3) Choose the format type Quick to Full (Erase) & Click on Ok:

4) Formatting will erase all your data from SD Card, so make sure and then
click on Format and click on Ok.

5) Now SD Card formatting is


successfully completed.
lOMoARcPSD|27781631

6) Download the latest version of Raspbian OS and unzip the .img file
•Download the OS from Raspberry Pi’s official website using following link
https://www.raspberrypi.org/downloads/

•After clicking on Raspbian OS option following page will be open

•Now click on Download ZIP .After the download unzip the file
lOMoARcPSD|27781631

7) Extract (Raspbian) Zip File –

8) Make bootable image for Raspbian OS using Win32DiskImager software


& open it.
9) Now Select Device and select path of image where Raspbian image file is
stored using browse option

10) Now Click on the Write to start installation


11) Now click on Yes.

12) It takes some time to process the installation 13) Installation is done
lOMoARcPSD|27781631

Now your SD Card is ready to use.


Open My Computer and check the status of your SD Card
Before creating bootable SD After creating bootable SD
card (using Raspbian OS) card (using Raspbian OS)

14) Right click on SD Card and Click on Eject.

Step 2: Time to Power Up Raspberry Pi

1) Now Remove SD card from Card Reader and insert it into Raspberry Pi.
2) Connect all devices
a. USB Keyboard and Mouse
b. Ethernet Cable
c. HDMI Cable or HDMI to VGA Connector
d. Power Supply

HDMI
Cable Power
Connection of LAN Cable
raspberry pi
Power
Indicator
Keyboard
SD Card
Active

Mouse GPIO CPU


PINS Memory
card
lOMoARcPSD|27781631

3) Power on Switch Button

After power on Raspberry Pi, two light indicators should be blink. In which
Red Light indicates that power supply is provided, whereas Green Light
indicates that SD card is read by Pi.

If green light is not visible, then something is wrong with your SD Card.

After successful installation, the following screen should display on your


monitor screen.
lOMoARcPSD|27781631

Setup RASPBERRY PI using Headless mode

Hardware Requirements

 A Raspberry Pi Model A/B/B+


 A good quality, micro USB power supply that can provide at least 700mA at 5V
 8 GB Class 10 SD card (or better) and a Card Reader
 An Ethernet cable / Wi-Fi
 Laptop / PC

Software Requirements

 Raspbian image
 Putty (Console Mode)
 Remote Desktop Connection / VNC Viewer (Graphical Mode)

Pre-requisites
 Bootable SD card with Raspbian OS installed in it.

Step 1: Prepare Your SD Card

1. Make SD Card bootable with Raspbian OS installed in it.


Refer previous steps for that.

2. Insert SD Card in card reader and connect to PC or Laptop. Open SD Card drive.
lOMoARcPSD|27781631

3. Now, here create empty file named as ssh without extension.


SSH (Secure Shell) is used to connect any device remotely.

4. Remove SD card from Card


Reader. Now insert it into
Raspberry Pi.

Step 2:Power on Raspberry Pi

1. Connect Power Supply &


Ethernet
Ethernet Cable to Raspberry
Cable
Pi.

2. Power on Switch button.


Power
Cable

Step 3: Setup Laptop / PC

IMP Note: My Laptop and Raspberry Pi (via Ethernet cable) are connected to
the same router. So both are sharing same network.
lOMoARcPSD|27781631

Now first find the IP address of Raspberry Pi. There are various ways to
do so. Some are listed as follows:
 Advanced IP Scanner Application
Download it using https://www.advanced-ip-scanner.com/

 Fing App.
Install Fing free app on your Mobile
from Play store.
Fing is a wireless network discovery
and audit tool which can be used to
view the devices connected to your
network.

 With the help of Gateway Address of your network, go to the router


settings and you will get Raspberry Pi IP address.

Using one of them, you will definitely get the IP address of Pi. Use this IP
address to connect remotely to the Pi device from your laptop.
lOMoARcPSD|27781631

Use Raspberry Pi in Console Mode

1. PuTTY is a free implementation of SSH and Telnet for Windows and


UNIX platforms, along with an xterm terminal emulator.
Download PuTTy Application on your Laptop / PC using below link
https://www.putty.org/

2. Now, Connect Laptop to Raspberry Pi via PuTTy.


(Here provide above IP address of Raspberry Pi and Click Open.)

3. Now login as (Use default ) Username: pi


Password: raspberry

Login successful. So here you can perform any operations using Linux
Commands.
lOMoARcPSD|27781631

Use Raspberry Pi in Graphical Mode

1. Connect your Laptop to Raspberry Pi using Putty.


2. Install xrdp package in it.This package is used to connect Pi via
RDC (Remote Desktop Connection)
As xrdp package is depend upon tightvncserver package , first
install this package and then proceed further to install xrdp.

3. Now from Laptop’s Start Menu, Select and Open Remote Desktop
Connection & give IP address of Raspberry Pi and Click on Connect
lOMoARcPSD|27781631

Provide Username
and Password and
Click on OK
lOMoARcPSD|27781631

Practical No:03
GPIO: Light the LED with Python
1) Using One LED
Code: Output:

LED
ON

LED
OFF

2) Using Three LED

Output:
Code: Green LED
ON

Red LED
ON

Blue LED
On
lOMoARcPSD|27781631

Displaying Time over 4-Digit 7-Segment Display


Using Raspberry Pi.

Installation Manual
To display small amount of data with Raspberry Pi, we can use 4 digit 7-segment Display.
7 Segment Display has seven segments in it and each segment has one LED inside it to display
the numbers by lighting up the corresponding segments.

Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. 4 digit 7 Segment Display
3. Jumper wires (Female to Female)

Here, I am using 4 digits-7 segments LED display with TM1637 controller

 Software Requirements
1. Raspbian Stretch OS
1. Connect your 4 digit 7 segment display with Raspberry Pi's GPIO Pins.

TM1637 Board
Function RPI Physical Pin Raspberry Function
Pin
GND Ground 14 GND

VCC + 5V Power 4 5V

DI0 Data In 18 GPIO 24

CLK Clock 16 GPIO 23


lOMoARcPSD|27781631

Step 1: Download Python Script


In order to control the LED, using a special script with pre-defined functions. Various functions
are available in the script, for example, to display numbers and adjust the intensity of the LEDs.
Create a folder 4digitTime under /home/pi.

Download the script using wget command.

Note: This Script file contains some of the important functions, which are required to add in our
Python script.

Step 2: Write Python Script to display Time (e.g clock.py)

import sys
import time
import datetime
import RPi.GPIO as GPIO
import tm1637

#CLK -> GPIO23 (Pin 16)


#Di0 -> GPIO24 (Pin 18)
lOMoARcPSD|27781631

Display = tm1637.TM1637(23,24,tm1637.BRIGHT_TYPICAL)

Display.Clear()
Display.SetBrightnes(1)
while(True):
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
currenttime = [ int(hour / 10), hour % 10, int(minute / 10), minute % 10 ]

Display.Show(currenttime)
Display.ShowDoublepoint(second % 2)

time.sleep(1)

The above script needs the tm1637.py script to work, so place both files in the same folder.

Script functions
The clock script uses the following functions, defined in tm1637.py:
Display. Clear () - Clears the display if individual LEDs are still active.
Display.SetBrightnes(x) - After this you can adjust the brightness of the display, at least 0 and
maximum 7.
Display. Show(x,x,x,x) - Show the actual 4 digits (digits), x can be 0 to 9.
Display.ShowDoublepoint (status) - Controlling the ':' between the second and third digit, true
(1) = on / false (0) = off.

To know more about TM1637 controller, check


http://www.microcontroller.it/english/Tutorials/Elettronica/componenti/TM1637.htm

Step 3: Start the script with following command


lOMoARcPSD|27781631

To run the script in background you can use following command:

That's all !!!


Thank you….
lOMoARcPSD|27781631

Raspberry Pi based Oscilloscope


Installation Manual

One of the most important tools in Electrical/Electronic engineering is The Oscilloscope.


An oscilloscope is a laboratory instrument commonly used to display and analyze the waveform of
electronic signals. In effect, the device draws a graph of the instantaneous signal voltage as a
function of time.
In this project we will seek to replicate the signal visualization capabilities of the oscilloscope
using the Raspberry Pi and an analog to digital converter module.
Replicating the signal visualization of the oscilloscope using the Raspberry Pi will require the
following steps;
1. Perform Digital to analog conversion of the Input signal
2. Prepare the resulting data for representation
3. Plot the data on a live time graph

Analog Signals Signal Processing Visualize using the Graph

 Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. ADS1115 ADC
3. Breadboard
4. Jumper Wires

ADS1115 ADC chip is used to convert the analog input signals to digital signals which can be
visualized with the Raspberry Pi. This chip is important because the Raspberry Pi does not have an on-
board analog to digital converter (ADC).

 Software Requirements
1. Raspbian Stretch OS
2. Adafruit module for interfacing with the ADS1115 ADC chip
3. Python Module matplotlib used for data visualization
lOMoARcPSD|27781631

1. Connect your ADC with Raspberry Pi's GPIO Pins.

ADS1115 ADC Pin Number GPIO Number

VDD Pin 17 3.3v

GND Pin 9 GND

SCL Pin 5 GPIO 3

SDA Pin 3 GPIO 2

Step 1: Enable Raspberry Pi I2C interface

Go to Interfacing Options  I2C  Enable (Yes)

Step 2: Update the Raspberry pi


lOMoARcPSD|27781631

Step 3: Install the Adafruit ADS1115 library for ADC


To install the dependencies starting with the Adafruit python module for the ADS115 chip,
Ensure you are in the Raspberry Pi home directory ($ cd ~)

Next, clone the Adafruit git folder for the library by running

Change into the cloned file’s directory and run the setup file

Step 4: Test the library and 12C communication.


Now,it is important to test the library and ensure the ADC can communicate with the raspberry pi
over I2C. To do this use an example script that comes with the library.
$ cd examples
$ python simpletest.py
If the I2C module is enabled and connections good, it should display the data as below
If an error occurs, check to ensure the ADC is well connected to the PI and I2C communication is
enabled on the Pi.

Step 5: Install Matplotlib

With all the dependencies installed, we are now ready to write the code.
At this stage it is important to switch to a monitor or use the VNC viewer (or Remote Desktop
Connection), anything through which you can see your Raspberry Pi’s desktop, as the graph being
plotted won’t show on the terminal.
lOMoARcPSD|27781631

Step 6 :Python Code for Raspberry Pi Oscilloscope:

import matplotlib.pyplot as plt


from matplotlib.animation import FuncAnimation
import Adafruit_ADS1x15

# Create an ADS1115 ADC (16-bit) instance.


adc = Adafruit_ADS1x15.ADS1115()

GAIN = 1
val = [ ]

# Start continuous ADC conversions on channel 0 using the previous gain value.
adc.start_adc(0, gain=GAIN)
print('Reading ADS1x15 channel 0')

fig, ax = plt.subplots()
ax.set_ylim(-5000,5000)
ax.set_title('Oscilloscope')
ax.grid(True)
ax.set_ylabel('ADC outputs')

line, = ax.plot([], 'ro-', label='Channel 0')


ax.legend(loc='lower right')

def update(cnt):
# Read the last ADC conversion value and print it out.
value = adc.get_last_result()
print('Channel 0: {0}'.format(value))
# Set new data to line
line.set_data(list(range(len(val))), val)
ax.relim()
ax.autoscale_view()
#Store values for later
val.append(int(value))
if(cnt>50):
val.pop(0)

ani = FuncAnimation(fig, update, interval=500)


plt.show()
lOMoARcPSD|27781631

Save the code and run using

That's all !!!


ADC data being printed on the terminal,and related Plot is also visible.

Thank you….
lOMoARcPSD|27781631

Controlling Raspberry Pi using Telegram


Installation Manual
 Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. LED
3. Breadboard
4. Jumper Wires
1. Connect 4 LED with Raspberry Pi's GPIO Pins.

Led Terminal Pin Number GPIO Number

Green Positive Pin 31 GPIO 6

Yellow Positive Pin 33 GPIO 13

Red Positive Pin 35 GPIO 19

Blue Positive Pin 37 GPIO 26

Negative of all four Pin 9 GND

2. Install Telegram App in Mobile . Follow process to obtain access token


lOMoARcPSD|27781631

3. Install Telegram Bot on Raspberry Pi

4. Write Python Script to blink LED with Telegram Bot

#Sample program for Light LED on/off using Telegram

import time, datetime


import RPi.GPIO as GPIO
import telepot
from telepot.loop import MessageLoop

green = 6
yellow = 13
red = 19
blue = 26

now = datetime.datetime.now()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

##LED Blue
GPIO.setup(blue, GPIO.OUT)
GPIO.output(blue, 0) #Off initially

#LED Yellow
GPIO.setup(yellow, GPIO.OUT)
GPIO.output(yellow, 0) #Off initially
#LED Red
GPIO.setup(red, GPIO.OUT)
GPIO.output(red, 0) #Off initially
#LED green
GPIO.setup(green, GPIO.OUT)
GPIO.output(green, 0) #Off initially

def action(msg):
chat_id = msg['chat']['id']
lOMoARcPSD|27781631

command = msg['text']

print ('Received: %s' % command)

if 'on' in command:
message = "on"
if 'blue' in command:
message = message + "blue "
GPIO.output(blue, 1)
if 'yellow' in command:
message = message + "yellow "
GPIO.output(yellow, 1)
if 'red' in command:
message = message + "red "
GPIO.output(red, 1)
if 'green' in command:
message = message + "green "
GPIO.output(green, 1)
if 'all' in command:
message = message + "all "
GPIO.output(blue, 1)
GPIO.output(yellow, 1)
GPIO.output(red, 1)
GPIO.output(green, 1)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)

if 'off' in command:
message = "off "
if 'blue' in command:
message = message + "blue "
GPIO.output(blue, 0)
if 'yellow' in command:
message = message + "yellow "
GPIO.output(yellow, 0)
if 'red' in command:
message = message + "red "
GPIO.output(red, 0)
if 'green' in command:
message = message + "green "
GPIO.output(green, 0)
if 'all' in command:
message = message + "all "
GPIO.output(blue, 0)
GPIO.output(yellow, 0)
GPIO.output(red, 0)
GPIO.output(green, 0)
message = message + "light(s)"
telegram_bot.sendMessage (chat_id, message)
lOMoARcPSD|27781631

telegram_bot = telepot.Bot('677951290:AAE57TbLoJT3rz7out0W2udQU0MC2AN1wbs')
Access Token Key
print (telegram_bot.getMe())

MessageLoop(telegram_bot, action).run_as_thread()
print ('Up and Running ...')

while 1:
time.sleep(10)

5. Now ,run the example code as follows:

Thank you….
lOMoARcPSD|27781631

Setting up Wireless Access Point using Raspberry Pi


Installation Manual
 Hardware Requirements
• A Raspberry Pi Model A/B/B+
• Ethernet Cable
• Power Supply for the Pi
• WiFi USB dongle (Optional)
As Raspberry Pi 3 or Raspberry Pi Zero W both have Wi-Fi on board. So in that case no need of
any external Wi-Fi module.

 Software Requirements

• Latest Raspbian Stretch OS


• Putty
• Advanced IP Scanner Software or
• Fing App to check IP address of Raspberry Pi

1. Set up the Raspberry Pi with the Raspbian Stretch OS


Prepare SD Card with bootable OS, insert it into Raspberry Pi.

• Connect LAN Cable coming out from your Network Provider into Raspberry Pi.
• Make sure your Laptop/PC is also connected with the same network.
• Connect Power Supply to Raspberry Pi.
• Check IP address of Raspberry Pi using IP Scanner Software or Fing App
• Then connect your Laptop/PC to Raspberry Pi using a terminal software like Putty.
lOMoARcPSD|27781631

• Update the Raspberry Pi to ensure we have the latest version of everything. This is done
by using following commands:

2. Install hostapd and bridge-utils

3. Edit file /etc/hostapd/hostapd.conf and add following lines to it


lOMoARcPSD|27781631

4. Edit file /etc/network/interfaces and add following lines to it

This will result in the Pi using DHCP which means it can be used in any network.

5. Finally ,edit last file to enable hostapd to run upon boot


lOMoARcPSD|27781631

6. To effect the changes made to the Raspberry Pi, reboot the system.

Note : From now on hostapd will start whenever your Pi boots up.
There should now be a functioning bridge between the wireless LAN and the Ethernet connection
on the Raspberry Pi, and any device associated with the Raspberry Pi access point will act as if it
is connected to the access point's wired Ethernet.

It is possible to use a static IP address for the bridge if required, but generally, if the Raspberry
Pi access point is connected to a ADSL router, the DHCP address will be fine.

Testing Raspberry Pi Wireless Access Point:


To test above instructions, use a mobile phone or any other device capable of connecting to a WiFi
hotspot network, you should see the name pop up. You can then connect to it by entering password
we specified in hostapd.conf file.
lOMoARcPSD|27781631

Fingerprint Sensor interfacing with Raspberry Pi


Installation Manual
Finger Print Sensor, which we used to verify the identity of a person for various purposes.
Nowadays we can see fingerprint-based systems everywhere in our daily life.

One of the advantage of fingerprint-based systems is that passwords and / or number codes can
be completely omitted.

Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. Fingerprint Module
3. Serial USB Converter
4. Jumper Wires

Here, I am using R307 fingerprint module with Serial USB Converter.

R307 Fingerprint Module consists of optical fingerprint sensor, Supply voltage: DC 4.2 ~ 6.0V

Pin No Pin Name Details


1 5V Regulated 5V DC
2 GND Common Ground
3 TXD Data output - Connect to MCU RX
4 RXD Data Input - Connect to MCU TX
5 TOUCH Active Low output when there is touch on sensor by finger
6 3.3V Use this wire to give 3.3V to sensor instead of 5V

Note: So I connected first 4 pins of Fingerprint module to Serial USB Converter.


lOMoARcPSD|27781631

Connect fingerprint module to USB Serial converter.

Fingerprint Module USB Serial Converter


5V 5.0 V
GND GND
TXD TXD
RXD RXD
TOUCH -
3.3V -
Note: Check USB to Serial Converter pins according to your model. And connect accordingly.

 Software Requirements
1. Raspbian Stretch OS

1. Now, just connect fingerprint module to Raspberry Pi USB port by using USB to
Serial converter.

Step 1: To install this library, root privileges are required. So login with root user.
lOMoARcPSD|27781631

Step 2: Download some required packages using wget command

wget –O – http://apt.pm-codeworks.de/pm-codeworks.de.gpg | apt-key add –

wget http://apt.pm-codeworks.de/pm-codeworks.list -P /etc/apt/sources.list.d/

Step 3: Update the Raspberry Pi

Step 4: Install the downloaded finger print sensor library

Step 5: To return to the normal shell (under the Pi user), type exit

Step 6: Now check USB port on which your finger print sensor is connected. Use this USB
port in our Python script.

Step 7: Now go to the examples directory. (/usr/share/doc/python-fingerprint/examples/)


lOMoARcPSD|27781631

Step 8: Run sample file, to test to see if the sensor is detected and ready for access

The above data should appear, which allows you to display the positions under which an imprint
is stored by selecting a page (0-3).
If here you get Exception message, then something is wrong with the cabling or the sensor.
Check it again.

Step 9: Now execute other scripts, to make sure Fingerprint module is working.

Script Usage

example_index.py Shows template index table.

example_enroll.py Stores new fingerprint

example_delete.py Deletes a fingerprint from sensor

example_search.py Search for recorded fingerprint

example_downloadimage.py Read fingerprint and download it.

example_generaterandom.py Generates 32 bit random number.

Run example_enroll.py script to store new fingerprint

Put your finger on the glass surface, wait for the instruction in the terminal and remove your finger
as soon as it is written there. Afterwards you have to put your finger a second time for the
verification and the imprint is stored in the next number.

Now, Run example_search.py script to see whether our finger is recognized.

Put the same finger on glass surface.


If the fingerprint is detected, it displays below message.
lOMoARcPSD|27781631

Execute same script again, this time use other finger which is not previously stored.
If fingerprint is not detected, then gives "No match Found" message

So, our fingerprint module is working properly.

That's all!!!
Thank you….
lOMoARcPSD|27781631

Interfacing GPS module with Raspberry Pi


Installation Manual
• GPS stands for Global Positioning System and used to detect the Latitude and Longitude of any
location on the Earth, with exact UTC time (Universal Time Coordinated).
• GPS module is the main component in our vehicle tracking system.
• This device receives the coordinates from the satellite for each and every second, with time and
date.
• GPS module sends the data related to tracking position in real time, and it sends so many data in
NMEA format.
• NMEA format consists of sentence starts from $GPGGA, the coordinates, time and other useful
information.
• GPGGA is referred to Global Positioning System Fix Data.
• GPGGA string contains following co-ordinates separated by commas.

Sr Sr
No Identifier Description No Identifier Description

Global Positioning system


1 $GPGGA 7 FQ Fix Quality Data
fix data
Time in hour minute
No. of Satellites being
2 HHMMSS.SSS seconds and milliseconds 8 NOS
Used
format.
Horizontal Dilution of
3 Latitude Latitude (Coordinate) 9 HPD
Precision
Direction N=North, Altitude from sea
4 N 10 Altitude
S=South level

5 Longitude Longitude(Coordinate) 11 M Meter

Direction E= East,
6 E 12 Height Height
W=West

13 Checksum Checksum Data

Hardware Requirements Software Requirements


• Raspberry Pi Model B/B+ , SD Card • Raspbian Stretch OS
• Ethernet Cable / Wi-Fi • Adafruit Python Char LCD Library
• Power Supply to Pi
• Neo 6m v2 GPS Module
• Jumper wires
• Breadboard
• 2x16 LCD Display
• Potentiometer (to adjust Contrast)
lOMoARcPSD|27781631

Neo 6m v2 GPS Module


 This board features the u-blox NEO-6M GPS module with
antenna and built-in EEPROM. This is compatible with
various flight controller boards designed to work with a GPS
module.
 EEPROM is used for saving the configuration data when
powered off.
 Power Supply Range: 3 V to 5 V
 Default Baud Rate: 9600 bps

Connect GPS Module to RPi


Connection is very simple. Requires 4 Female to Female Jumper Wires
Neo 6m V2 GPS Raspberry Pi
Details Raspberry Pi Function
Board Pin Physical Pin
VCC Power Pin 1 3.3V Power
GND Common Ground Pin 39 GND
TXD Data Output Pin 10 (UART_RXD0) GPIO15
RXD Data Input Pin 8 (UART_TXD0) GPIO14

Connect 2x16 LCD Display to RPi


A 16x2 LCD is used for displaying all messages. A 10k Potentiometer is also used with LCD for
controlling the contrast. I used following GPIO pins to connect LCD to Raspberry Pi’s GPIO Pins:
Sr No LCD Display Board Pin RPI Physical Pin Raspberry Function
4 RS 37 GPIO26
6 E 35 GPIO19
11 D4 33 GPIO13
12 D5 31 GPIO6
13 D6 29 GPIO5
14 D7 23 GPIO11
lOMoARcPSD|27781631

Connect GPS module to Raspberry Pi’s GPIO Pins by using Female to Female Jumper wires
Connect 2x16 LCD Display to Raspberry Pi’s GPIO Pins with the help of breadboard and
jumper wires.

Step 1: Update Raspberry Pi

Step 2: edit the /boot/config.txt file

At the bottom of this file, add the above lines

The dtoverlay=pi3-disable-bt disconnects the bluetooth from the ttyAMA0, this is to allow us access to
use the full UART power available via ttyAMAO instead of the mini UART ttyS0.
Save with Ctrl+X, yes and press Enter.
lOMoARcPSD|27781631

Step 3: Before proceeding, make a copy of cmdline.txt file

Now, edit file cmdline.txt

Remove console=serial0,115200 and Modify root=/dev/mmcblk0p2

Save with Ctrl+X, yes and press Enter.

Step 4: Reboot Raspberry Pi using the command sudo reboot

Step 5: Stop and disable the Pi’s serial ttyS0 service

The following commands can be used to enable it again if needed

sudo systemctl enable [email protected]

sudo systemctl start [email protected]

Step 6: Reboot Raspberry Pi using the command sudo reboot

Step 7: Now, Enable the ttyAMA0 service

Verify it using ls –l /dev command


lOMoARcPSD|27781631

Step 8: Install minicom and pynmea2


Install minicom package which is used to connect to the GPS module and make sense of the data.

Install pynmea2 library which is used to parse the received data.

Step 9: Use minicom command to test our GPS module is working fine.

9600 represents the baud rate at which the GPS module communicates.
Here, we can see NMEA sentences .NMEA format consist several sentences, in which we only need
one sentence. This sentence starts from $GPGGA and contains the coordinates

Sometimes we received sentences which contains unknown msg*58, but this is not an error, actually it
may takes some time to track your GPS module. (Even for the first time more than 20-30 minutes.)
I suggest keep your GPS module's antenna in open space (e.g. near the window)
To exit from above window, Press Ctrl+A, and Press x and Enter Key.
Step 10: The above same test can also be done using cat command

This sentence gives you Latitude found after two commas and Longitude found after four commas.
lOMoARcPSD|27781631

Step 11: Write Python script to display your current Latitude and Longitude on LCD Display.

Python Script (gpsdemo.py)


import time
import serial
import string
import pynmea2
import RPi.GPIO as gpio
import Adafruit_CharLCD as LCD

gpio.setmode(gpio.BCM)

lcd = LCD.Adafruit_CharLCD(rs=26, en=19,


d4=13, d5=6, d6=5, d7=11,
cols=16, lines=2)

lcd.message("MSD Gurukul\n Welcomes You")


time.sleep(2)
lcd.clear()
lcd.message("GPS Demo")
time.sleep(2)
lcd.clear()

port = "/dev/ttyAMA0" # the serial port to which the pi is connected.

#create a serial object


ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)

try:
while 1:
try:
data = ser.readline()
except:
print("loading")
#wait for the serial port to churn out data

if data[0:6] == '$GPGGA': # the long and lat data are always contained in the GPGGA string of
the NMEA data

msg = pynmea2.parse(data)
latval = msg.lat #parse the latitude and print
concatlat = "Lat:" + str(latval)
print(concatlat)
lcd.set_cursor(0,0)
lcd.message(concatlat)
lOMoARcPSD|27781631

#parse the longitude and print


longval = msg.lon
concatlong = "Long:"+ str(longval)
print(concatlong)
lcd.set_cursor(0,1)
lcd.message(concatlong)

time.sleep(0.5)#wait a little before picking the next data.


except KeyboardInterrupt:
lcd.clear()
lcd.message("Thank You")
time.sleep(2)

Run Python script on terminal using sudo command (sudo gpsdemo.py)

That's all!!!
Thank you….
lOMoARcPSD|27781631

IoT based Web Controlled Home Automation


Using Raspberry Pi.

Installation Manual
Controlling AC appliances with the click of buttons on a webpage using internet. It is possible
to control your Home appliances from anywhere in the world. This web server can be run from
any device which can run HTML applications, like Smart Phone, tablet, computer etc.

Hardware Requirements
1. Raspberry Pi Model B/B+ 5v Relays
2. LEDs to test.
3. Breadboard
4. AC lamp to Test
5. Jumper wires

 Software Requirements
1. Raspbian Stretch OS
2. WebIOPi frame work
1. Connect your 5v Relay with Raspberry Pi's GPIO Pins using Jumper wires (Female-
Female).

Relay Board Pin Function RPI Physical Pin Raspberry Function

+5v + 5V Power 4 5V

I/P Data In 7 GPIO 4

GND Ground 6 GND

LED to Test : Connect LED to Raspberry Pi using breadboard

LED Terminal RPI Physical Pin LED Terminal RPI Physical Pin

Positive 37 Negative 39
lOMoARcPSD|27781631

Step 1: Download the WebIOPi Framework file


Use wget command to get the installer file of WebIOPi framework from sourceforge page
Make sure you are in home directory.

Extract the file using tar command.

Now, Go to the WebIOPi Directory.

Step 2: Install patch file


At this point before running the setup, we need to install a patch as this version of the WebIOPi
does not work with the raspberry pi 3.
Download patch file using wget command

Install patch file using patch command


lOMoARcPSD|27781631

Step 3: Install setup of WebIOPi framework, Run setup file

Keep saying yes if asked to install any dependencies during setup installation. When done, reboot
your pi

Step 4: Test WebIOPi Installation


We will need to test our WebIOPi installation to be sure everything works fine as desired.
Run following command on terminal

Now, open web browser and connect to http://PI’s IP address:8000

The system will prompt you for username and password.


Username: webiopi
Password: raspberry

After the login, click on the GPIO header link. Test your LED which is connected to raspberry Pi’s
GPIO Pins. In my case, I have used Physical Pin no 37 of Pi. So set it as output. Click the pin 37
button to turn on or off the LED. This way we can control the Raspberry Pi GPIO using WebIOPi.

After the test, if everything worked as described, then we can go back to the terminal and stop the
program with CTRL + C.

Step 4: Building the Web Application for Raspberry Pi Home Automation

Create below directory structure


lOMoARcPSD|27781631

Place image inside img folder

Create smarthome.js file inside scripts folder

Smarthome.js file
webiopi().ready(function() {
webiopi().setFunction(4,"out");
var content, button;
content = $("#content");

button = webiopi().createGPIOButton(4,"Room 1");


content.append(button);
});

Create smarthome.css file inside styles folder

Smarthome.css file
body {
background-color:#fff;
background-repeat:no-repeat;
background-position:center;
background-size:cover;
font: bold 18px/25px Arial, sans-serif;

h1 {
font: bold 40px Arial, sans-serif;
background-color:#000;
lOMoARcPSD|27781631

color:white;
}

button {
display: block;
position: absolute;
margin: 40px 610px;
padding: 0 10px;
text-align: center;
text-decoration: none;
width: 130px;
height: 40px;
font: bold 18px/25px Arial, sans-serif;
color: black;

text-shadow: 1px 1px 1px rgba(255,255,255, .22);


-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;

-webkit-box-shadow: 1px 1px 1px rgba(0,0,0, .29), inset 1px 1px 1px rgba(255,255,255,
.44);
-moz-box-shadow: 1px 1px 1px rgba(0,0,0, .29), inset 1px 1px 1px rgba(255,255,255, .44);
box-shadow: 1px 1px 1px rgba(0,0,0, .29), inset 1px 1px 1px rgba(255,255,255, .44);

-webkit-transition: all 0.15s ease;


-moz-transition: all 0.15s ease;
-o-transition: all 0.15s ease;
-ms-transition: all 0.15s ease;
transition: all 0.15s ease;
}

input[type="range"] {
display: block;
width: 160px;
height: 45px;
}

#gpio4.LOW {
background-color: White;
color: Black;
}
#gpio4.HIGH {
background-color: Black;
color: LightGray;
}
lOMoARcPSD|27781631

Create index.html file inside html folder


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content = "height = device-height, width = device-width,
user-scalable = no" />
<title>Smart Home</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript" src="/scripts/smarthome.js"></script>
<link rel="stylesheet" type="text/css" href="/styles/smarthome.css">
<link rel="shortcut icon" sizes="196x196" href="/img/roomlighton.jpeg" />
</head>
<body>
<h1 align=center>Web Based Controlled Home Automation using Raspberry Pi </h1>

<div id="content" align="center"></div>


<center><img src="/img/roomlighton.jpeg" height="500px" width="800px"
id='pic1' /></center>

</body>
</html>

Step 5: WebIOPi Server Edits for Home Automation

We need to edit the config file of the webiopi service so it’s pointed to use data from our html folder
instead of the config files that came with it.

Under http section of the config file, comment out doc-root line and change the path to your project
file
lOMoARcPSD|27781631

Step 6: Change the username & password of the WebIOPi service

Note that you can change the password of the WebIOPi service using the command if you want. Or
skip this step.

Step 7: Run the WebIOPi service

Start the WebIOPi service

Restart the WebIOPi service

Status the WebIOPi service

Stop the WebIOPi service

To setup WebIOPi to run at boot, use:

To reverse and stop it from running at boot, use


lOMoARcPSD|27781631

When you Click on button Room1 ,it switch on AC Lamp, again clicking on same button ,it
will switch off AC Lamp.

Note : It is possible to open same URL http://PI’s IP address:8000 on smart phone , tablet
over local network.
That's all !!!
Thank you….
lOMoARcPSD|27781631

Capture Image & Record Videos


With Raspberry Pi and Pi Camera

Installation Manual
In this tutorial, we are demonstrating Visitors Monitoring System with Image capture and
recording functionality. This Monitoring system will digitize and automate the whole visitor
entries, and there will be no need to maintain them manually.
We are interfacing Pi camera with Raspberry Pi to capture the image and record videos of every
visitor which has entered through the Gate or door. This captured image is saved in the system
with the Date and time of the entry.
This system is very useful in offices, factories where visitor entry record is maintained for visitors,
employees. So this can be very useful for security purpose.

Hardware Requirements
 Raspberry Pi , SD Card
 Pi camera
 Buzzer
 2 Push Buttons
 LED
 Bread Board
 Jumper Wires
 Power supply
 Ethernet Cable / Wi Fi
 Monitor , Keyboard, Mouse (Optional ,For without headless connection)

Software Requirements

1. Raspbian Stretch OS
2. Python Script
lOMoARcPSD|27781631

System Explanation

 Pi camera is used to capture the images and record the videos of visitors, when a push button
is pressed or triggered.
 After pushing the one button, Raspberry Pi sends command to Pi Camera to click the
picture and save it.
 Similarly, after pushing another button, Raspberry Pi sends command to Pi Camera to
record the video and save it.
 The buzzer is used to generate sound when button pressed.
 LED is used for indicating that Raspberry Pi is ready to accept Push Button press, means
when LED is ON, and system is ready for operation.

Circuit Explanation
 Connect Camera to Raspberry Pi
The Camera Module is a great accessory
for the Raspberry Pi, allowing users to
take still pictures and record video in full
HD. Connect the Camera Module to the
Raspberry Pi’s camera port (Blue side of
cable to face Ethernet connection).

 Connect LED,Push Button ,Buzzer with Raspberry Pi's GPIO Pins.


The buzzer is used to generate sound when
button pressed.
LED is used for indicating that Raspberry Pi is
ready to accept Push Button press, means when
LED is ON, and system is ready for operation.
lOMoARcPSD|27781631

I used following GPIO pins to connect above three components to Raspberry Pi.
Component Terminal RPI Raspberry
Physical Pin Function
Buzzer Positive Terminal Pin 32 GPIO 12
Push Button1 Positive Terminal Pin 36 GPIO 16
Push Button2 Positive Terminal Pin 38 GPIO 20
LED Positive Terminal Pin 40 GPIO 21
all Negative Terminal Pin 20 GND

Note that the camera preview only works when a monitor is connected to the Pi,
so remote access (such as SSH and VNC) will not allow you to see the camera
preview.

Complete Connection

Camera

LED

Buzzer
Push Button

Step 1: Update Raspberry Pi


lOMoARcPSD|27781631

Step 3: Enable Raspberry Pi Camera by using Raspberry Pi Software Configuration


Tool (raspi-config)

Select Interfacing Options  Camera  Enable

After this reboot the system, using sudo reboot command.


Step 4: After Reboot, Create a folder which is used to store pictures captured by Pi Camera.
(E.g. /home/pi/Desktop/Visitors)

Step 5: Write a Python Script to capture images and save them in folder.
(capture_record_picamera.py)

import RPi.GPIO as gpio


import picamera
import time

led=21 #pin no 40
buz=12 #pin no 32

butcapture=16 #pin no 36
butrecord=20 #pin no 38
lOMoARcPSD|27781631

HIGH=1
LOW=0

gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(led, gpio.OUT)
gpio.setup(buz, gpio.OUT)
gpio.setup(butcapture, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(butrecord, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.output(led , 0)
gpio.output(buz , 0)
data=""

def capture_image():
print('Please Wait...')
data= time.strftime("%d_%b_%Y\%H:%M:%S")
camera.start_preview()
time.sleep(5)
print(data)
camera.capture('/home/pi/Desktop/Visitors/%s.jpg'%data)
camera.stop_preview()
print('Image Captured successfully')
time.sleep(2)

def record_video():
print('Please Wait...')
data= time.strftime("%d_%b_%Y\%H:%M:%S")
camera.start_preview()
camera.start_recording('/home/pi/Desktop/Visitors/rec.h264')
time.sleep(5)
print(data)
camera.stop_recording()
camera.stop_preview()
print('Video recorded successfully')
time.sleep(2)

print('Welcome to my System')
time.sleep(2)

print('Visitor Monitor System using RPi')


time.sleep(3)

camera = picamera.PiCamera()
camera.rotation=180
camera.awb_mode= 'auto'
camera.brightness=55
lOMoARcPSD|27781631

print(" Please Press Button")


time.sleep(2)
try:
while 1:
d= time.strftime("%d %b %Y")
t= time.strftime("%H:%M:%S")
print("Time: %s"%t)
print("Date:%s"%d)
gpio.output(led, 1)
if gpio.input(butcapture)==False:
gpio.output(buz, 1)
gpio.output(led, 0)
time.sleep(0.5)
gpio.output(buz, 0)
capture_image()

if gpio.input(butrecord)==False:
gpio.output(buz, 1)
gpio.output(led, 0)
time.sleep(0.5)
gpio.output(buz, 0)
record_video()

time.sleep(0.5)

except KeyboardInterrupt:
print("Done .......")
time.sleep(3)
gpio.output(led, 0)
finally:
exit(0)

1. Import picamera ,gpio ,


2. Initialize and setup all GPIO(BCM Pattern)Pins used for led,buzzer,push button
3. Write capture_image() function to capture images and saved them in specified folder with
date & time.
4. Write record_video() function to record videos and saved them in specified folder with
rec.h264 filename
5. When you execute script, first it displays some welcome messages on terminal
6. After welcome messages, it will ask you to Press Button, and Displays current Date &
Time on terminal,and LED gets on ,indicating Ready for process.
7. When you press first push button,
a. first ,buzzer generates sound
b. then led gets off,
c. after half second ,
d. Stops buzzer sound,
e. And call capture_image() function which helps to capture image & saved in
folder.
lOMoARcPSD|27781631

8. When you press second push button,


a. first ,buzzer generates sound
b. then led gets off,
c. after half second ,
d. Stops buzzer sound,
e. And call record_video() function which helps to record the videos & saved in
folder.

Step 6: Execute above script using python capture_record_picamera.py

Some useful methods


 camera.capture() is used to capture the still pictures. Provide Path(where to save) and
image name as parameter.
 start_recording() is used to start the recording of the videos. Provide Path(where to save)
and video name as parameter. Raspberry Pi’ video supports .ht64 as extension.
 stop_recording() is used to stop the recording.
 To play the video, need to open a terminal window. Type the command omxplayer
videonme.h264 and Press Enter to play the video.
 It may actually play at a faster speed than what has been recorded, due to omxplayer’s fast
frame rate.

Effects
 The resolution of the capture is configurable. By default it’s set to the resolution of your
monitor, but the maximum resolution is 2592 x 1944 for still photos and 1920 x 1080 for
video recording. The minimum resolution allowed is 64 x 64. To set the resolution to max
use following method. Note that you’ll also need to set the frame rate to 15 to enable this
maximum resolution.
camera.resolution = (2592, 1944)
camera.framerate = 15
camera.start_preview()
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/max.jpg')
camera.stop_preview()

 To add text to your image with annotate_text.

camera.start_preview()
camera.annotate_text = "Hello world!"
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/text.jpg')
camera.stop_preview()
lOMoARcPSD|27781631

 To set the annotation text size with the following code. Valid sizes are 6 to 160. The
default is 32
camera.annotate_text_size = 50

 To alter the annotation colors. First of all, ensure that Color is imported by amending
your import line at the top.
from picamera import PiCamera, Color
Then amend the rest of your code as follows:

camera.start_preview()
camera.annotate_background = Color('blue')
camera.annotate_foreground = Color('yellow')
camera.annotate_text = " Hello world "
sleep(5)
camera.stop_preview()

 To alter the brightness setting, which can be set from 0 to 100. The default is 50. Try
setting it to another value.
camera.start_preview()
camera.brightness = 70
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/bright.jpg')
camera.stop_preview()

 To alter the Contrast setting, which can be set from 0 to 100. The default is 50. Use similar
to brightness
camera.start_preview()
camera.contrast = 70
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/contrast.jpg')
camera.stop_preview()

 Use camera.image_effect to apply a particular image effect. The options


are: none, negative, solarize, sketch, denoise, emboss, oilpaint, hatch, gpen, pastel, watercol
or, film, blur, saturation, colorswap, washedout, posterise, colorpoint, colorbalance, cartoon,
deinterlace1, and deinterlace2. The default is none. Pick one and try it out:
camera.start_preview()
camera.image_effect = 'colorswap'
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/colorswap.jpg')
camera.stop_preview()
 Use camera.awb_mode to set the auto white balance to a preset mode to apply a particular
effect. The options
areoff, auto, sunlight, cloudy, shade, tungsten, fluorescent, incandescent, flash, and horizon.
The default is auto. Pick one and try it out:
camera.start_preview()
camera.awb_mode = 'sunlight'
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/sunlight.jpg')
camera.stop_preview()
lOMoARcPSD|27781631

 You can use camera.exposure_mode to set the exposure to a preset mode to apply a particular
effect. The options
are: off, auto, night, nightpreview, backlight, spotlight, sports, snow, beach, verylong, fixedfps, anti
shake, and fireworks. The default is auto. Pick one and try it out:
camera.start_preview()
camera.exposure_mode = 'beach'
sleep(5)
camera.capture('/home/pi/Desktop/Visitors/beach.jpg')
camera.stop_preview()

That's all !!!


Thank you….
lOMoARcPSD|27781631

Interfacing Raspberry Pi with RFID.

Installation Manual
RFID stands for Radio Frequency Identification uses radio frequency to read information stored
in a RFID card or tag. Each card has a unique ID and this makes it a perfect choice for many
authentication applications. The RFID authentication systems are easy to design and are cheap in
cost. Interfacing RFID Reader with Raspberry Pi can be very useful as you can implement a wide
range of applications like:
 Access Control
 Authentication
 e-Ticket ,e-Payment ,e-Toll
 Attendance System

Hardware Requirements
1. Raspberry Pi Model 3 B/B+
2. RFID Reader (RC 522)
3. RFID Tags or Cards
4. Jumper wires (Female to Male)
5. Breadboard

Here, I am using RFID Reader RC 522

This module came with two different styles of header pins,


one of which needed to be soldered onto the PCB.
The RFID RC522 is a very low-cost RFID (Radio-frequency
identification) reader and writer that is based on the MFRC522
microcontroller. This microcontroller provides its data through
the SPI protocol and works by creating a 13.56MHz
electromagnetic field that it uses to communicate with the
RFID tags.
lOMoARcPSD|27781631

 Software Requirements

1. Raspbian Stretch OS
2. SPI Supporting Libraries
3. RC522 Python Library
Connect your RFID reader with Raspberry Pi's GPIO Pins.

RFID Reader
RPI Physical Pin Raspberry Function
Board Pin
SDA 24 GPIO8 (SPI_CE0_N)

SCK 23 GPIO11 (SPI0-_CLK)

MOSI 19 GPIO10 (SPI0_MOSI)

MISO 21 GPIO9 (SPI0_MISO)

IRQ UNUSED

GND 6 GND

RST 22 GPIO25 (GPIO_GEN6)

3.3V 1 3.3V PWR

Step 1: Update Raspberry Pi

Step 2: Enable SPI Interface using sudo raspi-config tool

Select using Arrow Keys  Interfacing Options  SPI  Enable


Step 3: Reboot Raspberry Pi
lOMoARcPSD|27781631

Step 4: Check to make sure that SPI has been enabled.

Step 5: Install python3-dev, python3-pip packages to setting up RFID reader

Step 6: Install spidev to Raspberry Pi using pip. The spidev library helps to handle
interactions with the SPI

Step 7: Install the MFRC522 library using pip that helps talk to the RC522 module over
the SPI interface

There are two files included in this repository:


MFRC522.py which is an implementation of the RFID RC522 circuit.
SimpleMFRC522.py that takes the MFRC522.py file and greatly simplifies it.
lOMoARcPSD|27781631

Step 8: Write Python script which is used to write data from the RC522 to your RFID tags.

Run above script

When you run script, it asked to write in the new data, in my case I am going to just type in msd
gurukul. Press Enter when you are happy with what you have written.

With that done, simply place your RFID Tag on top of your RFID RC522 circuit. As soon as it
detects it, it will immediately write the new data to the tag. You should see “Data Written
successfully” appear in your command line if it was successful.

Step 8: Write Python script which is used to read this data back off the RFID tag.
lOMoARcPSD|27781631

Run above script

With the script now running, all you need to do is place your RFID Tag on top of your RFID
RC522 circuit. As soon as the Python script detects the RFID tag being placed on top, it will
immediately read the data and print it back out to you.
If you successfully receive data back from your read.py script with the text that you pushed to
the card using your write.py script then you have successfully set up your Raspberry Pi to
connect with your RFID RC522 Circuit.

That's all !!!


Thank you….
lOMoARcPSD|27781631

Configure and Test Audio on Raspberry Pi

Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. SD Card
3. Ethernet Cable / Wi-Fi
4. Power Supply
5. USB Microphone
6. Speakers

Software Requirements

1. Raspbian Stretch OS

Attach USB Microphone and Speakers to Raspberry Pi.

I am using speakers with audio jack.


lOMoARcPSD|27781631

1. Select Output device

Advanced Options  Audio  Force 3.5 mm( ‘headphone’) jack

2. Locate your USB microphone in the list of capture hardware devices.


(Write down the card number and device number.) (in my case its 1,0 respectively)

$ arecord -l

3. Locate your speaker in the list of playback hardware devices.


(Write down the card number and device number.)
Note that the 3.5mm-jack is typically labeled Analog or bcm2835 ALSA (not bcm2835
IEC958/HDMI). (in my case its 0,0 respectively)

$ aplay -l
lOMoARcPSD|27781631

4. Create a new file named .asoundrc in the home directory (/home/pi)

Add following lines in it

pcm.!default {
type asym
capture.pcm "mic"
playback.pcm "speaker"
}
pcm.mic {
type plug
slave {
pcm "hw:<card number>,<device number>"
}
}
pcm.speaker {
type plug
slave {
pcm "hw:<card number>,<device number>"
}
}

Replace <card number> and <device number> with the numbers you wrote down in the previous
step. Do this for both pcm.mic and pcm.speaker.

Save file with


Ctrl+O and
Enter
lOMoARcPSD|27781631

5. Adjust the playback volume.


Press the up arrow key to set the playback volume level to around 70.

$ alsamixer

Press Esc to exit .

6. Play a test sound (this will be a person speaking). Press Ctrl+C when done.
If you don't hear anything when you run this, check your speaker connection.

$ speaker-test –t wav
lOMoARcPSD|27781631

7. Record a short audio clip.

$ arecord --format=S16_LE --duration=5 --rate=16000 --file-type=raw sample.wav

8. Check the recording by replaying it

aplay --format=S16_LE --rate=16000 sample.wav

Note that…
 If recording and playback are working, then you are done configuring audio.
 If not, check that the microphone and speaker are properly connected.
 If this is not the issue, then try a different microphone or speaker.

That's all!!!
Thank you….
lOMoARcPSD|27781631

Building Google Assistant with raspberry Pi

Installation Manual

 The Google Assistant is a virtual assistant powered by artificial intelligence and developed
by Google that is primarily available on mobile and smart home devices.
 The Google Assistant can engage in two-way conversations.

Hardware Requirements
1. Raspberry Pi Model A/B/B+
2. SD Card
3. Ethernet Cable / Wi-Fi
4. Power Supply
5. USB Microphone
6. Speakers

 Software Requirements

1. Raspbian Stretch OS
2. Google Account

Configure and Test Audio


 Attach USB Microphone and Speakers to Raspberry Pi.
 After connection, test it to ensure audio is working or not.
Follow below tutorial to configure and test audio
https://drive.google.com/open?id=1gexNOv_zK1jqRpeyCn7JKU6Tpud2Vn82
lOMoARcPSD|27781631

Note that…
 If recording and playback are working, then you are done configuring audio.
 If not, check that the microphone and speaker are properly connected.
 If this is not the issue, then try a different microphone or speaker.

Step 1: Registering the Google API


1. Before we get started with setting up the Google Assistant code on the Raspberry Pi itself, we
must first register and setup oAuth access to Google’s Assistant API. To do this, you will need to
have a Google account already.

Once you have your Google account ready, go to the following web address.
https://console.cloud.google.com/project

2. Once you have logged into your account, a dialog


box appears, in which select your Country and for the two
radial boxes, we selected ‘No‘ to wanting email updates and
‘Yes‘ to agree to their terms of service.

3. Click on Create Project Link.


lOMoARcPSD|27781631

4. Enter Project Name and Click on Create

The project creation process can take some time. You should receive a notification in the top
right-hand corner of the screen when it’s complete. If it doesn’t automatically appear after some
time, try refreshing the page.

5. Once it has appeared, click the project name.

6. On the side menu, select API's & Services

7. In Dashboard Option, Click on Enable


API's & Services
lOMoARcPSD|27781631

8. Search for Google Assistant API in Library


Section

9. Click on Enable Button

10. Now in APIs & Services Page, Select Credentials


Option.

11. Switch to the oauth consent screen

Enter name in Project Name shown to users

Click on Save
lOMoARcPSD|27781631

12. Click on Create Credentials button

13. In the drop-down menu,


Click on oauth Client ID

14. Set the Application Type to Other,


You can also change the name for client ID.
Or keep default as it is.

Click on Create button.


lOMoARcPSD|27781631

15. Now Download the Credentials file for our newly created oauth credential.

Downloaded file will be saved under /home/pi/Downloads folder.


Step 2: Account Settings
Now, go to the URL https://myaccount.google.com/activitycontrols, and activate the following
activity controls to ensure that the Google Assistant API works correctly.

 Web & App Activity


 Location History
 Device Information
 Voice & Audio Activity

Step 3: Register the Device Model


1. Now open https://www.console.actions.google.com
Select your Project (created in previous step), Or Even you can also create your new project with
this link.
lOMoARcPSD|27781631

2. Scroll Down to get Device Registration Option, Click on Device Registration.

3. Click the Register Model button to continue.

4. Set Product Name as a simple descriptor

Set Manufacturer Name as anything (because it


doesn’t hugely matter)

Set the Device Type as Speaker (as it matches with


our current project)

Note down this Device Model Id for later use.

Click on Register Model


Click on Next, then Click on Save Traits.
lOMoARcPSD|27781631

Step 4: Install the SDK and Sample Code on Raspberry PI


1. Update Raspberry Pi

2. Create a directory, and then Copy credential file (downloaded in previous step) to your
directory (with new name credentials.json)

3. Install Python3 and the Python 3 Virtual Environment to our Raspberry Pi.

$ sudo apt-get install python3-dev python3-venv #for Python 3

4. Install the package's system dependencies

$ sudo apt-get install portaudio19-dev libffi-dev libssl-dev


lOMoARcPSD|27781631

5. Enable python3 as our virtual environment variable

$ python3 -m venv env

6. Install the latest versions of pip and the setuptools.

$ env/bin/pip install setuptools --upgrade

7. Get into this new Python environment that we have set up

$ source env/bin/activate

8. Now Install all the packages that we need to install the Google Assistant Library

$ python -m pip install --upgrade google-assistant-library

$ python -m pip install --upgrade google-assistant-sdk[samples]

9. Install the Python authorization tool on Raspberry Pi

$ pip install --upgrade google-auth-oauthlib[tool]

10. To run the installed Google Authentication library, use following command.

$ google-oauthlib-tool --client-secrets /path/to/client_secret_client-id.json --scope


https://www.googleapis.com/auth/assistant-sdk-prototype --scope
https://www.googleapis.com/auth/gcm --save --headless
lOMoARcPSD|27781631

This command will generate a URL, Right Click on above URL, Copy it.

You will need to go to in your web browser, Paste above URL in address bar.

On this screen login to your Google account, if you have multiple accounts make sure you
select the one you set up your API key with.
Click on Allow

11. Copy the authentication code and paste it back into your terminal and press enter.
lOMoARcPSD|27781631

12. if the authentication was accepted, you received a message credentials saved

Step 5: Run the Sample Code


Finally, we have finished setting up everything we need to run the Google Assistant sample on
our Raspberry Pi. Run the software by running the following command on your Raspberry Pi.

$ googlesamples-assistant-pushtotalk --project_id my-dev-project --device_model_id


my-model-id

Use Project ID and Model ID created in previous steps.


lOMoARcPSD|27781631

Using the Google Assistant on the Raspberry Pi


 Now that we have finally fully authorized our Raspberry Pi as Google Assistant.
 So for next time login, if you want to run the Google Assistant software without having to
go through the entire tutorial, follow above steps
 Start a new terminal session and set it into virtual environment.(source env/bin/activate)
 To start up the push to talk sample, run the googlesamples-assistant-pushtotalk command,
this time we do not need to write in the project id or the device id as these were cached
when we first utilized the push to talk tool.
$ source env/bin/activate
$ googlesamples-assistant-pushtotalk

Getting the Google Assistant to start up on boot


Up to this time, you have got your Google Assistant up and running
Now you will likely want to get it to start up on boot rather than having to go to the effort of entering
the commands every time.
The easiest way to achieve this is to create a service for it. This service will allow the Google assistant
to run in the background on the Raspberry Pi and easily allow us to retain control over it.
Please follow below tutorial
https://drive.google.com/open?id=1dYSHka8jSAOaCrhGaKNQ28lA9GHaO8BY

That's all!!!
Thank you….
lOMoARcPSD|27781631

LED ON/OFF using Windows 10 IOT Core on Raspberry Pi

Hardware Requirements
 Raspberry Pi , SD Card
 LED
 Bread Board
 Jumper Wires
 Power supply
 Ethernet Cable / Wi Fi
 Monitor , Keyboard, Mouse

Software Requirements

• Windows 10 IOT Core installed in SD Card

• Windows 10 IOT Core Dashboard

• Visual Studio 2015 / 2017 (Community Edition - Free) with Universal Windows Platform
Development component installed.

Circuit Explanation
 Connect LED to Raspberry Pi
lOMoARcPSD|27781631

• Connect LED to Raspberry’s GPIO Pins using Breadboard.


• Longer Terminal (Positive Terminal) of LED is connected to Raspberry Pi’s GPIO Physical
Pin No 7.
• Shorter Terminal (Negative Terminal) of LED is connected to Raspberry Pi’s GPIO Physical
Pin No 6.

Component Terminal RPI Physical Pin Raspberry Function


Positive Terminal Pin 7 GPIO 4
LED
Negative Terminal Pin 6 GND

• Open Visual Studio 2015/ 2017 installed in your Laptop / PC with Universal
Windows Platform Development component.
• Create a New Project and add some code in it.
• Execute this Project on Raspberry Pi as remote machine.

using Windows.Devices.Gpio;

namespace LED_Blink_win
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private int red_state = 1;
private const int RED = 4;
private GpioPin redPin;
public MainPage()
{
this.InitializeComponent();
InitGPIO();
}

private void InitGPIO()


{
var gpio = GpioController.GetDefault();
redPin = gpio.OpenPin(RED);
redPin.Write(GpioPinValue.Low);
redPin.SetDriveMode(GpioPinDriveMode.Output);
}
lOMoARcPSD|27781631

private void Button_Click(object sender, RoutedEventArgs e)


{
if (red_state == 0)
{
redPin.Write(GpioPinValue.Low);
red_state = 1;
TXT1.Text = "LED OFF";
}
else if (red_state == 1)
{
redPin.Write(GpioPinValue.High);
red_state = 0;
TXT1.Text = "LED ON";
}
}

private void MainPage_Unloaded(object sender, object args)


{
redPin.Dispose();
}

}
}

That's all !!!


Thank you….

3|Page Manorama Darekar,Gurukul College.

Downloaded by C Kalpana ([email protected])

You might also like