Guest User

Untitled

a guest
Oct 17th, 2019
511
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <SPI.h>
  3. #include <Adafruit_PN532.h>
  4. #define PN532_SCK  (13)
  5. #define PN532_MOSI (11)
  6. #define PN532_SS   (10)
  7. #define PN532_MISO (12)
  8. Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
  9.  
  10. void setup(void) {
  11.   #ifndef ESP8266
  12.     while (!Serial); // for Leonardo/Micro/Zero
  13.   #endif
  14.   Serial.begin(115200);
  15.   Serial.println("Hello!");
  16.  
  17.   nfc.begin();
  18.  
  19.   uint32_t versiondata = nfc.getFirmwareVersion();
  20.   if (! versiondata) {
  21.     Serial.print("Didn't find PN53x board");
  22.     while (1); // halt
  23.   }
  24.  
  25.   // Got ok data, print it out!
  26.   Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  27.   Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  28.   Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  29.  
  30.   // Set the max number of retry attempts to read from a card
  31.   // This prevents us from waiting forever for a card, which is
  32.   // the default behaviour of the PN532.
  33.   nfc.setPassiveActivationRetries(0xFF);
  34.  
  35.   // configure board to read RFID tags
  36.   nfc.SAMConfig();
  37.  
  38.   Serial.println("Waiting for an ISO14443A card");
  39. }
  40.  
  41. void loop(void) {
  42.   boolean success;
  43.   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  44.   uint8_t uidLength;                // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  45.  
  46.   // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  47.   // 'uid' will be populated with the UID, and uidLength will indicate
  48.   // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  49.   success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
  50.  
  51.   if (success) {
  52.     Serial.println("Found a card!");
  53.     Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
  54.     Serial.print("UID Value: ");
  55.     for (uint8_t i=0; i < uidLength; i++)
  56.     {
  57.       Serial.print(" 0x");Serial.print(uid[i], HEX);
  58.     }
  59.     Serial.println("");
  60.     // Wait 1 second before continuing
  61.     delay(1000);
  62.   }
  63.   else
  64.   {
  65.     // PN532 probably timed out waiting for a card
  66.     Serial.println("Timed out waiting for a card");
  67.   }
  68. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×