-
Notifications
You must be signed in to change notification settings - Fork 109
print at serial only when a new card its avaiable #45
Description
dear friend, i test the example pn5180-readuid and the reader its looping, and i would like to read and print the uid at serial only a new card has been detected at reader, its possible? the actual code its same this
void loop() {
Serial.println(F("----------------------------------"));
Serial.print(F("Loop #"));
Serial.println(loopCnt++);
#if defined(ARDUINO_ARCH_ESP32)
Serial.println("Free heap: " + String(ESP.getFreeHeap()));
#endif
uint8_t uid[10];
// check for ISO-14443 card
nfc14443.reset();
nfc14443.setupRF();
if (nfc14443.isCardPresent()) {
uint8_t uidLength = nfc14443.readCardSerial(uid);
if (uidLength > 0) {
Serial.print(F("ISO14443 card found, UID="));
for (int i=0; i<uidLength; i++) {
Serial.print(uid[i] < 0x10 ? " 0" : " ");
Serial.print(uid[i], HEX);
}
Serial.println();
Serial.println(F("----------------------------------"));
delay(1000);
return;
}
}
// check for ISO-15693 card
nfc15693.reset();
nfc15693.setupRF();
// check for ICODE-SLIX2 password protected tag
uint8_t password[] = {0x01, 0x02, 0x03, 0x04}; // put your privacy password here
ISO15693ErrorCode myrc = nfc15693.disablePrivacyMode(password);
if (ISO15693_EC_OK == myrc) {
Serial.println("disablePrivacyMode successful");
}
// try to read ISO15693 inventory
ISO15693ErrorCode rc = nfc15693.getInventory(uid);
if (rc == ISO15693_EC_OK) {
Serial.print(F("ISO15693 card found, UID="));
for (int i=0; i<8; i++) {
Serial.print(uid[7-i] < 0x10 ? " 0" : " ");
Serial.print(uid[7-i], HEX); // LSB is first
}
Serial.println();
// enable privacy mode
ISO15693ErrorCode myrc = nfc15693.enablePrivacyMode(password);
if (ISO15693_EC_OK == myrc) {
Serial.println("enablePrivacyMode successful");
}
Serial.println();
Serial.println(F("----------------------------------"));
delay(1000);
return;
}
// no card detected
Serial.println(F("*** No card detected!"));
}