Fixed uid output. Also fixed line endings (sorry).
This commit is contained in:
@@ -1,44 +1,45 @@
|
|||||||
from mfrc522 import MFRC522
|
from mfrc522 import MFRC522
|
||||||
import utime
|
import utime
|
||||||
|
|
||||||
|
|
||||||
def uidToString(uid):
|
def uid_to_string(uid):
|
||||||
mystring = ""
|
mystring = "0x"
|
||||||
for i in uid:
|
# The mfrc522 lib returns all tested uids in inverse order
|
||||||
mystring = "%02X" % i + mystring
|
for i in reversed(uid):
|
||||||
return mystring
|
mystring += "%02X" % i
|
||||||
|
return mystring
|
||||||
def main():
|
|
||||||
reader = MFRC522(spi_id=1,sck=10,miso=12,mosi=11,cs=13,rst=9)
|
def main():
|
||||||
|
reader = MFRC522(spi_id=1,sck=10,miso=12,mosi=11,cs=13,rst=9)
|
||||||
print("")
|
|
||||||
print("Please place card on reader")
|
print("")
|
||||||
print("")
|
print("Please place card on reader")
|
||||||
|
print("")
|
||||||
PreviousCard = [0]
|
|
||||||
|
previous_uid = [0]
|
||||||
try:
|
|
||||||
while True:
|
try:
|
||||||
reader.init()
|
while True:
|
||||||
|
reader.init()
|
||||||
(stat, tag_type) = reader.request(reader.REQIDL)
|
|
||||||
#print('request stat:',stat,' tag_type:',tag_type)
|
# For now we omit the tag type
|
||||||
if stat == reader.OK:
|
(stat, _) = reader.request(reader.REQIDL)
|
||||||
(stat, uid) = reader.SelectTagSN()
|
if stat == reader.OK:
|
||||||
if uid == PreviousCard:
|
(stat, uid) = reader.SelectTagSN()
|
||||||
continue
|
if uid == previous_uid:
|
||||||
if stat == reader.OK:
|
continue
|
||||||
print("Card detected {} uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid)))
|
if stat == reader.OK:
|
||||||
|
print(uid_to_string(uid))
|
||||||
PreviousCard = uid
|
|
||||||
else:
|
previous_uid = uid
|
||||||
pass
|
else:
|
||||||
else:
|
pass
|
||||||
PreviousCard=[0]
|
else:
|
||||||
utime.sleep_ms(50)
|
previous_uid=[0]
|
||||||
|
utime.sleep_ms(50)
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user