Hey!...I am using ESP32 - S2 DevKitC-1 v1 and i am trying to connect the PN532 to it inorder to do some NFC card detection. but the ESP32 is not connecting with the PN532 over the I2c
Connections:
SDA - GPIO_8
SCL - GPIO_9
VCC - 5v
GND - GND
the code :
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
volatile bool connected = false;
void setup(void) {
Wire.begin(8, 9); // Initialize I2C with SDA on pin 8 and SCL on pin 9
Serial.begin(115200);
Serial.println("*** Testing Module PN532 NFC RFID ***");
}
void loop(void) {
boolean success;
// Buffer to store the UID
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
// UID size (4 or 7 bytes depending on card type)
uint8_t uidLength;
while (!connected) {
connected = connect();
}
// 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 the card is detected, print the UID
if (success) {
Serial.println("Card Detected");
Serial.print("Size of UID: "); Serial.print(uidLength, DEC);
Serial.println(" bytes");
Serial.print("UID: ");
for (uint8_t i = 0; i < uidLength; i++) {
Serial.print(" 0x"); Serial.print(uid[i], HEX);
}
Serial.println("");
Serial.println("");
delay(1000);
connected = connect();
}
else {
// PN532 probably timed out waiting for a card
// Serial.println("Timed out waiting for a card");
}
}
bool connect() {
nfc.begin();
// Connected, show version
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.println("PN53x card not found!");
return false;
}
//port
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware version: "); 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 behavior of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for card (ISO14443A Mifare)...");
Serial.println("");
return true;
}```
Output:
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x524
load:0x4004c000,len:0xa70
load:0x40050000,len:0x298c
entry 0x4004c18c
*** Testing Module PN532 NFC RFID ***
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!
PN53x card not found!```