-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.py
48 lines (32 loc) · 902 Bytes
/
read.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#import RPi.GPIO as GPIO
#from mfrc522 import SimpleMFRC522
#reader = SimpleMFRC522()
import time
import RPi.GPIO as GPIO
import MFRC522
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
# Welcome message
print("Looking for cards")
print("Press Ctrl-C to stop.")
# This loop checks for chips. If one is near it will get the UID
try:
while True:
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
# Print UID
print("UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()
'''
try:
id = reader.read()
print(id)
finally:
GPIO.cleanup()
'''