Created
August 9, 2019 08:50
-
-
Save winhtut/02e0c263587bbc1e77a84985ede11fef to your computer and use it in GitHub Desktop.
rpi rfid servo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf8 -*- | |
# | |
# Copyright 2018 Daniel Perron | |
# | |
# Base on Mario Gomez <[email protected]> MFRC522-Python | |
# | |
# This file use part of MFRC522-Python | |
# MFRC522-Python is a simple Python implementation for | |
# the MFRC522 NFC Card Reader for the Raspberry Pi. | |
# | |
# MFRC522-Python is free software: | |
# you can redistribute it and/or modify | |
# it under the terms of | |
# the GNU Lesser General Public License as published by the | |
# Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# MFRC522-Python is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU Lesser General Public License for more details. | |
# | |
# You should have received a copy of the | |
# GNU Lesser General Public License along with MFRC522-Python. | |
# If not, see <http://www.gnu.org/licenses/>. | |
# | |
import RPi.GPIO as GPIO | |
import MFRC522 | |
import signal | |
#####adding servo | |
import time | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(12,GPIO.OUT) | |
#setting pin number and pulse width modulation | |
p=GPIO.PWM(12,50) | |
p.start(7.5) | |
#adding to zero position | |
p.ChangeDutyCycle(2.5) | |
continue_reading = True | |
# function to read uid an conver it to a string | |
def uidToString(uid): | |
mystring = "" | |
for i in uid: | |
mystring = format(i, '02X') + mystring | |
return mystring | |
# Capture SIGINT for cleanup when the script is aborted | |
def end_read(signal, frame): | |
global continue_reading | |
print("Ctrl+C captured, ending read.") | |
continue_reading = False | |
GPIO.cleanup() | |
# Hook the SIGINT | |
signal.signal(signal.SIGINT, end_read) | |
# Create an object of the class MFRC522 | |
MIFAREReader = MFRC522.MFRC522() | |
# Welcome message | |
print("Welcome to the MFRC522 data read example") | |
print("Press Ctrl-C to stop.") | |
# This loop keeps checking for chips. | |
# If one is near it will get the UID and authenticate | |
while continue_reading: | |
# Scan for cards | |
(status, TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL) | |
# If a card is found | |
if status == MIFAREReader.MI_OK: | |
print ("Card detected") | |
# Get the UID of the card | |
(status, uid) = MIFAREReader.MFRC522_SelectTagSN() | |
# If we have the UID, continue | |
if status == MIFAREReader.MI_OK: | |
print("Card read UID: %s" % uidToString(uid)) | |
number=(uidToString(uid)) | |
print("Checkig Number ..... %s" % number) | |
success="D352F9B1" | |
if number==success: | |
print("success The Door is opening") | |
#turn towards 90 degree | |
p.ChangeDutyCycle(7.5) | |
time.sleep(7) | |
#turn towards 0 degress | |
p.ChangeDutyCycle(2.5) | |
else: | |
print("Authentication error") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment