Iot pdf code output
Iot pdf code output
P3 blinking led
#Blink LED Program
#Connect the LED to GPIO 22 Pin
#LED Blink Progarm
#Connect the LED to GPIO22 (i.e. Physical Pin15)
#import GPIO and time library
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM) ledPin = 22 #setup the ledPin(i.e. GPIO22) as output
GPIO.setup(ledPin, GPIO.OUT)
GPIO.output(ledPin, False)
#set the Pin mode you will be working with
#this is GPIO22 pin i.e Physical Pin15
try:
while True:
GPIO.output(ledPin, True) #Set the LED Pin to HIGH
print("LED ON")
sleep(1) #Wait for 1 sec
GPIO.output(ledPin, False) #Set the LED Pin to LOW
print("LED OFF")
sleep(1) #wait for 1 sec
finally:
#reset the GPIO Pins
GPIO.output(ledPin, False)
GPIO.cleanup()
import time
from pyfingerprint.pyfingerprint import PyFingerprint
import RPi.GPIO as gpio
enrol=5
delet=6
led=26
HIGH=1
LOW=0
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(enrol, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(delet, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(led, gpio.OUT)
try:
f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
if ( f.verifyPassword() == False ):
raise ValueError('The given fingerprint sensor password is wrong!')
except Exception as e:
print('Exception message: ' + str(e))
exit(1)
print('Currently used finger templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
def enrollFinger():
print('Waiting for finger...')
while ( f.readImage() == False ):
pass
f.convertImage(0x01)
result = f.searchTemplate()
positionNumber = result[0]
if ( positionNumber >= 0 ):
print('Finger already exists at position #' + str(positionNumber))
time.sleep(2)
return
print('Remove finger...')
time.sleep(2)
print('Waiting for same finger again...')
while ( f.readImage() == False ):
pass
f.convertImage(0x02)
if ( f.compareCharacteristics() == 0 ):
print ("Fingers do not match")
time.sleep(2)
return
f.createTemplate()
positionNumber = f.storeTemplate()
print('Finger enrolled successfully!')
print('New template position #' + str(positionNumber))
time.sleep(2)
def searchFinger():
try:
print('Waiting for finger...')
while( f.readImage() == False ):
#pass
time.sleep(.5)
return
f.convertImage(0x01)
result = f.searchTemplate()
positionNumber = result[0]
accuracyScore = result[1]
if positionNumber == -1 :
print('No match found!')
time.sleep(2)
return
else:
print('Found finger at position #' + str(positionNumber))
time.sleep(2)
except Exception as e:
print('Operation failed!')
print('Exception message: ' + str(e))
exit(1)
def deleteFinger():
positionNumber = 0
count=0
while gpio.input(delet) == True: # here delet key means ok
positionNumber = input('Please enter the template position you want to delete: ')
positionNumber = int(positionNumber)
if f.deleteTemplate(positionNumber) == True :
print('Template deleted!')
time.sleep(1)
print('Currently used finger templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
time.sleep(1)
return
print ("Edkits Electronics Welcomes You ")
time.sleep(3)
flag=0
while 1:
gpio.output(led, HIGH)
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()
P6 GPS interfacing
import serial #import serial pacakge
from time import sleep
import webbrowser #import package for opening link in browser
import sys #import system package
def GPS_Info():
global NMEA_buff
global lat_in_degrees
global long_in_degrees
nmea_time = []
nmea_latitude = []
nmea_longitude = []
nmea_time = NMEA_buff[0] nmea_latitude = NMEA_buff[1] nmea_longitude = NMEA_buff[3]
#extract time from GPGGA string
#extract latitude from GPGGA string
#extract longitude from GPGGA string
print("NMEA Time: ", nmea_time,'\n')
print ("NMEA Latitude:", nmea_latitude,"NMEA Longitude:", nmea_longitude,'\n')
lat = float(nmea_latitude) #convert string into float for calculation
longi = float(nmea_longitude) #convertr string into float for calculation
lat_in_degrees = convert_to_degrees(lat) #get latitude in degree decimal format
long_in_degrees = convert_to_degrees(longi) #get longitude in degree decimal format
#convert raw NMEA string into degree decimal form at
def convert_to_degrees(raw_value):
decimal_value = raw_value/100.00
degrees = int(decimal_value)
mm
_
mmmm = (decimal
_
value - int(decimal_value))/0.6
position = degrees + mm_mmmm
position = "%.4f" %(position)
return position
gpgga_info = "$GPGGA,"
ser = serial.Serial ("/dev/ttyUSB0") GPGGA_buffer = 0
NMEA_buff = 0
lat_in_degrees = 0
long_in_degrees = 0
#Open port with baud rate
try:
while True:
received_data = (str)(ser.readline ()) GPGGA_data_available =
received_data.find(gpgga_info) #read NMEA string received
#check for NMEA GPGGA string
if (GPGGA_data_available>0):
GPGGA_buffer = received_data.split("$GPGGA,",1)[1] #store data coming after "$GPGGA,"
NMEA_buff = (GPGGA_buffer.split(',')) #store comma separated data in buffer
GPS_Info() #get time, latitude, longitude
print("lat in degrees:", lat_in_degrees," long in degree: ", long_in_degrees, '\n')
map_link = 'http://maps.google.com/?q=' + lat_in_degrees + ',' + long_in_degrees
#create link to plot location on Google map
print("<<<<<<<<press ctrl+c to plot location on google maps>>>>>>\n")
#press ctrl+c to plot on map and exit
print("
------------------------------------------------------------\n")
except KeyboardInterrupt:
webbrowser.open(ma p_link) sys.exit(0)
#open current position information in google map
#end of file