/**************************************************************************/ /*! @file iso14443a_uid.pde @author Adafruit Industries @license BSD (see license.txt) @modified by Salvador Mendoza (salmg.net) for Electronic Cats' NFC Copy Cat This example will attempt to connect to an ISO14443A card or tag and retrieve some basic information about it that can be used to determine what type of card it is. Note that you need the baud rate to be 115200 because we need to print out the data and read from the card at the same time! This is an example sketch for the NFC Copy Cat board This library works with the NFC Copy Cat board ----> https://www.electroniccats.com/ Check out the links above for our tutorials and wiring diagrams These chips use SPI or I2C to communicate. Electronic Cats invests time and resources providing this open source code, please support Electronic Cats and open-source hardware by purchasing products from Electronic Cats! */ /**************************************************************************/ #include #include #include // If using the breakout with SPI, define the pins for SPI communication. #define PN532_SCK (17) #define PN532_MOSI (16) #define PN532_SS (18) #define PN532_MISO (19) #define L1 (14) //LED1 #define L2 (5) //LED2 #define L3 (4) //LED3 #define MPIN (28) //MagsSpoof Button #define NPIN (27) //NFC Button // 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); // Or use this line for a breakout or shield with an I2C connection: //Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); void setup(void) { pinMode(L2, OUTPUT); pinMode(L1, OUTPUT); pinMode(NPIN, INPUT_PULLUP); 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); // Set the max number of retry attempts to read from a card // This prevents us from waiting forever for a card, which is // the default behaviour of the PN532. nfc.setPassiveActivationRetries(0xFF); // configure board to read RFID tags nfc.SAMConfig(); // blink to show we started up blink(L1, 200, 2); blink(L2, 200, 2); blink(L3, 200, 2); } void blink(int pin, int msdelay, int times){ for (int i = 0; i < times; i++){ digitalWrite(pin, HIGH); delay(msdelay); digitalWrite(pin, LOW); delay(msdelay); } } void nfcread(void) { Serial.println("Waiting for an ISO14443A card"); boolean 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) // 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 Ultralight) success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { blink(L1, 100, 2); Serial.println("Found a card!"); Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); Serial.print("UID Value: "); for (uint8_t i=0; i < uidLength; i++) { Serial.print(" 0x");Serial.print(uid[i], HEX); } Serial.println(""); // Wait 1 second before continuing delay(1000); } else { // PN532 probably timed out waiting for a card Serial.println("Timed out waiting for a card"); } } void nfcbutton(){ if (digitalRead(NPIN) == 0){ blink(L2, 150, 1); Serial.println("Activating NFC..."); nfcread(); blink(L2, 100, 3); } } void loop(){ nfcbutton(); }