2016-06-24 7 views
1

まず、Arduinoの初心者です。
私は、Arduino Uno、RFID RC522カードリーダー、RF 433 MHzモジュールの送信機からなる回路を持っています。Arduino Unoを使用してRF 433 MHz送信機でメッセージを送信できません

RFIDカードのIDコードをRF 433MHz送信者で送信しようとしていますが、動作しません。
最初に、私はカードを読んでいて、1つのストリングで元のRFIDコードを構成します。文字列"18016518623564"に変換します。
下のコードで、RFIDカードを読み取ることができません。 (シリアルモニタには何も表示されません)vw_setup(2000);では問題があるようです。私がコメントすれば、コードを一度読むことができます。私もvw_wait_tx();とコメントすれば、コードを2回読むことができます。私もsend("1");とコメントすれば、コードを無制限に読むことができます。しかし、私が何をしても何も送れません(プログラムはvw_wait_tx();で終わります)。

問題を解決して受信者にRFIDコードを送信できるように助けてください。いくつかの臨床試験After

// 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); // set the baud rate to 9600 

    SPI.begin(); // start the SPI library 
    rfid.init(); // initialize the RFID 

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

答えて

1

が、私は解決策に達している:以下

はコードです。
SPIとrfidの前にRF( vw_setup(2000);)を初期化すると、カードを読み取りメッセージを送信できます。なぜそれが動作するのかわかりませんが、動作します。たぶん誰かが説明できます。

+0

RFモジュールを起動する必要がありますか? – geofftnz

関連する問題