【问题标题】:Reading NFC tag not working with Arduino Uno + PN532 itead module读取 NFC 标签不适用于 Arduino Uno + PN532 itad 模块
【发布时间】:2015-08-18 14:32:46
【问题描述】:

我正在努力使用 Arduino Uno 和 PN532 模块读取 NFC 标签(然后在其上写字)。我在我的 Arduino 上使用了itead PN532 NFC 模块 (http://wiki.iteadstudio.com/ITEAD_PN532_NFC_MODULE)。 我想使用 I2C 通信。所以我像这样链接了我的端口:

  • IRQ(NFC 模块)到 A2(Arduino Uno)
  • RST(NFC 模块)转 A3(Arduino Uno)
  • SDA(NFC 模块)转 A4(Arduino Uno)
  • SCL(NFC 模块)转 A5(Arduino Uno)
  • GND(NFC 模块)到 GND(Arduino Uno)
  • 5V(NFC 模块)转 5V(Arduino Uno)

然后我使用 USB 将我的 Arduino 连接到我的笔记本电脑。我已经下载了 Adafruit_PN532_master 库以将其与我的盾牌一起使用。然后我尝试使用此代码读取 NFC 标签,但它无法正常工作。

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


// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (13)
#define PN532_MOSI (11)
#define PN532_SS   (10)
#define PN532_MISO (12)


#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
boolean val(true);

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

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop(void) {
  uint8_t 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], (uint8_t*) &uidLength);
  Serial.println(success);

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

作为 Arduino 监视器的结果,我有 “你好!找到芯片 PN532。固件版本 1.6。等待 ISO14443A 卡...” 没有别的了。我的 NFC 标签在防护罩上方,所以我不明白为什么它无法读取。它似乎检测到标签的存在。但它无法读取它。我觉得这个函数有问题:readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0],&uidLength) 但我不明白为什么。

即使我运行 Adafruit_PN532 库中的示例,它也会显示相同的输出,因为它无法读取标签。

我可能遗漏了一些东西......如果你有任何想法,你能帮帮我吗?

非常感谢!!

【问题讨论】:

    标签: arduino nfc arduino-uno


    【解决方案1】:

    代码顶部的定义显示的引脚与连接的引脚不同。

    例如,IRQ 应该连接在引脚 2 上,而不是连接在 A2 上。尝试将其与代码匹配或更改代码以使其匹配

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多