安防监控-刘

安防监控-刘

0个粉丝

29

问答

3

专栏

43

资料

安防监控-刘  发布于  2020-10-27 14:34:38
采纳率 0%
29个问答
2656

关于arduino怎么连接两个RFID模块的问题

   

毕业设计我要做一个基于rfid的巡更系统,为此我要连接至少两个的RFID读写模块。
但网上的示例都是只用一个的,引脚的插得位置也是一样的,我不太清楚引脚都是怎么定义的。
我用的是mfrc522的模块。
以下面代码为例,我只知道#define RST_PIN 9 和#define SS_PIN 10
是定义RST和SS引脚的,但剩下的SCK MOSI MISO 是怎么定义的。本来我以为剩下的是可以公用的,就用一个面包板连接起来,但发现不行。
现在可能是要定义这些的引脚,但我不知道哪部分代码是定义这些引脚的。
求大神指点一下。

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

#define RST_PIN   9     // 可配置,见典型引脚布局以上
#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 初始化与PC串行通信 
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) 如果没有串口打开,什么也不做(添加基于atmega32u4 Arduinos)
  SPI.begin();         // Init SPI bus 初始化SPI总线
  mfrc522.PCD_Init();  // Init MFRC522 card
  Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!")); //警告:这个例子改写你的UID变卡UID,小心使用!

  // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory. 准备关键所有按键都设置在芯片ffffffffffff H从工厂交货。
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
}

// Setting the UID can be as simple as this: 设置UID可以这么简单:
//void loop() {
//  byte newUid[] = NEW_UID;
//  if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
//    Serial.println("Wrote new UID to card.");
//  }
//  delay(1000);
//}

// But of course this is a more proper approach 当然,这是一个更恰当的方法
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.现在选择卡片。UID和SAK是mfrc522.uid。

  // Dump UID转储的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();

  // Dump PICC type 转为PICC类型
//  MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
//  Serial.print(F("PICC type: "));
//  Serial.print(mfrc522.PICC_GetTypeName(piccType));
//  Serial.print(F(" (SAK "));
//  Serial.print(mfrc522.uid.sak);
//  Serial.print(")\r\n");
//  if (  piccType != MFRC522::PICC_TYPE_MIFARE_MINI 
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_1K
//    &&  piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
//    Serial.println(F("This sample only works with MIFARE Classic cards."));
//    return;
//  }

  // Set new UID 设置新的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 / /停止PICC和重新选择那么DumpToSerial不混乱
  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);
}
我来回答
回答0个
时间排序
认可量排序
易百纳技术社区暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区