PN532: Problem with wire connection, libaries and sketch

Hello. I have already did some projects with nodemcu, esp32 and Blynk and now I'm trying to do another one with RFID - NFC reader. I have bought PN532 but it looks like that I can't make it work even with simple program at Arduino Uno. I think I have problem with the connections and I can't find anyting similar internet example for guidance. I want to use SPI connection and pn532 supports that. I can't understand which arduino examples can be paired with pn532. I would appreciate if someone could give me some proper advise for wiring and sketch.


Might be a good idea to include your wiring diagram and your sketch...include power supplies.

You have to choose a communication method, SPI, IIC, or UART. That is what the little table on the back is sort of showing you. To do that, you need to know which communication method your chosen Arduino example code is using, so, decide on one; if you can't figure out what it's doing, report back, giving us a link to the library in question.

The switches in the photo are already set for SPI, so choose an SPI example. Tutorials on line present the correct wiring.

I'm asking for wiring, I don't have it. I just want to test this thing with simple program. I tried some things and it looks like that the pn532 is not recognized.

I have already wrote that I want to implement SPI. I did the settings on the pn532 with SET1&2 - LOW&HIGH. With simple programs, I'm getting a message that the board is not recognized.

Show what you tried. Code (don't forget to use code tags as described in How to get the best out of this forum) and wring (photo of a had drawn one is fine).

If you don't have wiring, how can you test?

Note:
Pins have numbers; the pin with the square is always pin 1. On the double row, it's for the photo of the back

2 1
4 3
6 5
etc

Arduino 5V pin --- PN532 VCC pin
Arduino GND pin --- PN532 GND pin
Arduino digital pin 10 --- PN532 SDA pin
Arduino digital pin 13 --- PN532 SCL pin

#include <Wire.h>
#include <Adafruit_PN532.h>

#define SDA_PIN 10
#define SCL_PIN 13

Adafruit_PN532 nfc(SDA_PIN, SCL_PIN);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1);
  }

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


  nfc.setPassiveActivationRetries(0xFF);


  nfc.SAMConfig();
  Serial.println("Waiting for an NFC tag");
}

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  uint8_t uidLength;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    Serial.println("Found an NFC tag!");

    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("");
    delay(1000);
  }
}

Im using SPI settings on NFC board.
The message I'm getting is:
"Hello!
Didn't find PN53x board"
Because it can't recognize the board in order to read the tags.
I tried a similar way with UART, but I got the same result.

So why do you use the constructor with two pins? That would indicate the I2C interface.

From the .h file

  Adafruit_PN532(uint8_t clk, uint8_t miso, uint8_t mosi,
                 uint8_t ss);                          // Software SPI
  Adafruit_PN532(uint8_t ss, SPIClass *theSPI = &SPI); // Hardware SPI
  Adafruit_PN532(uint8_t irq, uint8_t reset,
                 TwoWire *theWire = &Wire);              // Hardware I2C
  Adafruit_PN532(uint8_t reset, HardwareSerial *theSer); // Hardware UART

You're using the third one based on your code which is the I2C; it can be seen as it is the only constructor that takes two bytes for the arguments.

I'm not sure I understand. You mean at the library? I'm using wrong library? I' m new at this. What I must do?

Setting the switches on the board to I2C is one solution; you can later look at the SPI as described below.

The other one would be

You should use that constructor. In your code replace

Adafruit_PN532 nfc(SDA_PIN, SCL_PIN);

by

const uint8_t pn532SS = 10;
Adafruit_PN532 nfc(pn532SS);

And you need to wire 10/11/12/13 on your Uno to the correct pins in the PN532; I do not know for sure which pins on the PN532 it would be; SCK is probably pin 13, MO is probably MOSI which would be pin 11. RO is probably MISO which would be pin 12 and I have no idea what the chip select pin will be on the PN532 board (possibly M).

Arduino pinout from The Full Arduino Uno Pinout Guide [including diagram]

Note:
I do not have the PN532 so can't advise further.

Thank you for your help. I will make a try.

You are using the wrong wiring for an SPI interface. An internet search for "arduino pn532 spi wiring" will turn up several examples.

Thank you for the responses. As a matter of fact there isn't a single one example with this board and arduino, or other board (like arduino). There is only a video on youtube without wiring or code. If you find something please share it. Anyway I manage to find a solution from a past post here at this forum . I changed something at the wiring and it seems to be working.

The wiring to the sensor pins is the same, regardless of the board layout. Follow the SPI example in this post: Interfacing PN532 NFC RFID Module with Arduino