Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 5477|回復: 3
打印 上一主題 下一主題

[請問]該如何用arduino感測3個RFID的訊號?

[複製鏈接]
跳轉到指定樓層
1#
發表於 2010-4-4 01:50:02 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 curitis 於 2010-4-4 03:52 編輯

最近 因為需要使用RFID做出類似介面的裝置
而我現在想要在一個arduino上
裝入3個RFID read用來偵測個別的RFID tag訊號
而在最後同時顯示出3各別的訊號
像是: 0415ADAB82、0415AF5A82、0415AF0D27
而若之中有一組沒有的話則顯示空白

我在google上有找到相關資料
不過只能顯示出一組
程式碼如下
因為我是新手對程式也沒有概念
請各位可以給我指導嗎?
還有可以推薦我要撰寫Arduino這類的程式
從什麼地方下手或看什麼之類的書會比較有效率
謝謝



  1. #include <SoftwareSerial.h>
  2. #define rxPin 2
  3. #define txPin 3
  4. #define ledPin 13
  5. // set up a soft serial port
  6. SoftwareSerial mySerial(rxPin, txPin);
  7. int  val = 0;
  8. char code[10];
  9. int bytesread = 0;
  10. void setup() {
  11.   // define pin modes for tx, rx, led pins:
  12. pinMode(rxPin, INPUT);    // Set rxPin as INPUT to accept SOUT from RFID pin
  13. pinMode(txPin, OUTPUT);   // Set txPin as OUTPUT to connect it to the RFID /ENABLE pin
  14. pinMode(ledPin, OUTPUT);  // Let the user know whats up
  15.   // set the data rate for the serial ports
  16. mySerial.begin(2400);    // RFID reader SOUT pin connected to Serial RX pin at 2400bps
  17. Serial.begin(9600);      // Serial feedback for debugging in Wiring
  18.   // say something
  19.   Serial.println("Hello World!");
  20. }
  21. void loop() {
  22.   digitalWrite(txPin, LOW);           // Activate the RFID reader
  23.   digitalWrite(ledPin, LOW);          // Turn off debug LED
  24.    
  25.   if((val = mySerial.read()) == 10) { // check for header
  26.     bytesread = 0;
  27.    
  28.     while(bytesread<10) {             // read 10 digit code
  29.       val = mySerial.read();
  30.       
  31.       if((val == 10)||(val == 13)) {  // if header or stop bytes before the 10 digit reading
  32.         break;                        // stop reading
  33.       }
  34.       
  35.       code[bytesread] = val;          // add the digit           
  36.       bytesread++;                    // ready to read next digit  
  37.     }
  38.    
  39.     if(bytesread == 10) {             // If 10 digit read is complete
  40.       digitalWrite(txPin, HIGH);      // deactivate RFID reader
  41.       digitalWrite(ledPin, HIGH);     // activate LED to show an RFID card was read
  42. //      Serial.print("TAG code is: ");  // possibly a good TAG
  43.       Serial.println(code);           // print the TAG code
  44.     }
  45.    
  46.     bytesread = 0;
  47.     delay(2000);                      // wait for a second to read next tag
  48.   }
  49. }

複製代碼

2#
發表於 2010-7-8 19:20:56 | 只看該作者
curitis big big:Arduino上面只有一組rxPin txPin,
要如何同時裝入3個RFID reader?

有個方法便是使用SoftwareSerial(任何數字IO口模擬Serial串口程序庫),


#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
and
#define rxPin1 4
#define txPin1 5
and
#define rxPin2 6
#define txPin2 7
.......................
.....................

==================
另外一個方法便是買另一種RFID reader--> StrongLink SL018 Mifare RFID reader module ,

aroboto 該用戶已被刪除
3#
發表於 2010-7-27 13:50:38 | 只看該作者
回復 2# vegewell


    http://arduino.cc/en/Reference/SoftwareSerial

    軟體模擬 的確是相當方便。
    使用者要注意以下幾個部分
1.Only speeds up to 9600 baud work
2.Serial.available() doesn't work
3.Serial.read() will wait until data arrives
4.Only data received while Serial.read() is being called will be received. Data received at other times will be lost, since the chip is not "listening".

    簡單的說:
        鮑率的選擇只能9600
        如果RX資料沒收到,程式會停滯,等待資料進入。這通常會早成不小的困擾
        只有呼叫Serial.read() 時才會接收資料,沒呼叫時,資料會掉@@

   通常,這樣的功能比較建議使用在感測器資料持續擷取的狀況。(如GPS)
   或者,您的主要用途再透過RS232控制其他裝置時。
aroboto 該用戶已被刪除
4#
發表於 2010-7-27 13:52:46 | 只看該作者
回復 1# curitis


    建議您的使用Arduino MEGA處理。 4組UART 處理,會比較單純
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-5-15 16:13 , Processed in 0.197452 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表