Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1.  
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <Adafruit_PN532.h>
  5.  
  6. // If using the breakout with SPI, define the pins for SPI communication.
  7. #define PN532_SCK (2)
  8. #define PN532_MOSI (3)
  9. #define PN532_SS (4)
  10. #define PN532_MISO (5)
  11.  
  12. // If using the breakout or shield with I2C, define just the pins connected
  13. // to the IRQ and reset lines. Use the values below (2, 3) for the shield!
  14. #define PN532_IRQ (2)
  15. #define PN532_RESET (3) // Not connected by default on the NFC Shield
  16.  
  17. // Uncomment just _one_ line below depending on how your breakout or shield
  18. // is connected to the Arduino:
  19.  
  20. // Use this line for a breakout with a SPI connection:
  21. Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
  22.  
  23. // Use this line for a breakout with a hardware SPI connection. Note that
  24. // the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's
  25. // hardware SPI SCK, MOSI, and MISO pins. On an Arduino Uno these are
  26. // SCK = 13, MOSI = 11, MISO = 12. The SS line can be any digital IO pin.
  27. //Adafruit_PN532 nfc(PN532_SS);
  28. #include <LiquidCrystal.h>
  29.  
  30. // Or use this line for a breakout or shield with an I2C connection:
  31. //Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
  32. LiquidCrystal lcd(12,11,5,4,3,2);
  33. #if defined(ARDUINO_ARCH_SAMD)
  34. #define Serial SerialUSB
  35. #endif
  36.  
  37.  
  38. void setup(void) {
  39.  
  40. #ifndef ESP8266
  41. while(!Serial);
  42. #endif
  43.  
  44. lcd.begin(16, 2);
  45. Serial.begin(115200);
  46. Serial.println("Hello!");
  47.  
  48. nfc.begin();
  49.  
  50. uint32_t versiondata = nfc.getFirmwareVersion();
  51. if (! versiondata) {
  52. Serial.print("Didn't find PN53x board");
  53. while (1); // halt
  54. }
  55. // Got ok data, print it out!
  56. Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  57. Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  58. Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  59.  
  60. // configure board to read RFID tags
  61. nfc.SAMConfig();
  62.  
  63. Serial.println("Waiting for an ISO14443A Card ...");
  64. }
  65.  
  66.  
  67. void loop(void) {
  68. uint8_t success;
  69. uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
  70. uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  71.  
  72. lcd.print("Do you have your ");
  73. lcd.setCursor(0,1);
  74. lcd.print("cane?");
  75. lcd.print(" ");
  76.  
  77. // Wait for an ISO14443A type cards (Mifare, etc.). When one is found
  78. // 'uid' will be populated with the UID, and uidLength will indicate
  79. // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultraligh)
  80. success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  81.  
  82.  
  83. if (success) {
  84. // Display some basic information about the card
  85. Serial.println("Found an ISO14443A card");
  86. nfc.PrintHex(uid, uidLength);
  87. lcd.print("You are good to go!");
  88. }
  89. success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  90.  
  91. if (success) {
  92. // Display some basic information about the card
  93. Serial.println("Found an ISO14443A card");
  94. Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
  95. Serial.print(" UID Value: ");
  96. nfc.PrintHex(uid, uidLength);
  97. Serial.println("");
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement