RFID,NFC Module(PN532) CN

아두위키 : Arduwiki

这是一个NFC模块,通过内置的两个开关可以在UART、I2C和SPI三种方式中选择通信方式。

本文中我们将使用I2C方式进行。如果对其他方式感兴趣,请参考PN532指南


规格

  • 工作电压:5V
  • 接口:UART、I2C、SPI
  • 工作距离:最大5cm ~ 7cm


硬件


连接

Arudino UNO PN532
5V VCC
GND GND
A4 SDA
A5 SCL


Libraries

  • Wire
  • PN532_I2C
  • PN532
  • NfcAdapter

Library Download

Installation Method

示例代码

// for I2C Communication (SDA(A4), SCL(A5))
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
String tagId = "None";
byte nuidPICC[4];

void setup(void) {
  Serial.begin(9600);
  Serial.println("Serial start");
  nfc.begin();
}

void loop() {
  readNFC();
}

void readNFC() {
  if (nfc.tagPresent()) {
    Serial.println("============================================");
    NfcTag tag = nfc.read();
    tag.print();
    tagId = tag.getUidString();
  }
  delay(1000);
}


执行结果