I have in issue with the sketch not working the way I think it should!
#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)
#define PN532_SS2 (6)
// 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);
Adafruit_PN532 nfc2(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS2);
// 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);
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
// also change #define in Adafruit_PN532.cpp library file
// #define Serial SerialUSB
#endif
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.println("Didn't find PN53x board 1");
//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();
delay(1000);
nfc2.begin();
uint32_t versiondata2 = nfc2.getFirmwareVersion();
if (! versiondata2) {
Serial.println("Didn't find PN53x board 2");
//while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata2>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata2>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata2>>8) & 0xFF, DEC);
nfc2.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}
void loop(void) {
ReadRFID1();
ReadRFID2();
}
void ReadRFID1(){
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)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (!success){
ReadRFID2();
}
else if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card 1");
Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc.PrintHex(uid, uidLength);
if (uidLength == 4)
{
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
}
Serial.println("");
}
else{
Serial.println("No card at reader 1");
}
}
void ReadRFID2(){
//// Look at second reader
delay(200);
uint8_t uid2[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength2; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
uint8_t success2;
success2 = nfc2.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid2, &uidLength2);
if (!success2){
ReadRFID1();
}
if (success2) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card 2");
Serial.print(" UID Length: ");Serial.print(uidLength2, DEC);Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc2.PrintHex(uid2, uidLength2);
if (uidLength2 == 4)
{
// We probably have a Mifare Classic card ...
uint32_t cardid = uid2[0];
cardid <<= 8;
cardid |= uid2[1];
cardid <<= 8;
cardid |= uid2[2];
cardid <<= 8;
cardid |= uid2[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
}
Serial.println("");
}
else{
Serial.println("No card at 2nd reader");
}
}
IF
ReadRFID1();
ReadRFID2();
Then it will read the tag if at ReadRFID1 but not ReadRFID2 unless I read ReadRFID1 first
Then I have to read a tag at ReadRFID2 then I can read a tag at ReadRFID1 again.
If
ReadRFID2();
ReadRFID1();
it will read the tag if at ReadRFID2 1st then I can read a tag at ReadRFID1 then I can read a tag at ReadRFID2 again.
for some resone, it is holding at the first Read and waiting there for a tag to be read how would I make this non-blocking?