简体   繁体   中英

Get UID from NFC Card on ESP32

I am having a bit of trouble reading an NFC card with an ESP32 (using Arduino IDE). I'm using PN532 module, which works pretty well. So far my code looks like:

#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_SPI pn532spi(SPI, SS);
NfcAdapter nfc = NfcAdapter(pn532spi);

void setup(void) {
    Serial.begin(115200);
    Serial.println("NDEF Reader");
    nfc.begin();
}


void loop(void) {
    //Serial.println("\nScan a NFC tag\n");
    if (! nfc.tagPresent())
    {
      return;}
    else{
        NfcTag tag = nfc.read();
        String scannedUID = tag.getUidString();
        Serial.println(scannedUID);
    }
    delay(5000);
}

which is basically just the example from don's ndef library. I just got the UID string, rather than printing all details of the card.

It does work and displays the UID. However, I get a message saying "Tag is not NDEF formatted". Which I don't really care about. I only want to print the UID to serial and then pick this up in a C# windows app. I guess I could just ignore it, but is there a way to stop it showing up?

Is there a better library I should be using?

Thanks

Andrew

I fixed it by modifying the mifareclassic.cpp file which is part of the library. I just commented out the offending line. Probably a better way since it's still doing the check. But will do for now.

Thanks

Andrew

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM