I am using "Arduino Uno R4 WiFi" and "PN532 NFC Hat." The problem I am facing is after uploading the code. The code does seem to be working but did not detect the "PN532 NFC HAT." After pressing the reset button multiple times on the Uno R4, one time will be displayed as the NFC is detected but did not work. I am not sure where I am making mistake. Please help me.
SPI Connectivity: PN532 WaveShare
The serial Monitor Output:
16:21:20.228 -> .......................Hello!
16:21:51.403 -> Failed to detect the PN532
16:21:52.425 -> ..................Hello!
16:22:13.355 -> Found PN532 with firmware version: 1.6
16:22:13.355 -> Waiting for RFID/NFC card...
16:22:15.361 -> ...Hello!
16:22:21.497 -> Failed to detect the PN532
16:22:23.520 -> ...Hello!
16:22:29.570 -> Failed to detect the PN532
16:22:31.544 -> .Hello!
16:22:34.983 -> Failed to detect the PN532
16:22:35.979 -> ...Hello!
16:22:41.773 -> Failed to detect the PN532
16:22:43.784 -> ............................................................................................................................................................................Hello!
16:25:41.336 -> Failed to detect the PN532
16:25:43.340 -> ................................Hello!
16:26:18.069 -> Failed to detect the PN532
16:26:20.064 -> ...........................Hello!
16:26:49.891 -> Failed to detect the PN532
16:26:51.899 -> .........................................................Hello!
16:27:52.374 -> Failed to detect the PN532
16:27:54.368 ->
Code:
#include "pn532.h"
#include "pn532_uno.h"
uint8_t buff[255];
uint8_t uid[MIFARE_UID_MAX_LENGTH];
int32_t uid_len = 0;
PN532 pn532;
void setup() {
// put your setup code here, to run once:
//PN532_I2C_Init(&pn532);
PN532_SPI_Init(&pn532);
Serial.println("Hello!");
if (PN532_GetFirmwareVersion(&pn532, buff) == PN532_STATUS_OK) {
Serial.print("Found PN532 with firmware version: ");
Serial.print(buff[1], DEC);
Serial.print(".");
Serial.println(buff[2], DEC);
Serial.println("Waiting for RFID/NFC card...");
}
PN532_SamConfiguration(&pn532);
}
void loop() {
// put your main code here, to run repeatedly:
// Check if a card is available to read
uid_len = PN532_ReadPassiveTarget(&pn532, uid, PN532_MIFARE_ISO14443A, 1000);
if (uid_len == PN532_STATUS_ERROR) {
Serial.print(".");
} else {
Serial.print("Found card with UID: ");
for (uint8_t i = 0; i < uid_len; i++) {
if (uid[i] <= 0xF) {
Serial.print("0");
}
Serial.print(uid[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}