NFC Tag Reader with PyNFC Library

  • Share this:

Code introduction


This function reads data from an NFC tag using the PyNFC library. It first attempts to connect to the specified type of NFC tag and then reads data from the tag.


Technology Stack : PyNFC

Code Type : NFC data read function

Code Difficulty : Intermediate


                
                    
def read_nfc_tag(reader, tag_type='iso14443-3'):
    """
    This function reads data from an NFC tag using the PyNFC library.

    :param reader: An instance of the NFC reader.
    :param tag_type: The type of NFC tag to read from, default is 'iso14443-3'.
    :return: The data read from the NFC tag.
    """
    # Attempt to connect to the NFC tag
    tag = reader.connect(tag_type)
    if tag is None:
        return "No tag found"

    # Read data from the NFC tag
    data = tag.read()
    return data                
              
Tags: