Reading NFC Tags with PyNFC

  • Share this:

Code introduction


This function uses the PyNFC library to read NFC tags and prints out the content of the tag.


Technology Stack : PyNFC

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
def read_tag(tag):
    import nfc
    clf = nfc.ContactlessFrontend('usb')

    try:
        tag = clf.connect(rdwr={'on-connect': lambda tag: True})
        print("Tag read: {}".format(tag.ndef))
    except Exception as e:
        print("Error reading tag: {}".format(e))                
              
Tags: