首先,我是Arduino的初学者。我有一个电路,包括:一个Arduino Uno,一个RC522读卡器和来自RF 433 MHz模块的发送器。
我试图用RF 433 the发送者发送RFID卡的ID码,但是它不工作。首先,我读取卡,然后我组成一个字符串的射频识别代码,例如"18016518623564"。
使用下面的代码,我无法读取RFID卡。(在串行监视器上看不到任何东西。)这似乎是vw_setup(2000);的一个问题。如果我注释掉它,我可以读一遍代码。如果我也注释掉了vw_wait_tx();,我可以读两遍代码。如果我也注释掉了send("1");,我可以不受限制地阅读代码。但是,无论我做什么,都不能发送任何东西(程序在vw_wait_tx();停止)。
请有人帮我解决这个问题,并能把RFID码发送到接收器吗?
以下是代码:
// includes for RFID
#include <SPI.h>
#include <RFID.h>
// includes for RF communication
#include <VirtualWire.h>
// defines for RFID
#define SS_PIN 10
#define RST_PIN 5
// variables for RFID
RFID rfid(SS_PIN, RST_PIN);
int serNum[5]; // array to store the RFID code
String rfid_string; // variable to store the concatenated card identifier
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.init();
// initialize the IO and ISR for RF
vw_setup(2000); // Bits per sec
}
void loop() {
read_and_compose_rfid_code(); // read and compose the rfid code into one string
send("1"); // send 1 throug RF - just for testing
delay(1000);
}
void read_and_compose_rfid_code (void) {
if (rfid.isCard()) {
// check if rfid card is present nearby to the sensor antenna
if (rfid.readCardSerial()) {
// read card identifier into array defined in RFID class
// concatenate the card identifier as one string
rfid_string = String(rfid.serNum[0]) + String(rfid.serNum[1]) + String(rfid.serNum[2]) + String(rfid.serNum[3]) + String(rfid.serNum[4]);
Serial.print(rfid_string); // test to see if the code is properly composed
Serial.println();
}
rfid.halt();
delay(1000); // set a delay of 1 second before the next card read
}
}
/* function used to send the card identifier through RF */
void send (char *message) {
vw_send((uint8_t *)message, strlen(message));
// "message" is an array of the bytes to send, and strlen(message) is the number of bytes stored in the array
vw_wait_tx(); // wait until the whole message has been transmitted
}发布于 2016-06-25 16:51:15
经过几次试验,我已经找到了解决办法。
如果我在射频识别和射频识别之前初始化RF (vw_setup(2000);),我就可以读取卡片并发送消息。我不知道它为什么会起作用,但它起作用。也许有人能解释。
https://stackoverflow.com/questions/38021292
复制相似问题