Iot 2019
Iot 2019
import time
GPIO.setmode(GPIO.BCM)
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.LOW)
SleepTimeL = 2
# main loop
try:
GPIO.output(5, GPIO.HIGH)
print ("ONE")
time.sleep(SleepTimeL);
GPIO.output(6, GPIO.HIGH)
print ("TWO")
time.sleep(SleepTimeL);
GPIO.output(13, GPIO.HIGH)
print ("THREE")
time.sleep(SleepTimeL);
GPIO.output(19, GPIO.HIGH)
print ("FOUR")
time.sleep(SleepTimeL);
GPIO.output(26, GPIO.HIGH)
print ("FIVE")
time.sleep(SleepTimeL);
GPIO.cleanup()
except KeyboardInterrupt:
print ("Quit")
#SLIP 1: Q2) - Interface Raspberry Pi with RFID and write a program to read the RFID.
import time
try:
while True:
print("Acces Granted")
else:
print("Access Denied")
finally:
print("Bye")
#SLIP 2 : Q1) 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.
#Image
import picamera
camera = picamera.PiCamera()
#set resolution
camera.brightness = 60
camera.start_preview()
sleep(5)
#store image
camera.capture('image1.jpeg’)
camera.stop_preview()
#$ sudo raspistill /home/pi/Desktop/image.jpg (to capture a picture; raspistill loads the image
#Video
import picamera
camera = picamera.PiCamera()
print()
camera.start_recording("demo.h264")
camera.wait_recording(20)
#stop recording
camera.stop_recording()
camera.close()
#SLIP 3 - Q1)-Interface Raspberry Pi with RFID and write a program to read the RFID
import time
ser = serial.Serial ("/dev/ttyUSB0") #Open named port "(To check the port, ls
/dev/ttyUSB*)"
try:
while True:
print("Acces Granted")
else:
print("Access Denied")
finally:
print("Bye")
#Q2). 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
#Image
import picamera
camera = picamera.PiCamera()
#set resolution
camera.brightness = 60
camera.start_preview()
sleep(5)
#store image
camera.capture('image1.jpeg’)
camera.stop_preview()
#$ sudo raspistill /home/pi/Desktop/image.jpg (to capture a picture; raspistill loads the image
#Video
import picamera
camera = picamera.PiCamera()
print()
camera.start_recording("demo.h264")
camera.wait_recording(20)
#stop recording
camera.stop_recording()
camera.close()
#SLIP 5 - Interface Raspberry Pi with Fingerprint Module and write a program to capture and verify
finger print.
1) sudo bash
4) ls /dev/ttyUSB*
mport time
RS =18
EN =23
D4 =24
D5 =25
D6 =8
D7 =7
enrol=5
delet=6
inc=13
dec=19
led=26
HIGH=1
LOW=0
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(RS, gpio.OUT)
gpio.setup(EN, gpio.OUT)
gpio.setup(D4, gpio.OUT)
gpio.setup(D5, gpio.OUT)
gpio.setup(D6, gpio.OUT)
gpio.setup(D7, gpio.OUT)
gpio.setup(led, gpio.OUT)
try:
if ( f.verifyPassword() == False ):
except Exception as e:
exit(1)
def begin():
lcdcmd(0x33)
lcdcmd(0x32)
lcdcmd(0x06)
lcdcmd(0x0C)
lcdcmd(0x28)
lcdcmd(0x01)
time.sleep(0.0005)
def lcdcmd(ch):
gpio.output(RS, 0)
gpio.output(D4, 0)
gpio.output(D5, 0)
gpio.output(D6, 0)
gpio.output(D7, 0)
if ch&0x10==0x10:
gpio.output(D4, 1)
if ch&0x20==0x20:
gpio.output(D5, 1)
if ch&0x40==0x40:
gpio.output(D6, 1)
if ch&0x80==0x80:
gpio.output(D7, 1)
gpio.output(EN, 1)
time.sleep(0.005)
gpio.output(EN, 0)
# Low bits
gpio.output(D4, 0)
gpio.output(D5, 0)
gpio.output(D6, 0)
gpio.output(D7, 0)
if ch&0x01==0x01:
gpio.output(D4, 1)
if ch&0x02==0x02:
gpio.output(D5, 1)
if ch&0x04==0x04:
gpio.output(D6, 1)
if ch&0x08==0x08:
gpio.output(D7, 1)
gpio.output(EN, 1)
time.sleep(0.005)
gpio.output(EN, 0)
def lcdwrite(ch):
gpio.output(RS, 1)
gpio.output(D4, 0)
gpio.output(D5, 0)
gpio.output(D6, 0)
gpio.output(D7, 0)
if ch&0x10==0x10:
gpio.output(D4, 1)
if ch&0x20==0x20:
gpio.output(D5, 1)
if ch&0x40==0x40:
gpio.output(D6, 1)
if ch&0x80==0x80:
gpio.output(D7, 1)
gpio.output(EN, 1)
time.sleep(0.005)
gpio.output(EN, 0)
# Low bits
gpio.output(D4, 0)
gpio.output(D5, 0)
gpio.output(D6, 0)
gpio.output(D7, 0)
if ch&0x01==0x01:
gpio.output(D4, 1)
if ch&0x02==0x02:
gpio.output(D5, 1)
if ch&0x04==0x04:
gpio.output(D6, 1)
if ch&0x08==0x08:
gpio.output(D7, 1)
gpio.output(EN, 1)
time.sleep(0.005)
gpio.output(EN, 0)
def lcdclear():
lcdcmd(0x01)
def lcdprint(Str):
l=0;
l=len(Str)
for i in range(l):
lcdwrite(ord(Str[i]))
def setCursor(x,y):
if y == 0:
n=128+x
elif y == 1:
n=192+x
lcdcmd(n)
def enrollFinger():
lcdcmd(1)
lcdprint("Enrolling Finger")
time.sleep(2)
lcdprint("Place Finger")
pass
f.convertImage(0x01)
result = f.searchTemplate()
positionNumber = result[0]
if ( positionNumber >= 0 ):
lcdcmd(1)
lcdprint("Finger ALready")
lcdcmd(192)
time.sleep(2)
return
print('Remove finger...')
lcdcmd(1)
lcdprint("Remove Finger")
time.sleep(2)
lcdcmd(1)
lcdprint("Place Finger")
lcdcmd(192)
pass
f.convertImage(0x02)
if ( f.compareCharacteristics() == 0 ):
lcdcmd(1)
time.sleep(2)
return
f.createTemplate()
positionNumber = f.storeTemplate()
lcdcmd(1)
lcdprint("Stored at Pos:")
lcdprint(str(positionNumber))
lcdcmd(192)
lcdprint("successfully")
time.sleep(2)
def searchFinger():
try:
#pass
time.sleep(.5)
return
f.convertImage(0x01)
result = f.searchTemplate()
positionNumber = result[0]
accuracyScore = result[1]
if positionNumber == -1 :
lcdcmd(1)
time.sleep(2)
return
else:
lcdcmd(1)
lcdprint("Found at Pos:")
lcdprint(str(positionNumber))
time.sleep(2)
except Exception as e:
print('Operation failed!')
exit(1)
def deleteFinger():
positionNumber = 0
count=0
lcdcmd(1)
lcdprint("Delete Finger")
lcdcmd(192)
lcdprint("Position: ")
lcdcmd(0xca)
lcdprint(str(count))
if gpio.input(inc) == False:
count=count+1
if count>1000:
count=1000
lcdcmd(0xca)
lcdprint(str(count))
time.sleep(0.2)
if count<0:
count=0
lcdcmd(0xca)
lcdprint(str(count))
time.sleep(0.2)
positionNumber=count
if f.deleteTemplate(positionNumber) == True :
print('Template deleted!')
lcdcmd(1)
lcdprint("Finger Deleted");
time.sleep(2)
begin()
lcdcmd(0x01)
lcdprint("FingerPrint ")
lcdcmd(0xc0)
lcdprint("Interfacing ")
time.sleep(3)
lcdcmd(0x01)
lcdprint("Circuit Digest")
lcdcmd(0xc0)
time.sleep(3)
flag=0
lcdclear()
while 1:
gpio.output(led, HIGH)
lcdcmd(1)
lcdprint("Place Finger")
if gpio.input(enrol) == 0:
gpio.output(led, LOW)
enrollFinger()
elif gpio.input(delet) == 0:
gpio.output(led, LOW)
while gpio.input(delet) == 0:
time.sleep(0.1)
deleteFinger()
else:
searchFinger()
#SLIP 6- Q1) Install Windows IoT Core on Raspberry Pi and using GPIO blink LED using sample
program.
Step 2 : Download the IOt dashboard win 10 and then run the install and open dashboard and then
setup new device
Step 3 : Connect your Iot device and then click next next and DONE"""
import time
GPIO.setmode(GPIO.BCM)
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.LOW)
# main loop
try:
GPIO.output(5, GPIO.HIGH)
print ("ONE")
time.sleep(SleepTimeL);
GPIO.output(6, GPIO.HIGH)
print ("TWO")
time.sleep(SleepTimeL);
GPIO.output(13, GPIO.HIGH)
print ("THREE")
time.sleep(SleepTimeL);
GPIO.output(19, GPIO.HIGH)
print ("FOUR")
time.sleep(SleepTimeL);
GPIO.output(26, GPIO.HIGH)
print ("FIVE")
time.sleep(SleepTimeL);
GPIO.cleanup()
except KeyboardInterrupt:
print ("Quit")
#Q2)Interface Raspberry Pi with 4-digit Seven Segment module and write a program to display
current time on it.
import tm1637
try:
import thread
except ImportError:
# Initialize the clock (GND, VCC=3.3V, Example Pins are DIO-20 and CLK21)
try:
Display.StartClock(military_time=False)
sleep(5)
Display.ShowDoublepoint(False)
sleep(5)
loops = 3
Display.SetBrightness(i / 10.0)
sleep(0.5)
loops -= 1
Display.StopClock()
thread.interrupt_main()
except KeyboardInterrupt:
Display.cleanup()
"ALTERNATIVE"
import math
import RPi.GPIO as IO
import threading
# IO.setwarnings(False)
IO.setmode(IO.BCM)
ADDR_AUTO = 0x40
ADDR_FIXED = 0x44
STARTADDR = 0xC0
# DEBUG = False
class TM1637:
__doublePoint = False
__Clkpin = 0
__Datapin = 0
__currentData = [0, 0, 0, 0]
self.__Clkpin = CLK
self.__Datapin = DIO
self.__brightness = brightness
IO.setup(self.__Clkpin, IO.OUT)
IO.setup(self.__Datapin, IO.OUT)
def cleanup(self):
self.StopClock()
self.Clear()
IO.cleanup()
def Clear(self):
b = self.__brightness
point = self.__doublePoint
self.__brightness = 0
self.__doublePoint = False
self.Show(data)
self.__brightness = b
self.__doublePoint = point
s = str(i)
self.Clear()
self.Show1(i, int(s[i]))
self.__currentData[i] = data[i]
self.start()
self.writeByte(ADDR_AUTO)
self.br()
self.writeByte(STARTADDR)
for i in range(0, 4):
self.writeByte(self.coding(data[i]))
self.br()
self.writeByte(0x88 + int(self.__brightness))
self.stop()
return # error
self.__currentData[DigitNumber] = data
self.start()
self.writeByte(ADDR_FIXED)
self.br()
self.writeByte(STARTADDR | DigitNumber)
self.writeByte(self.coding(data))
self.br()
self.writeByte(0x88 + int(self.__brightness))
self.stop()
max_brightness = 7.0
brightness = 0
if(self.__brightness != brightness):
self.__brightness = brightness
self.Show(self.__currentData)
def ShowDoublepoint(self, on):
if(self.__doublePoint != on):
self.__doublePoint = on
self.Show(self.__currentData)
IO.output(self.__Clkpin, IO.LOW)
IO.output(self.__Datapin, IO.HIGH)
else:
IO.output(self.__Datapin, IO.LOW)
IO.output(self.__Clkpin, IO.HIGH)
IO.output(self.__Clkpin, IO.LOW)
IO.output(self.__Datapin, IO.HIGH)
IO.output(self.__Clkpin, IO.HIGH)
IO.setup(self.__Datapin, IO.IN)
while(IO.input(self.__Datapin)):
sleep(0.001)
if(IO.input(self.__Datapin)):
IO.setup(self.__Datapin, IO.OUT)
IO.output(self.__Datapin, IO.LOW)
IO.setup(self.__Datapin, IO.IN)
IO.setup(self.__Datapin, IO.OUT)
def start(self):
IO.output(self.__Clkpin, IO.HIGH)
IO.output(self.__Datapin, IO.HIGH)
IO.output(self.__Datapin, IO.LOW)
IO.output(self.__Clkpin, IO.LOW)
def stop(self):
IO.output(self.__Clkpin, IO.LOW)
IO.output(self.__Datapin, IO.LOW)
IO.output(self.__Clkpin, IO.HIGH)
IO.output(self.__Datapin, IO.HIGH)
def br(self):
"""terse break"""
self.stop()
self.start()
if(self.__doublePoint):
pointData = 0x80
else:
pointData = 0
if(data == 0x7F):
data = 0
else:
return data
https://github.com/johnlr/raspberrypi-tm1637"""
self.ShowDoublepoint(True)
t = localtime()
hour = t.tm_hour
if not military_time:
d1 = hour % 10
d2 = t.tm_min // 10
d3 = t.tm_min % 10
self.Show(digits)
# print digits
if (not self.__stop_event.is_set()):
sleep(1)
self.__stop_event = threading.Event()
self.__clock_thread = threading.Thread(
target=self.clock, args=(military_time,))
self.__clock_thread.start()
def StopClock(self):
try:
except:
if __name__ == "__main__":
display.Clear()
digits = [1, 2, 3, 4]
display.Show(digits)
scrap = raw_input()
display.Clear()
display.Show1(1, 3)
sleep(0.5)
display.Show1(2, 2)
sleep(0.5)
display.Show1(3, 1)
sleep(0.5)
display.Show1(0, 4)
scrap = raw_input()
display.ShowDoublepoint(True)
sleep(0.2)
print ("Brightness Off")
display.SetBrightness(0)
sleep(0.5)
display.SetBrightness(1)
sleep(0.5)
display.SetBrightness(0.3)
sleep(0.3)