NFC Tag Reader Function

  • Share this:

Code introduction


This function uses the PyNFC library to scan and read NFC tag data. It first opens the NFC device, then scans for nearby NFC tags, reads, and prints the tag ID and data.


Technology Stack : PyNFC

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
from pynfc import NFC

def read_tag():
    nfc = NFC()
    nfc.open()
    tag = nfc.scan()[0]
    if tag:
        print(f"Tag ID: {tag.id}")
        data = tag.read()
        print(f"Data: {data}")
    else:
        print("No tag found")
    nfc.close()                
              
Tags: