I have coded a working PN532 NFC reader on my Arduino. I would like to connect multiple ones to the same Arduino. How would i define a 2nd instance of that in code. I have used multiple I2C devices in the past and usually they have a address pad to solder to change the address, but this one doesn't. I dont mind using SPI or wiring interrupt pins if needed.
Here is the code for the PN532
/*!
*@file nfcCardInfo.ino
*@brief read the basic information of the card
*@details This demo runs on the arduino platform.
*@ Download this demo to read the basic information of the card,
*@ including UID, manufacturer, storage space, RF technology etc.
*@
*@ Suported NFC card/tag:
*@ 1.MIFARE Classic S50/S70
*@ 2.NTAG213/215/216
*@ 3.MIFARE Ultralight
*@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
*@license The MIT license (MIT)
*@author [fengli](li.feng@dfrobot.com)
*@version V1.0
*@date 2019-7-3
*@url https://github.com/DFRobot/DFRobot_PN532
*/
#include <DFRobot_PN532.h>
#define BLOCK_SIZE 16
#define PN532_IRQ (2)
#define INTERRUPT (1)
#define POLLING (0)
// Use this line for a breakout or shield with an I2C connection
// Check the card by polling
DFRobot_PN532_IIC nfc(PN532_IRQ, POLLING);
DFRobot_PN532:: sCard_t NFCcard;
const int output_pin = 6;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(output_pin, OUTPUT);
Serial.begin(115200);
//Initialize the NFC module
while (!nfc.begin()) {
Serial.println("initial failure");
delay (1000);
}
Serial.println("Please place the NFC card/tag on module..... ");
}
void loop()
{
//Scan, write and read NFC card every 2s
//Print all what is to be written and read
if (nfc.scan())
{
//Read the basic information of the card
NFCcard = nfc.getInformation();
Serial.println("----------------NFC card/tag information-------------------");
Serial.print("UID Lenght: "); Serial.println(NFCcard.uidlenght);
Serial.print("UID: ");
for (int i = 0; i < NFCcard.uidlenght; i++) {
Serial.print(NFCcard.uid[i], HEX);
Serial.print(" ");
//call here
if (readRFID()) {
// Access granted.
digitalWrite(output_pin, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Valid");
}
else {
// Access denied
digitalWrite(output_pin, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Invalid");
}
}
Serial.println("");
}
else
{
//Serial.println("no card!");
digitalWrite(output_pin, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
}
delay(200);
}
boolean readRFID()
{
byte card_ID[4]; // card UID size 4byte
const int numOfCards = 1; // the number of cards used. this can change as you want
byte cards[numOfCards][7] = {{0x93, 0xDB, 0x1B, 0xFB}}; // array of UIDs of rfid cards
//1 0xFD, 0xF8, 0x92, 0xDA
//2 0x3D, 0xD2, 0x93, 0xDA
//3 0xCD, 0xE7, 0x94, 0xDA
//4 0x0D, 0x74, 0x94, 0xDA
//5 0xCD, 0x73, 0x94, 0xDA
//6 0x7D, 0xD2, 0x93, 0xDA
for (byte i = 0; i < NFCcard.uidlenght; i++)
{ card_ID[i] = NFCcard.uid[i]; }
for (int i = 0; i < numOfCards; i++)
{
if ((card_ID[0] == cards[i][0]) && (card_ID[1] == cards[i][1]) && (card_ID[2] == cards[i][2]) && (card_ID[3] == cards[i][3]))
{ return true; }
}
return false;
}