1

I have a Elechouse PN532 module (bought here - https://robu.in/product/pn532-nfc-rfid-read-write-module-v3-kit/). When I try to use to it with I2C and connect it to my ESP32 (DOIT ESP32 DEV KIT V1, 30 pin version), the PN532 gets detected but it doesn't detect when a card or token shown to it. When I try the exact same code with Arduino Uno with I2C, it works flawlessly. Below are the connections for both boards, the code, the output and actual connection picture (since some said wire position matters for PN532).

Connections

  • ESP32
ESP32 PN532
GPIO 22 SCL
GPIO 21 SDA
3.3V VCC
GND GND
  • Arduino Uno
Uno PN532
A5 SCL
A4 SDA
3.3V VCC
GND GND

The code

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup(void) {
 Serial.begin(115200); 
 //Wire.begin(21, 22); //used this line only when connected with ESP32
 Serial.println("Hello!");
 pn532i2c.wakeup(); //delays 500ms
 nfc.begin();
 uint32_t versiondata = nfc.getFirmwareVersion();
 if (! versiondata) {
 Serial.print("Didn't find PN53x board");
 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);
 // 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.
 nfc.setPassiveActivationRetries(0xFF);
 // configure board to read RFID tags
 nfc.SAMConfig();
 Serial.println("Waiting for an ISO14443A card");
}
void loop(void) {
 boolean 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)
 // 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 (success) {
 Serial.println("Found a card!");
 Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
 Serial.print("UID Value: ");
 for (uint8_t i=0; i < uidLength; i++) 
 {
 Serial.print(" 0x");Serial.print(uid[i], HEX); 
 }
 Serial.println("");
 // Wait 1 second before continuing
 delay(1000);
 }
 else
 {
 // PN532 probably timed out waiting for a card
 Serial.println("Timed out waiting for a card");
 }
}

Output

Connection Placements

Also, the configuration of ESP32 in Arduino IDE

enter image description here

asked Sep 14, 2021 at 13:33
4
  • 1
    The PN532 requires I2C clock stretching. It doesn't work well over I2C with the ESP8266 or ESP32 (Adafruit has it working with the ESP32 under certain conditions - using an interrupt and being the only device on the I2C bus - you might try their driver). Your best solution is to connect it via SPI and not I2C. Commented Sep 14, 2021 at 15:47
  • Are there pullups on the board? I don't know if the arduino enables its pullups in I2C master mode, bit I don't see any on those images. Try to enable them and use the I2CScanner sketch for debugging. Commented Sep 14, 2021 at 15:52
  • @romkey While using my PN532 with Adafruit library I need to connect 6 pins right? (VCC, GND, SDA, SCL, IRQ, RST) Commented Sep 17, 2021 at 17:24
  • @SimSon I will try with external pullups and one more thing, since the firmware on PN532 is getting detected, doesn't that mean I2C is working perfectly between PN532 & ESP32, and not require external pullups? I am beginner in I2C so forgive if anything is illogical. Commented Sep 17, 2021 at 17:31

2 Answers 2

1

To use PN532, UART or SPI seems to be a good choice. Also, the little red board needs a strong power supply, and the power supply capacity from the ESP32 DEV KIT will be insufficient; I recommend adding a capacitor of about 47uF on the PN532. enter image description here

answered Mar 14, 2022 at 1:37
0

Jumper settings for SPI -
For I2C is 1 up and 2 down.

Rohit Gupta
6122 gold badges5 silver badges18 bronze badges
answered Sep 29, 2024 at 15:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.