RFID 不适用于新的ARDUINO UNO WiFi REV2

问题描述 投票:0回答:1

[我遵循了ARDUINO UNO REV3上RFID模块的基本示例,它工作得很好。但是,当我尝试将其连接到新的ARDUINO UNO WiFi REV2时,它将无法工作。代码可以编译,但是当我扫描NFC徽章时,没有任何内容被打印到控制台。 NFC模块通过SPI协议进行通信。新的Arduino Uno WiFi REV2上的SPI连接是否不同?

enter image description here

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN   9    // Configurable, see typical pin layout above
#define SS_PIN    10    // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card
  Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));

  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}

void loop() {

  // Look for new cards, and select one if present
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    delay(50);
    return;
  }

  // Now a card is selected. The UID and SAK is in mfrc522.uid.

  // Dump UID
  Serial.print(F("Card UID:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();

  // Set new UID
  byte newUid[] = NEW_UID;
  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
    Serial.println(F("Wrote new UID to card."));
  }

  // Halt PICC and re-select it so DumpToSerial doesn't get confused
  mfrc522.PICC_HaltA();
  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
    return;
  }

  // Dump the new memory contents
  Serial.println(F("New UID and contents:"));
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

  delay(2000);
}
arduino nfc rfid spi
1个回答
0
投票

[Arduino UNO Wifi REV2架构是不同的,唯一的办法是使它工作,就是使用wifi模块旁边的ICSP引脚,顺便提一下,我的库出现问题,并且无法使用wifi进行编译修订版2(错误:无法在return和中将'const char *'转换为'const __FlashStringHelper *'),但确实可以使用在线编辑器https://create.arduino.cc/editor进行编译。 enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.