PN532 RFID/NFC Shield reading tags when they are not near th

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
voyagerProd
 
Posts: 2
Joined: Mon Apr 25, 2022 11:39 am

PN532 RFID/NFC Shield reading tags when they are not near th

Post by voyagerProd »

Hello everyone,

I am new to NFC and was trying out a few different things with the shield. I was able to use the examples properly, but I had some NTAG216 that I wanted to read and write to.
Unfortunately, whenever I run this, I get a reading from the tag. The problem is that my tag is not near the antenna. Is there something I am doing wrong, maybe an initialization that I cannot see?

Code: Select all

#include <Wire.h>
#include <Adafruit_PN532.h>

//Shield with I2C specific defines
#define PN532_IRQ   (2)
#define PN532_RESET (3) //not connected on shield by default
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

//Name and description for all used variables
String action = "";   //Used to know what the program should do
String saveData = ""; //Used to capture user input to save to Ntag
//byte buf[31] = {};    //Used to convert string to character array

void setup() {
  // put your setup code here, to run once:

  //Serial added only to be able to see on computer
  Serial.begin(115200);   //Arbitraty baud rate can be changed
  Serial.println("official testing started.");

  //Initializing the NFC shield for us to use
  nfc.begin();

  //Extra Init might be needed for proper functionality
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  //Configuration to read RFID tags
  nfc.SAMConfig();

  Serial.println("NFC ready to go waiting your response.");

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("What do you wish to do? 1. Read a tag, 2. Rewrite a tag, 3. Exit");
  //Wait for user input
  while ( Serial.available() == 0 )
  {}
  action = Serial.readString();

  //Read a tag (Might need to put a delimiter for reading multiple pages, let us see what we can do
  if ( action == "1" ){
    Serial.println("Ready to read tag.");
    uint8_t data[16];                           //Can this 16 be modified to read the proper amount?
    nfc.ntag2xx_ReadPage (4, data);             //4 is just an arbitrarty page number we can change this in the future
    //Show of confirmation
    nfc.PrintHexChar(data,4);
    Serial.println("");
    delay (1000);
  }
}
Attachments
Reading I get without having a tag near it
Reading I get without having a tag near it
Untitled.png (27.41 KiB) Viewed 213 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: PN532 RFID/NFC Shield reading tags when they are not nea

Post by mikeysklar »

So you are seeing false reads with no tag present.

Which processor / controller board are you using?

You are running Arduino code with i2c interface have you tried clock stretching?

https://learn.adafruit.com/working-with ... stretching

If it is not too much trouble I would try the SPI interface.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”