Problema con PN532

Buongiorno!!
Poco tempo ho fa ho acquistato un lettore nfc/rfid PN532 con due tag: una scheda bianca e un portachiave.
Ho utilizzato questo rfid con arduino in modalità I2C. All'inizio tutto andava bene, cioè riuscivo a leggere e scrivere più volte un blocco (o più blocchi) di un certo settore. Ora però non riesco più ad autenticare il blocco (ho provato anche a cambiare chiave di accesso)....e se viene autenticato per un'operazione (lettura o scrittura) all'operazione successiva non viene autenticato...Qualcuno mi saprebbe aiutare????

Non ho mai usato gli RFid, però verifica che non abbiano un limite massimo di scritture.
Oppure verifica le eventuali modifiche che hai fatto al codice o ai collegamenti tra il PN e l'Arduino.

Ehm ... per quanto ne so, i tag RFID standard (quelli che si usano per serrature ed accessi, intendo, non quelli delle "money-keys" ) sono a sola lettura, non si scrivono ...

Cosa intendi esattamente per "non autentica" ... che ti legge correttamente il codice del tag ma non te lo riconosce piu come valido (il che potrebbe essere un'errore dello sketch), o che non riesce piu a leggerti correttamente il codice del tag (e allora potrebbe essere un problema del tag o del lettore) ?

EDIT: se invece usi quelli scrivibili (dato che ci sono pure quelli), il loro limite di riscritture dichiarate dal produttore in genere e' di circa 100.000 cicli, per i tipi "mifare" come quelli letti da quel reader ...

Non so se sia solo di lettura o anche di scrittura, ma so che prima riuscivo a scrivere un qualcosa in un blocco e poi a leggerlo. Di sicuro avrò fatto meno di 10.000 scritture. Vi allego gli sketch di scrittura e lettura
SCRITTURA:

#if 0
#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"

PN532SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
#elif 0
#include <PN532_HSU.h>
#include <PN532.h>

PN532_HSU pn532hsu(Serial1);
PN532 nfc(pn532hsu);
#else
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
#endif


void setup(void) {
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  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);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A Card ...");
}

void loop() {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  if (success) {
    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);
    Serial.println("");
    if (uidLength == 4) {
      Serial.println("Seems to be a Mifare Classic Card (4 byte UID)");
      Serial.println("Try to authenticate a certain sector's block with one of access keys");

      uint8_t keyDefault[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
      uint8_t keya[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
      /*uint8_t keyb[6] = { 0xA0, 0xA1. 0xA2, 0xA3, 0xA4, 0xA5 };
      uint8_t keyc[6] = { 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5 };
      uint8_t keyd[6] = { 0x4D, 0x3A, 0x99, 0xC3, 0x51, 0xDD };
      uint8_t keye[6] = { 0x1A, 0x98, 0x2C, 0x7E, 0x45, 0x9A };
      uint8_t keyf[6] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
      uint8_t keyg[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
      uint8_t keyh[6] = { 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56 };*/

 
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 28, 0, keyDefault);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyb);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyc);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyd;
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keye);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyf);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyg);
      //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyh);
      if (success) {
        Serial.println("Sector 7 (Block 28) has been authenticate");

        //declaration of what you want to write in the block
        uint8_t f[16] = {"frank"};
        success = nfc.mifareclassic_WriteDataBlock (28, f);
        if (success) {
          Serial.println("Block 28 has been write succesfuly");
          digitalWrite(7, HIGH);
          delay(200);
          digitalWrite(7, LOW);
          delay(200);
          delay(200);
        }
        else {
          Serial.println("Block 28 has not been write succesfuly!!!");
          digitalWrite(6, HIGH);
          delay(200);
          digitalWrite(6, LOW);
          delay(200);
          delay(200);
        }
      }
      else {
        Serial.println("Error. Sector 7 (Block 28) has not been authenticate!!");
        digitalWrite(8, HIGH);
        delay(200);
        digitalWrite(8, LOW);
        delay(200);
        delay(200);
      }

      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 29, 0, keyDefault);
      if (success) {
        Serial.println("Sector 7 (Block 29) has been authenticate");

        //declaration of what you want to write in the block
        uint8_t d[16] = {"diego"};
        success = nfc.mifareclassic_WriteDataBlock (29, d);
        if (success) {
          Serial.println("Block 29 has been write succesfuly");
          digitalWrite(7, HIGH);
          delay(200);
          digitalWrite(7, LOW);
          delay(200);
          delay(200);
        }
        else {
          Serial.println("Block 29 has not been write succesfuly!!!");
          digitalWrite(6, HIGH);
          delay(200);
          digitalWrite(6, LOW);
          delay(200);
          delay(200);
        }
      }
      else {
        Serial.println("Error. Sector 7 (Block 29) has not been authenticate!!");
        digitalWrite(8, HIGH);
        delay(200);
        digitalWrite(8, LOW);
        delay(200);
        delay(200);
      }
      
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 30, 0, keyDefault);
      if (success) {
        Serial.println("Sector 7 (Block 30) has been authenticate");

        //declaration of what you want to write in the block
        uint8_t o[16] = {"oliver"};
        success = nfc.mifareclassic_WriteDataBlock (30, o);
        if (success) {
          Serial.println("Block 30 has been write succesfuly");
          digitalWrite(7, HIGH);
          delay(200);
          digitalWrite(7, LOW);
          delay(200);
          delay(200);
        }
        else {
          Serial.println("Block 30 has not been write succesfuly!!!");
          digitalWrite(6, HIGH);
          delay(200);
          digitalWrite(6, LOW);
          delay(200);
          delay(200);
        }
      }
      else {
        Serial.println("Error. Sector 7 (Block 30) has not been authenticate!!");
        digitalWrite(8, HIGH);
        delay(200);
        digitalWrite(8, LOW);
        delay(200);
        delay(200);
      }

      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 31, 0, keyDefault);
      if (success) {
        Serial.println("Sector 7 (Block 31) has been authenticate");

        //declaration of what you want to write in the block
        uint8_t don[16] = {"donato"};
        success = nfc.mifareclassic_WriteDataBlock (31, don);
        if (success) {
          Serial.println("Block 31 has been write succesfuly");
          digitalWrite(7, HIGH);
          delay(200);
          digitalWrite(7, LOW);
          delay(200);
          delay(200);
        }
        else {
          Serial.println("Block 31 has not been write succesfuly!!!");
          digitalWrite(6, HIGH);
          delay(200);
          digitalWrite(6, LOW);
          delay(200);
          delay(200);
        }
      }
      else {
        Serial.println("Error. Sector 7 (Block 31) has not been authenticate!!");
        digitalWrite(8, HIGH);
        delay(200);
        digitalWrite(8, LOW);
        delay(200);
        delay(200);
      }

      
    }
    else {
      Serial.println("This is not a Mifare Classic Card...tihis is an Ultralight Card!!!");
      delay(200);
    }



  }
  else {
    Serial.println("Not found an ISO14443A Mifare Card!!!");
    delay(10000);
  }
}

LETTURA:

#if 0
#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"

PN532SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
#elif 0
#include <PN532_HSU.h>
#include <PN532.h>

PN532_HSU pn532hsu(Serial1);
PN532 nfc(pn532hsu);
#else
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
#endif


void setup(void) {
 Serial.begin(115200);
 Serial.println("Hello!");

 nfc.begin();

 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);

 // configure board to read RFID tags
 nfc.SAMConfig();

 Serial.println("Waiting for an ISO14443A Card ...");
}

void loop() {
 uint8_t success;
 uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
 uint8_t uidLength;
 success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
 if (success) {
   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);
   Serial.println("");
   if (uidLength == 4) {
     Serial.println("Seems to be a Mifare Classic Card (4 byte UID)");
     Serial.println("Try to authenticate a certain sector's block with one of these access key");
     uint8_t keyDefault[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
     uint8_t keya[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
     /*uint8_t keyb[6] = { 0xA0, 0xA1. 0xA2, 0xA3, 0xA4, 0xA5 };
     uint8_t keyc[6] = { 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5 };
     uint8_t keyd[6] = { 0x4D, 0x3A, 0x99, 0xC3, 0x51, 0xDD };
     uint8_t keye[6] = { 0x1A, 0x98, 0x2C, 0x7E, 0x45, 0x9A };
     uint8_t keyf[6] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
     uint8_t keyg[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
     uint8_t keyh[6] = { 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56 };*/

     success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 28, 0, keyDefault);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyb);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyc);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyd;
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keye);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyf);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyg);
     //success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keyh);
     if (success) {
       Serial.println("Sector 7 (Block 28) has been authenticate");
       uint8_t f[16];
       success = nfc.mifareclassic_ReadDataBlock(28, f);
       if (success) {
         Serial.println("Reading Block 28:");
         nfc.PrintHexChar(f, 16);
         //Serial.println("");
         Serial.print(char(f[0]));
         Serial.print(char(f[1]));
         Serial.print(char(f[2]));
         Serial.print(char(f[3]));
         Serial.println(char(f[4]));
         delay(200);
       }
       else {
         Serial.println("It is impossible to read the block 28!!!");
         delay(200);
       }

     }
     else {
       Serial.println("Sector 7 (Block 28) has not been authenticate!!!");
       delay(200);
     }

     success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 29, 0, keyDefault);
     if (success) {
       Serial.println("Sector 7 (Block 29) has been authenticate");
       uint8_t d[16];
       success = nfc.mifareclassic_ReadDataBlock(29, d);
       if (success) {
         Serial.println("Reading Block 29:");
         nfc.PrintHexChar(d, 16);
         //Serial.println("");
         Serial.print(char(d[0]));
         Serial.print(char(d[1]));
         Serial.print(char(d[2]));
         Serial.print(char(d[3]));
         Serial.println(char(d[4]));
         delay(200);
       }
       else {
         Serial.println("It is impossible to read the block 29!!!");
         delay(200);
       }

     }
     else {
       Serial.println("Sector 7 (Block 28) has not been authenticate!!!");
       delay(200);
     }

     success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 30, 0, keyDefault);
     if (success) {
       Serial.println("Sector 7 (Block 30) has been authenticate");
       uint8_t o[16];
       success = nfc.mifareclassic_ReadDataBlock(30, o);
       if (success) {
         Serial.println("Reading Block 30:");
         nfc.PrintHexChar(o, 16);
         //Serial.println("");
         Serial.print(char(o[0]));
         Serial.print(char(o[1]));
         Serial.print(char(o[2]));
         Serial.print(char(o[3]));
         Serial.print(char(o[4]));
         Serial.println(char(o[5]));
         delay(200);
       }
       else {
         Serial.println("It is impossible to read the block 30!!!");
       }

     }
     else {
       Serial.println("Sector 7 (Block 30) has not been authenticate!!!");
     }

     success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 31, 0, keyDefault);
     if (success) {
       Serial.println("Sector 7 (Block 31) has been authenticate");
       uint8_t don[16];
       success = nfc.mifareclassic_ReadDataBlock(31, don);
       if (success) {
         Serial.println("Reading Block 31:");
         nfc.PrintHexChar(don, 16);
         //Serial.println("");
         Serial.print(char(don[0]));
         Serial.print(char(don[1]));
         Serial.print(char(don[2]));
         Serial.print(char(don[3]));
         Serial.print(char(don[4]));
         Serial.println(char(don[5]));
         delay(200);
       }
       else {
         Serial.println("It is impossible to read the block 31!!!");
       }

     }
     else {
       Serial.println("Sector 7 (Block 31) has not been authenticate!!!");
     }

   
   }
   else {
     Serial.println("This is not a Mifare Classic Card...tihis is an Ultralight Card!!!");
   }
 }
 else {
   Serial.println("Not found an ISO14443A Mifare Card!!!");
   delay(10000);
 }

}

Non mi autentica più i blocchi anche se viene cambiata chiave di accesso...come se fossero protetti

Ma tu vedi cosa legge dalla scheda?
Perchè così come lo descrivi sembra un problema interno della libreria. L'hai aggiornata di recente?

Ci devo scrivere un qualcosa (tipo un nome o qualcosa del genere)...non ho aggiornato niente perhè fino a poco tempo fa tutto funzionava nel migliore dei modi

Per esempio mi fa leggere l'UID ma non mi autentica i blocchi!! Cosa potrebbe essere?

nessuno sa dirmi niente??