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

IOT Journal C

Iot notes

Uploaded by

Shaikh Kashaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

IOT Journal C

Iot notes

Uploaded by

Shaikh Kashaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

1

Practical No: 01 A

Aim: GPIO: Light the LED with Python .

Source Code:

import RPi.GPIO as a

from time import sleep

a.setmode(a.BOARD)

ledPin = 11

a.setup(ledPin, a.OUT)

a.output(ledPin, False)

try:

while True:

a.output(ledPin, True)

print("LED ON")

sleep(1)

a.output(ledPin, False)

print("LED OFF")

sleep(1)

finally:

a.output(ledPin, False)

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


2

a.cleanup()

Requirement:

1.Connecting Jumper Wires (Female to Female).

2.8 LED Display Board.

Hardware Connectivity:

1.Connect the GPIO11(pin 11) on Raspberry Pi.

2.Connect another end on 8 LED Board.

3.Connect the GPIO6(pin 6) on Raspberry Pi for Ground.

4.Connect another end on ground of 8 LED Board.

OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


3

Practical No: 01 B

Aim: Displaying different LED Patterns with Raspberry Pi

Source Code:

import RPi.GPIO as b

from time import time

b.setmode(b.BOARD)

b.setup(11,b.ouput)

b.setup(13,b.ouput)

b.setup(15,b.output)

for i in range(10):

b.output(11,True)

print("ON")

sleep(2)

b.ouput(11,False)

print("OFF")

sleep(2)

b.output(13,True)

print("ON")

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


4
sleep(2)

b.ouput(13,False)

print("OFF")

sleep(2)

b.output(15,True)

print("ON")

sleep(2)

b.ouput(15,False)

print("OFF")

sleep(2)

print("DONE")

b.cleanup()

Requirement:

1.Connecting Jumper Wires (Female to Female).

2.8 LED Display Board.

Hardware Connectivity:

1.Connect the GPIO11,GPIO13,GPIO15(pin 11 , pin13 , pin15 ) on Raspberry Pi.

2.Connect another end on 8 LED Board.

3.Connect the GPIO6(pin 6) on Raspberry Pi for Ground.

4.Connect another end on ground of 8 LED Board.

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


5

OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


6

Practical No: 02

Aim: Displaying Time over 4 Digit 7 Segment Display using

Raspberry Pi.

Source Code:

import sys

import time

import datetime

import RPi.GPIO as a

import tm1637

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)

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


7
Display.ShowDoublepoint(second % 2)

time.sleep(1)

Requirement:

1.TM1637 4-digit seven segment Display board

2.Connecting Jumper Wires (Female to Female).

Hardware Connectivity:

1. Connect your 4 digit 7 segment display with Raspberry Pi's GPIO Pins.

TM16737 Board Function Rpi Physical pin Raspberry Pi Function

GND Ground 6 GND

VCC Power 2 Power Supply

DIO Data In 18 GPIO24

CLK Clock 16 GPIO23

Other Requirement:

1. Now to download libraries, open Web Browser on your Raspberry Pi and log on to the
following link: https://github.com/timwaizenegger/raspberrypi-examples/tree/master/actor-led-
7segment-4numbers . Click on the actor-led-7segment-4numbers.zip folder and Now click on
Download Button to download the file.

2. Now on your rpi move to /home/pi/Downloads/ location to find the zip file downloaded.

3. Unzip the file and try to execute the different example codes present in that folder in Python

Idle.

4. create a new file, write the code given below and save it in the same folder

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


8
OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


9
Practical No: 03

Aim: Capturing Images with Raspberry Pi and Pi Camera.

Source Code:

from time import sleep

from picamera import PiCamera

camera = PiCamera()

camera.resolution = (1280, 720)

camera.start_preview()

sleep(2)

camera.capture('/home/pi/Pictures/newImage.jpg')

camera.stop_preview()

Requirement :

1. Raspberry Pi Camera Module

Hardware Connectivity:

1.First you have to connect Camera Module to Raspberry Pi ‘s Camera port.

2.Then open Terminal window and type command as follow:

# sudo apt-get update

# sudo raspi-config

3.Go to Interface Option and enable Camera and I2C option.then click on Done option.

Select Interfacing Options » Camera » Enable

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


10
Select Interfacing Options » I2C » Enable

4. After this reboot the system, using command:

# sudo reboot

OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


11
Practical No: 04

Aim: GPS Module Interfacing with Raspberry Pi.

Commands:

Open Terminal Window and type the following command

1. To know to which USB port the GPS module is attached:

# ls /dev/ttyUSB*

2. Select USB Port

# sudo cat /dev/ttyUSB0

3. To install gpsd, make sure your Pi has an Internet connection and run the following
commands:

# sudo apt-get update

# sudo apt-get install gpsd

4. You will need to enable the gpsd systemd service by running the following commands:

# sudo systemctl enable gpsd.socket

# sudo systemctl start gpsd.socket

5. After that use the gpsd command

# gpsd

6. Try running gpsmon to get a live-streaming update of GPS data!

# gpsmon

cgps which gives a less detailed, but still quite nice output

# cgps -s

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


12
(NOTE:if your got command stuck use “CTRL + z” for exit that command)

7.You can abort gpsd by the following command

# sudo killall gpsd

Requirement:

1. GPS module.

2. USB to TTL converter.

3. Connecting jumper wires (female to female).

Hardware Connectivity :

1. Connect the VCC Pin of GPS Module to 3.3V Pin of USB to TTL converter

2. Connect the GND Pin of GPS Module to GND Pin of USB to TTL converter

3. Connect the Tx Pin of GPS Module to Rx Pin of USB to TTL converter

4. Connect the Rx Pin of GPS Module to Tx Pin of USB to TTL converter.

5. Lastly connect the USB to TTL converter to USB port of Raspberry Pi.

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


13
OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


14

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


15
Practical No: 05

Aim: RFID Module Interfacing with Raspberry Pi.

Source Code:

1.For Writing

import RPi.GPIO as b

from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:

text = input('New Data : ')

print("Now place your tag to write")

reader.write(text)

print("Written")

finally:

b.cleanup()

2. For Reading

import RPi.GPIO as b

from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:

id, text = reader.read()

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


16
print(id)

print(text)

finally:

b.cleanup()

Requirement:

1. RFID Reader (RC 522)

2. RFID Tags or Cards

3. Jumper wires (Female to Female)

Hardware Connectivity:

RFID READER BOARD RPi PHYSICAL PIN


PIN

SDA 24

SCK 23

MOSI 19

MISO 21

GND 6

RST 22

3.3V 1

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


17
Other Requirement:

1. To enable P4 SPI :

# sudo raspi-config

2.To Restart your Paspberry Pi

# sudo reboot

3.To see if spi_bcm2835 is listed

# lsmod | grep spi

4. To update

# sudo apt-get update

5. Setting up the RFID reader

# sudo apt-get install python3.dev python3.pip

6. spidev library helps handle interactions with the SPI

# sudo pip3 install spidev

7. MFRC522,py which is an implementation of the RFID RC255 interface

# sudo pip3 install mfrc522

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


18
OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


19
Practical No: 06

Aim: Controlling Raspberry Pi with Telegram App

Source Code:

import time,datetime

import RPi.GPIO as b

import telepot

from telepot.loop import MessageLoop

LED1=31

LED2=33

LED3=35

LED4=37

now=datetime.datetime.now()

b.setmode(b.BOARD)

b.setwarnings(False)

b.setup(LED1,b.OUT)

b.output(LED1,0)

b.setup(LED2,b.OUT)

b.output(LED2,0)

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


20
b.setup(LED3,b.OUT)

b.output(LED3,0)

b.setup(LED4,b.OUT)

b.output(LED4,0)

def action(msg):

chat_id=msg['chat']['id']

command=msg['text']

print('Recevied : %s'% command)

if 'on' in command:

message="on"

if 'LED1' in command:

message=message+"LED1"

b.output(LED1,1)

if 'LED2' in command:

message=message+"LED2"

b.output(LED2,1)

if 'LED3' in command:

message=message+"LED3"

b.output(LED3,1)

if 'LED4' in command:

message=message+"LED4"

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


21
b.output(LED4,1)

if 'all' in command:

message=message+"all"

b.output(LED1,1)

b.output(LED2,1)

b.output(LED3,1)

b.output(LED4,1)

message=message+"light(s)"

telegram_bot.sendMessage(chat_id,message)

if 'off' in command:

message="off"

if 'LED1' in command:

message=message+"LED1"

b.output(LED1,0)

if 'LED2' in command:

message=message+"LED2"

b.output(LED2,0)

if 'LED3' in command:

message=message+"LED3"

b.output(LED3,0)

if 'LED4' in command:

message=message+"LED4"

b.output(LED4,0)

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


22
if 'all' in command:

message=message+"all"

b.output(LED1,0)

b.output(LED2,0)

b.output(LED3,0)

b.output(LED4,0)

message=message+"light(s)"

telegram_bot.sendMessage(chat_id,message)

16 pt

telegram_bot=telepot.Bot('6489494048:AAEPlW7QpyIW_ne8KNr1UvILgw2jkANvens')

print(telegram_bot.getMe())

MessageLoop(telegram_bot,action).run_as_thread()

print('up and Running...........................')

while 1:

time.sleep(10)

Requirement:

1. Jumper wires (F to F).

2. 8 LED Light Board.

3. Smartphone with Installed Telegram App.

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


23
Hardware Connectivity:

LED Terminal Pin Number GPIO Number

led_pin1 Pin 31 GPIO 6

led_pin2 Pin 33 GPIO13

led_pin3 Pin 35 GPIO19

led_pin4 Pin 37 GPIO26

Negative(ground) Pin 9 GND

Other Requirement:

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

2. Install Telegram Bot on Raspberry Pi.

# sudo apt-get install python.pip

# sudo pip install telepot

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


24
OUTPUT:

Practical No: 07

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


25

Aim: IOT Based Home Automation using raspberry Pi.

Commands:

1.Installation of WebIOPi:

To update the raspberry Pi below commands and then reboot the RPi:

1. sudo apt-get update

2. sudo reboot

2. Now download the latest version of WebIOPi from the following link on your raspberry
pi:

http://webiopi.trouch.com/DOWNLOADS.html

3. move to the downloads folder using the command:

cd /home/pi/Downloads/

4. extract the file and adapt x.y.z with the version you download:

1. tar xvzf WebIOPi-x.y.z.tar.gz

2. cd WebIOPi-x.y.z

5. Below commands are used to install patch while still in the WebIOPi directory, run:

1. wget https://raw.githubusercontent.com/doublebind/raspi/master/webiopi-pi2bplus.patch

2. patch -p1 -i webiopi-pi2bplus.patch

6. run the setup installation for the WebIOPi using:

1. sudo ./setup.sh

7. reboot your pi:


SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)
26
1. sudo reboot

Test WebIOPi Installation:

For instance, to start with verbose output and the default config file:

1. sudo webiopi -d -c /etc/webiopi/config

7. start/stop the background service, the configuration will be loaded from

/etc/webiopi/config.

1. sudo /etc/init.d/webiopi start

2. sudo /etc/init.d/webiopi stop

7.NOTE:

You can also start/stop the background service, the configuration will be loaded from

/etc/webiopi/config.

1. # sudo /etc/init.d/webiopi start

2. # sudo /etc/init.d/webiopi stop

8. Ip address

cmd - # ifconfig ( copy inet/ip address )

https;//copiedIPaddress:8000 (eg: http://192.168.0.123:8000)

9.then enter userID and Password:

username: webiopi

password: raspberry

After then click on the GPIO header link.

Wiring up your circuit:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


27
For this test, we will be connecting an LED to GPIO 17, so go on and set GPIO 17 as an output.

Requirement:

1. 8LED light board

2. Jumper wires (Female to Female).

Hardware Connectivity:

1. Connect to Physical PIN 6 for GND.

2.Connect to Physical PIN 17 with 8 LED Light Board.

Other Requirement:

1. To update the raspberry Pi below commands and then reboot the RPi:

1. #sudo apt-get update

2. #sudo apt-get upgrade

3. #sudo reboot

2. Now download the latest version of WebIOPi from the following link on your raspberry
pi:

http://webiopi.trouch.com/DOWNLOADS.html

OUTPUT:

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


28

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)


29

SHAH MOHAMMAD WASEEK FIT2148(BSC-IT)

You might also like