





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















import RPi.GPIO as GPIO import time
GPIO.setmode(GPIO.BOARD) GPIO.setwarning(False)
GPIO.setup(18,GPIO.OUT) GPIO.setup(16,GPIO.OUT) GPIO.setup(15,GPIO.OUT) GPIO.setup(13,GPIO.OUT)
def pattern(): while(True): print(“All LED on “) GPIO.output(18,GPIO.HIGH) GPIO.output(16,GPIO.HIGH) GPIO.output(15,GPIO.HIGH) GPIO.output(13,GPIO.HIGH) time.sleep(1) GPIO.output(18,GPIO.LOW) GPIO.output(16,GPIO.LOW) GPIO.output(15,GPIO.LOW) GPIO.output(13,GPIO.LOW)
print(“Two LED on and two LED off “) GPIO.output(18,GPIO.HIGH) GPIO.output(16,GPIO.LOW) GPIO.output(15,GPIO.HIGH) GPIO.output(13,GPIO.LOW) time.sleep(1) GPIO.output(18,GPIO.LOW) GPIO.output(16,GPIO.HIGH) GPIO.output(15,GPIO.LOW) GPIO.output(13,GPIO.HIGH)
print(“Three LED on and one LED off or One LED on three LED off “) GPIO.output(18,GPIO.HIGH) GPIO.output(16,GPIO.HIGH) GPIO.output(15,GPIO.HIGH) GPIO.output(13,GPIO.LOW) time.sleep(1) GPIO.output(18,GPIO.LOW) GPIO.output(16,GPIO.LOW)
GPIO.output(15,GPIO.LOW) GPIO.output(13,GPIO.HIGH)
print(“One LED on and two off “) GPIO.output(18,GPIO.HIGH) GPIO.output(16,GPIO.LOW) GPIO.output(15,GPIO.HIGH) GPIO.output(13,GPIO.LOW) time.sleep(1) GPIO.output(18,GPIO.LOW) GPIO.output(16,GPIO.HIGH) GPIO.output(15,GPIO.LOW) GPIO.output(13,GPIO.HIGH)
import random import time import datetime import RPi.GPIO as GPIO import tm
Display=tm1637,TM1637(23,24,tm1637,BRIGHT_TYPICAL) Display.Clear() Display.SetBrightness(1)
while(True): n1=random.randint(0,9) n2=random.randint(0,9) n3=random.randint(0,9) n4=random.randint(0,9) currentvalue=[n1,n2,n3,n4] Display.Show(currentvalue) time.sleep(1)
print(„Channel 0:{0}‟.format(value)) time.sleep(0.5) val.append(int(value)) drawnow(makeFig) plt.pause(_000001) cnt=cnt+1 if(cnt>50): val.pop(0)
Install telegram bot on raspberry pi :- $ sudo apt-get install python-pip
i. Install Telegram app on smart phone from playstore. ii. Open Telegram,request the bot father to create a new bot. iii. Search “BotFather” and click on it.
vi. Provide the name for new bot that we want to create,after that give same name followed by _bot postfix (e.g. tyit_bot). vii. After this process the BotFather will give a Token for access.
viii. Now search for the bot that we have created.
ix. Now give the command to LEDs as per your requirements.
import time, datetime import RPi.GPIO
as GPIO import telepot from telepot.loop import MessageLoop
green = 6 yellow = 13 red = 19 white = 26 now = datetime.datetime.now() GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
##LED White
GPIO.setup(white, GPIO.OUT)
GPIO.output(white, 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'] command = msg['text'] print ('Received: %s' % command) if 'on' in command: message = "on" if 'white' in command: message = message
import sys import time from PyFingerprint import *
try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except:
e = sys.exc_info()[1] print 'The fingerprint sensor could not be
initialized!' print 'Exception message: ' +
str(e.message) exit(1)
Remove finger... Waiting for same finger again... Finger enrolled successfully! New template position #
import hashlib import sys from PyFingerprint import *
sensor try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!')
except: e = sys.exc_info()[1] print 'The fingerprint sensor could not be initialized!' print 'Exception message: ' + str(e.message) exit(1)
print 'Currently stored templates: ' + str(f.getTemplateCount())
hash try: print 'Waiting for finger...'
while ( f.readImage() == False ): pass
charbuffer 1 f.convertImage(0x01) ## Searchs template result = f.searchTemplate() positionNumber = result[0] accuracyScore = result[1] if ( positionNumber == -1 ): print 'No match found!' exit(0) else: print 'Found template at position #' + str(positionNumber) print 'The accuracy score is: ' + str(accuracyScore)
f.loadTemplate(positionNumber, 0x01)
f.downloadCharacteristics(0x01)
template: ' + hashlib.sha256(str(characterics)).hexdigest() except: e = sys.exc_info()[1] print 'Fingerprint read failed!'
print 'Exception message: ' + str(e.message) exit(1)
root@raspberrypi:/usr/share/doc/python-fingerprint/examples# sudo python example_search.py Currently used templates: 10/1000 Waiting for finger... Found template at position #6 The accuracy score is: 105 SHA-2 hash of template: 5a6b7e8f7fe2fa4dd5b4d814de3c3ccb93bedab84a72df89fb68b2e8fdffd88d root@raspberrypi:/usr/share/doc/python-fingerprint/examples# sudo python example_search.py Currently used templates: 10/1000 Waiting for finger... Found template at position #8 The accuracy score is: 127 SHA-2 hash of template: 093c4e2fb69b5f216cc82a44ec84c74359885a147f9d0c7021910233cb24d42f
import sys from PyFingerprint import *
try: f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000) if ( f.verifyPassword() == False ): raise ValueError('The given fingerprint sensor password is wrong!') except: e = sys.exc_info()[1] print 'The fingerprint sensor could not be initialized!' print 'Exception message: ' + str(e.message) exit(1)
print 'Currently stored templates: ' + str(f.getTemplateCount())
try: page = raw_input('Please enter the index page (0, 1, 2, 3) you want to see: ') page = int(page) tableIndex = f.getTemplateIndex(page) for i in range(0, len(tableIndex)): print 'Template at position #' + str(i) + ' is used: ' + str(tableIndex[i]) except: e = sys.exc_info()[1] print 'Read out table index failed!' print 'Exception message: ' + str(e.message) exit(1)
root@raspberrypi:/usr/share/doc/python-fingerprint/examples# sudo python example_index.py Currently used templates: 10/ Please enter the index page (0, 1, 2, 3) you want to see: 0