PN532 - ESP32 - I2C not connecting

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!```

I moved your topic to a more appropriate forum category @scg98132222.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

1 Like

If you are referring to the Nano ESP32, the GPIO pins for SDA and SCL are A4 and A5 respectively.

Edit: After re-reading your post I see that you are referring to this: https://docs.espressif.com/projects/esp-idf/en/stable/esp32s2/_images/esp32-s2-devkitc-1-v1-pinout.png

Above is a link to them pinout for that board. I see I2C in the specs in the bottom left corner but I don't see it anywhere in the pinout.

Yes...
This is the board i use
and regarding I2C in ESP32...i found this in an article that...
"Yes, the digital portion has two hardware I2C modules. You don't see the pins for it in the pinout because they're conencted to the GPIO mux and you can connect them to any of the (output-capable) GPIOs ."

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.