#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
void setup() {
Serial.begin(9600);
Serial.println("NDEF Writer");
nfc.begin();
}
void loop() {
Serial.println("check");
Serial.println("\n Place a formatted NFC tag on the reader.");
if (nfc.tagPresent()) {
NdefMessage message = NdefMessage();
message.addUriRecord("http://arduino.cc");
bool success = nfc.write(message);
if (success) {
Serial.println("Success. Try reading this tag with your phone.");
} else {
Serial.println("Write failed.");
}
}
delay(5000);
}
In serial monitor printing only "NDEF Writer", "check" dont printing. Have the same problem with enother code for NFC module. With other projects dont have any problems.
It appears that your code is hanging in nfc.begin() which suggests that the NFC module is not wired correctly.
To be sure that it is hanging there add a print immediately afterwards:
Make sure that your solder joints for the four pins are good and that you have wired the pins to the correct pins on the Arduino. SDA to A4, SCL to A5.
Do you have 4.7k pullup resistors to +5V on A4 and A5? If the module itself doesn't have them, you definitely need to add them.
[+edit] Use an I2C scanner sketch to see if it finds the module's I2C address. If it doesn't, you've definitely got a wiring problem.
el_supremo, thanks for the advice. I checked everything, as you said and as I understood I have problems with the wiring. But I have correct connections SDA to A4 and SCL to A5, vcc I connected with 3,3V because with 5V arduino didn't find PN532 board. On this I want to clarify about this one here: "Do you have 4.7k pullup resistors to + 5V on A4 and A5? If the module itself does not have them, you definitely need to add them." Can you send a diagram or tell me about it in more detail?
Look at this documentation
It shows that the module has two jumper switches which by default are set for HSU mode (whatever that is). If you haven't changed or checked these switches (see the photos on the third page) you need to make sure that switch 1 (channel 1) is pushed towards ON and switch 2 is OFF.
The circuit diagram for the board is here and if I read it correctly, it already has the 4.7k pullup resistors. So after you've got the switches set correctly, this should work.
el_supremo, problem in this, that I did all from this documentation what you sended. And switches are correct, but after "nfc.begin" code does not want to work.
el_supremo, if I comment "nfc.begin();" and write "Wire.begin();" loop starts working. But how I understand now all nfc parts, for example: nfc.tagPresent() not working. May be problem in this part:
Hey guys. I have the exact same issue. I2C working but it's hanging in nfc.begin()... I even changed all cables, messed with the libraries, tested different switch settings (SPI/I2C) but nothing helped. I got my arduino nano from aliexpress as well as the pn532 module. Did anyone of you investigated further? Could it be a cold soldering joint?