Esp32s3 sense with PN532 from elecrow


D1 is GPIO2

So if the demo is working, the PN532 must be correct, The delay’s are Key AFAIK with NFC reads, You can use a mobile phone also to verify the card, The mifare is Generic one
Use GPIO’s
should work

ok sorry, i was confused so:
in the fritzing pn532 is set to HSU but i can confirm i have put the dip switch to i2c
what you mean by chip select is gpio4 (d3) take a look at the code i shared. theres some improvement
gpio2 is actually connected to a milwaukee m18 5amp/h battery but i have not yet created this fritzing part

so you suggest changing the ‘D’ names by gpio’number’ ?

1 Like

Ok, that would stand to reason it works then.
are you only using PL.IO or are you testing with Arduino?

Yes, try the Gpio numbers for what’s NOT working already.
HTH
GL :slight_smile: PJ

i work only with platformio

OK,
The I2C will know the pin numbers that’s why that works, BTW
the others will need the GPIO numbers
:+1:

could you be more precise ? what i need to change ?

https://files.seeedstudio.com/wiki/SeeedStudio-XIAO-ESP32S3/res/XIAO_ESP32S3_Sense_Pinout.xlsx

lol i saw that too… dip switches set correctly?

So,

#define PN532_IRQ (D9) (looks to me like it’s connected to D3 or GPIO4
#define PN532_RESET (D6) // Not connected by default on the NFC Shield

verify this?

I still think you are doing yourself a dis-service not using the XIAO Expansion Board

yeah thats because you look at the fritzing. i changed to D9 a few minutes ago

Hi there,
It wouldn’t work otherwise
He said it was. So. schematic may not be 100% accurate as to what he’s testing.
:v:

theres limit with fritzing

1 Like

Yes, there is…
so change the code and run that demo with the correct pin numbers you switched to and , see what works.
shorten the delay’s a little also.
LMK
:v:

1 Like

what about using 5v and 3.3 v is that a problem… I am assuming no problem as long as common grounded?

did you have a fire on that breadboard… or black spray paint?

yeah ahahahahahahahah :rofl:


heres the revised schematic and also the revised code :

/**************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>


// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
#define PN532_IRQ   (D3)
#define PN532_RESET (D6)  // Not connected by default on the NFC Shield

const int DELAY_BETWEEN_CARDS = 500;
long timeLastCardRead = 0;
boolean readerDisabled = false;
int irqCurr;
int irqPrev;

// This example uses the IRQ line, which is available when in I2C mode.
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

void startListeningToNFC();
void handleCardDetected();

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10); // for Leonardo/Micro/Zero

  Serial.println("Hello!");

  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);

  startListeningToNFC();
}

void loop(void) {
  if (readerDisabled) {
    if (millis() - timeLastCardRead > DELAY_BETWEEN_CARDS) {
      readerDisabled = false;
      startListeningToNFC();
    }
  } else {
    irqCurr = digitalRead(PN532_IRQ);

    // When the IRQ is pulled low - the reader has got something for us.
    if (irqCurr == LOW && irqPrev == HIGH) {
       Serial.println("Got NFC IRQ");
       handleCardDetected();
    }

    irqPrev = irqCurr;
  }
}

void startListeningToNFC() {
  // Reset our IRQ indicators
  irqPrev = irqCurr = HIGH;

  Serial.println("Starting passive read for an ISO14443A Card ...");
  if (!nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A)) {
    Serial.println("No card found. Waiting...");
  } else {
    Serial.println("Card already present.");
    handleCardDetected();
  }
}

void handleCardDetected() {
    uint8_t success = false;
    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)

    // read the NFC tag's info
    success = nfc.readDetectedPassiveTargetID(uid, &uidLength);
    Serial.println(success ? "Read successful" : "Read failed (not a card?)");

    if (success) {
      // Display some basic information about the card
      Serial.println("Found an ISO14443A card");
      Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
      Serial.print("  UID Value: ");
      nfc.PrintHex(uid, uidLength);

      if (uidLength == 4)
      {
        // We probably have a Mifare Classic card ...
        uint32_t cardid = uid[0];
        cardid <<= 8;
        cardid |= uid[1];
        cardid <<= 8;
        cardid |= uid[2];
        cardid <<= 8;
        cardid |= uid[3];
        Serial.print("Seems to be a Mifare Classic card #");
        Serial.println(cardid);
      }
      Serial.println("");

      timeLastCardRead = millis();
    }

    // The reader will be enabled again after DELAY_BETWEEN_CARDS ms will pass.
    readerDisabled = true;
}

what i notice its only when i play with IRQ like : disconnect it, put it on my finger, reconnect it that i detect a card or see things in the serial monitor