Grove NFC- I2C scanner found device, reading not working


#1

Hello, so i have recently finished cutting my grove NFC to I2C. My I2C scanner found my device, my code below flashed with no problems. when i open serial monitor to see if the device is reading this is what i get. Please if someone can help me i am running on a deadline :-1: Thanks Beforehand!

18%20PM

current code

 #define SYSTEM_THREAD(ENABLED)
#include <Adafruit_PN532/Adafruit_PN532.h>
#include <Wire.h>
#include <SPI.h>
#define PN532_MODE (PN532_I2C_MODE)
#define IRQ_PIN  (D0) // This is how the PN532 Shield gets ready status in I2C mode
#define RST_PIN  (D1) // Necessary for I2C mode

Adafruit_PN532 nfc(RST_PIN,IRQ_PIN);


void setup(void) {
  Serial.begin(9600); // Make sure your serial terminal is closed before power the Core.
  
   
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata;
  
  do {
    versiondata = nfc.getFirmwareVersion();
    if (!versiondata) {
      Serial.print("Didn't find PN53x board\n");
      delay(1000);
      Particle.process();
    }
    Particle.process();
    
    
  }while(!versiondata);
  
  

  // Got ok data, print it out!
  Serial.print("Found chip PN5\n"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. \n"); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // configure board to read RFID tags
  nfc.SAMConfig();

}


void loop(void) {

  Particle.process();
  Serial.println("Waiting for an ISO14443A Card ...\n");
  delay(1000);
  
  
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
    
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    
    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];  
      cardid <<= 8;
      cardid |= uid[3]; 
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid);
    }
    Serial.println("");
 
  }  else {
    Serial.println("nfc.readPassiveTarget Failed\n");
    
    }
}


Current tags; https://www.amazon.com/gp/product/B0716SXJ3S/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1


#2

@talalgedeon, you may want to revisit the example you based your code on, especially the location of the delay(1000). As it stands, your code only test the presence of a card every second whereas in the example, the sampling is done continuously and the one second delay only comes AFTER a card is successfully read. I suspect you did this because the message โ€œnfc.readPassiveTarget Failedโ€ prints rapidly on the console since nfc.readPassiveTargetID() will return immediately if no card is found. You could comment out that print line to avoid that.

Also, if a card is read and uidLength is not 4 nothing happens. You may want to add an else statement to indicate the card read has a uidLength of xx for example.