PN532 RFID slowing rest of sketch

I am using an RFID module as a ‘power on’ function and once detected an OLED display a RTC time.

Previously I used another RFID (RC522) and it didn’t slow the rest of the sketch down but the 532 does. They are both hardware SPI.

The RFID sketch on its own seems to run fairly quickly and recognises the card but I am wondering what the difference is and why this one slows the rest of the code down.

I use the card detect (success) to run the RTC routine and a display routine.

Could it be something in the library?

#include <SPI.h>
#include <PN532_SPI.h>
#include "PN532.h"

PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
boolean success;

void setup(void) {
void loop() 

void readRfid()
  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[0], &uidLength);
  if (success) {
    Serial.println("Found a card!");
    for (uint8_t i=0; i < uidLength; i++) 
      Serial.print(" 0x");Serial.print(uid[i], HEX); 

I found this U Tube video that I think helps my problem. Has anyone tried this? I don't totally understand it but it seems logical?

The video is suggesting that you edit the file named Adafruit_PN532.h which will be in a folder named Adafruint_PN532 in the libraries folder of your sketch folder.

On line 172 you will find this

 bool readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength, uint16_t timeout = 0); //timeout 0 means no timeout - will block forever.

Note the value of timeout and the comment.

Changing the value of timeout to say 50 will reduce the time that the code waits for a card to be read.

NOTE : I have not tried this so do not know whether it works. Change it at your own risk

Thanks Bob

I have also found this parameter

// 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.

Which looks like it does a similar thing. It is defaulted to FF so I changed it and it helped a lot. My RTC and display now run faster.....

Do you think the other parameter is a similar affect?

Do you think the other parameter is a similar affect?

From the names it sounds like they do different things but both may affect the responsiveness of the program

To me, retries is the number of times to try something before giving up whilst timeout is how long to wait before giving up.