Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <SPI.h>
- #include <Adafruit_PN532.h>
- // If using the breakout with SPI, define the pins for SPI communication.
- #define PN532_SCK (2)
- #define PN532_MOSI (3)
- #define PN532_SS (4)
- #define PN532_MISO (5)
- // If using the breakout or shield with I2C, define just the pins connected
- // to the IRQ and reset lines. Use the values below (2, 3) for the shield!
- #define PN532_IRQ (2)
- #define PN532_RESET (3) // Not connected by default on the NFC Shield
- // Uncomment just _one_ line below depending on how your breakout or shield
- // is connected to the Arduino:
- // Use this line for a breakout with a SPI connection:
- Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
- // Use this line for a breakout with a hardware SPI connection. Note that
- // the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's
- // hardware SPI SCK, MOSI, and MISO pins. On an Arduino Uno these are
- // SCK = 13, MOSI = 11, MISO = 12. The SS line can be any digital IO pin.
- //Adafruit_PN532 nfc(PN532_SS);
- #include <LiquidCrystal.h>
- // Or use this line for a breakout or shield with an I2C connection:
- //Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
- LiquidCrystal lcd(12,11,5,4,3,2);
- #if defined(ARDUINO_ARCH_SAMD)
- #define Serial SerialUSB
- #endif
- void setup(void) {
- #ifndef ESP8266
- while(!Serial);
- #endif
- lcd.begin(16, 2);
- 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(void) {
- uint8_t success;
- uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
- uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
- lcd.print("Do you have your ");
- lcd.setCursor(0,1);
- lcd.print("cane?");
- lcd.print(" ");
- // Wait for an ISO14443A type cards (Mifare, etc.). When one is found
- // 'uid' will be populated with the UID, and uidLength will indicate
- // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultraligh)
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
- if (success) {
- // Display some basic information about the card
- Serial.println("Found an ISO14443A card");
- nfc.PrintHex(uid, uidLength);
- lcd.print("You are good to go!");
- }
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
- if (success) {
- // Display some basic information about the card
- 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("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement