-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.py
37 lines (27 loc) · 1.02 KB
/
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
import signal
import time
import MFRC522
import RPi.GPIO as GPIO
MIF = MFRC522.MFRC522()
def Scan():
global status
# Use MI_OK to check status is going well
# If not it will looping until MI_OK to check status is True
# Because when Mifare is error the value is "2", Good is "0"
while status != MIF.MI_OK:
(status, TagType) = MIF.MFRC522_Request(MIF.PICC_REQIDL)
print("Rescaning...Place your tag in front of the scanner...")
time.sleep(3)
# Pause program for 3 second for placing tag in front of the scanner
print("Please place your tag in front of the scanner in 3 seconds!")
time.sleep(3)
# Read first time to check the status of the tag
(status, TagType) = MIF.MFRC522_Request(MIF.PICC_REQIDL)
Scan()
# Get the UID of the tag
(status, uid) = MIF.MFRC522_Anticoll()
# Turn UID into Heximal
UIDorigin = str(hex(uid[0])[2:].zfill(2)) + str(hex(uid[1])[2:].zfill(2)) + \
str(hex(uid[2])[2:].zfill(2)) + str(hex(uid[3])[2:].zfill(2))
print(uid)
print(f"Your UID(hex) is {UIDorigin}")