我正在努力用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监视器,我有"Hello! Found chip PN532. Firmware ver. 1.6. Waiting for an ISO14443A Card..."而且没有别的 . 我的NFC标签在盾牌上面,所以我不读它 . 它似乎检测到标签存在 . 但它可以说明原因 .
即使我从Adafruit_PN532库中运行一个示例,它也会向我显示相同的输出,因为它无法读取标记 .
我可能错过了一些东西......如果您有任何想法,请帮助我吗?
非常感谢!!
1 回答
代码顶部的定义不会显示与连接的相同的引脚 .
例如,IRQ应连接在引脚2而不是A2上 . 尝试将其与代码匹配或更改代码以使其匹配