Iot Practical PDF
Iot Practical PDF
Raspberry Pi 3 Model B
Bluetooth / Wifi model USB chip to connect processor
Broadcom Processor
4 USB port
GPIO 40 Pin
Audio/Video jack
Practical: 1
1. Power (3.3V,5V)
2. Ground
3. 12C (SDA,SCL)
Code:
Centerdash-pattern.py
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(26,GPIO.OUT)
list=[5,6,13,19,26]
for num in range((len(list) / 2)+1):
GPIO.output(list[num],GPIO.HIGH)
GPIO.output(list[len(list)-num-1],GPIO.HIGH)
time.sleep(0.05)
GPIO.output(list[num],GPIO.LOW)
GPIO.output(list[len(list)-num-1],GPIO.LOW)
time.sleep(0.05)
GPIO.cleanup()
OUTPUT
Running-pattern.py
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(26,GPIO.OUT)
list=[5,6,13,19,26]
print "Press q to Exit"
try:
while True:
if keyboard.is_pressed('q'):
break;
for num in range(len(list)):
GPIO.output(list[num],GPIO.HIGH)
time.sleep(0.05)
GPIO.output(list[num],GPIO.LOW)
time.sleep(0.05)
except KeyboardInterrupt:
pass
GPIO.output(5,GPIO.LOW)
GPIO.output(6,GPIO.LOW)
GPIO.output(13,GPIO.LOW)
GPIO.output(19,GPIO.LOW)
GPIO.output(26,GPIO.LOW)
GPIO.cleanup()
OUTPUT:
Practical No :03
Aim: Displaying Time over 4-Digit 7-Segment Display using Raspberry Pi.
Components:
1. 16Bit ADS1115
2. 12 M-M Jumper Wires
Display Description:
Above picture is pretty much self explanatory. Display model included in the kit
has 12 pins so as simple as it can be. 8 pins are attached to 7 segments of all digits
and single decimal point, other 4 are used as HIGH for every digit. If you connect
pin 12 to HIGH, the first digit will activate (9 = second, 8 = third, 6 =fourth). So if
we had 12, 9, 8 & 6 all connected to HIGH, and 7 & 4 LOW, all four digits would
display the number 1. This HIGH LOW scheme will be exactly opposite of this for
Common Cathode displays.
Connection Diagram:
Code:
Seg.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
try:
while True:
n = time.ctime()[11:13]+time.ctime()[14:16]
s = str(n).rjust(4)
for digit in range(4):
for loop in range(0,7):
if num[s[digit]][loop] == 0:
GPIO.output(segments[loop], 1)
else:
GPIO.output(segments[loop], 0)
if (int(time.ctime()[18:19])%2 == 0)
and (digit == 1):
GPIO.output(6, 0)
else:
GPIO.output(6, 1)
GPIO.output(digits[digit], 1)
time.sleep(0.001)
GPIO.output(digits[digit], 0)
except KeyboardInterrupt:
GPIO.cleanup()
OUTPUT:
Practical No 4
AIM: Raspberry Pi Based Oscilloscope.
Component List:
1. 10K Potentiometer
2. 16Bit ADS1115
3. Jumper Wire
Connection diagram (BCM Pins):
Install dependencies:
1. sudo apt-get update
2. sudo apt-get upgrade
3. sudo apt-get install build-essential python-dev python-smbus git
4. sudo apt-get install i2c-tools
Check i2c Address
Install Adafruit Library:
• cd TYIT/3-oscilloscope/
• Next, clone the Adafruit git folder for the library by running.
• Git clone https://github.com/adafruit/Adafruit_Python_ADS1x15
• Cd Adafruit_Python_ADS1x15
• Sudo python setup.py install
Install graph plotting and drawing libraries
• sudo apt-get install python-matplotlib
• sudo apt-get install python-pip
• sudo pip install drawnow
• sudo python scope.py
Code:
import time
import matplotlib.pyplot as plt
from drawnow import*
import Adafruit_ADS1x15
adc=Adafruit_ADS1x15.ADS1115()
GAIN=1
val=[]
cnt=0
plt.ion()
adc.start_adc(0, gain=GAIN)
print('Reading ADS1x15 Channel 0')
def makeFig():
plt.ylim(-5000,5000)
plt.title('Oscilloscope')
plt.grid(True)
plt.ylabel('ADC Ost_resultutputs')
plt.plot(val, 'ro-', label='Channel 0')
plt.legend(loc='lower right')
while (True):
value=adc.get_last_result()
print('channel 0: {0}'.format(value))
time.sleep(0.5)
val.append(int(value))
drawnow(makeFig)
plt.pause(0.000001)
cnt=cnt+1
if(cnt>50):
val.pop(0)
OUTPUT:
Practical No 5
Connection Diagram:
OUTPUT
PRACTICAL NO.6
AIM: Camera Connection and capturing Images
APPARATUS: Camera Module
THEORY: The Raspberry Pi Camera Board plugs directly into the CSI connector
on the Raspberry Pi. The camera is supported in the latest version of Raspbian,
the Raspberry Pi’s preferred operating system.
The Raspberry Pi Camera Board Features:
1. Fully Compatible with Both the Model A and Model B Raspberry Pi
2. 5MP Omnivision 5647 Camera Module
3. Still Picture Resolution: 2592 x 1944
4. Video: Supports 1080p @ 30fps, 720p @ 60fps and 640x480p 60/90
Recording
5. 15-pin MIPI Camera Serial Interface – Plugs Directly into the Raspberry Pi
Board
6. Size: 20 x 25 x 9mm
7. Weight 3g
8. Fully Compatible with many Raspberry Pi cases
PROCEDURE:
1. Locate the camera port and connect the camera:
2. Start up the Pi.
3. Open the Raspberry Pi Configuration Tool from the main menu.
4. Ensure the camera software is enabled. If it's not enabled, enable it and reboot
your Pi to begin.
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()
OUTPUT:
Practical No: 07
Aim: Controlling Raspberry Pi with Telegram Meesanger.
Telegram code:
import sys
import time
import telepot
#LED
def on(pin):
GPIO.output(pin, GPIO.HIGH)
def off(pin):
GPIO.output(pin, GPIO.LOW)
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)
def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']
if command == 'on':
bot.sendMessage(chat_id, on(5))
bot.sendMessage(chat_id, off(5))
else :
bot.sendMessage(chat_id, 'Echo:'+command)
bot = telepot.Bot('970040458:AAErVBNY3qrEoOhqqg4IxpKKqpZuQFvq5kY')
bot.message_loop(handle)
print('I am listening...')
while 1:
try:
time.sleep(10)
except KeyboardInterrupt:
print('')
print('Program Interrupted')
GPIO.cleanup()
exit()
except:
GPIO.cleanup()
OUTPUT:
Practical No:08