Robofun 機器人論壇

標題: RFID Evaluation Shield 問題 [打印本頁]

作者: rebelbear    時間: 2013-9-16 20:23
標題: RFID Evaluation Shield 問題
本帖最後由 rebelbear 於 2013-9-16 20:24 編輯

RFID Evaluation Shield - 13.56MHz + SM130-RFID 模組 (13.56 MHz)
我有購買以上所提及的模組套件,依照官方所提供的範例進行燒入使用,設備有正常運作,但始終無法顯示已感應到的卡片資訊,在此麻煩各位先進提供協助


以下為提供官方提供的程式碼。
  1. /*
  2.   RFID Eval 13.56MHz Shield example sketch v10

  3.   Aaron Weiss, aaron at sparkfun dot com
  4.   OSHW license: http://freedomdefined.org/OSHW

  5.   works with 13.56MHz MiFare 1k tags

  6.   Based on hardware v13:
  7.   D7 -> RFID RX
  8.   D8 -> RFID TX
  9.   D9 -> XBee TX
  10.   D10 -> XBee RX

  11.   Note: RFID Reset attached to D13 (aka status LED)

  12.   Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

  13.   Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
  14.   blinks the 'Found' LED and prints the serial number of the tag to the serial port
  15.   and the XBee port.
  16.   
  17.   06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

  18. */
  19. #include <SoftwareSerial.h>

  20. SoftwareSerial rfid(7, 8);
  21. SoftwareSerial xbee(10, 9);

  22. //Prototypes
  23. void check_for_notag(void);
  24. void halt(void);
  25. void parse(void);
  26. void print_serial(void);
  27. void read_serial(void);
  28. void seek(void);
  29. void set_flag(void);

  30. //Global var
  31. int flag = 0;
  32. int Str1[11];

  33. //INIT
  34. void setup()
  35. {
  36.   Serial.begin(9600);
  37.   Serial.println("Start");

  38.   // set the data rate for the SoftwareSerial ports
  39.   xbee.begin(9600);
  40.   rfid.begin(19200);
  41.   delay(10);
  42.   halt();
  43. }

  44. //MAIN
  45. void loop()
  46. {
  47.   read_serial();
  48. }

  49. void check_for_notag()
  50. {
  51.   seek();
  52.   delay(10);
  53.   parse();
  54.   set_flag();

  55.   if(flag = 1){
  56.     seek();
  57.     delay(10);
  58.     parse();
  59.   }
  60. }

  61. void halt()
  62. {
  63. //Halt tag
  64.   rfid.write((uint8_t)255);
  65.   rfid.write((uint8_t)0);
  66.   rfid.write((uint8_t)1);
  67.   rfid.write((uint8_t)147);
  68.   rfid.write((uint8_t)148);
  69. }

  70. void parse()
  71. {
  72.   while(rfid.available()){
  73.     if(rfid.read() == 255){
  74.       for(int i=1;i<11;i++){
  75.         Str1[i]= rfid.read();
  76.       }
  77.     }
  78.   }
  79. }

  80. void print_serial()
  81. {
  82.   if(flag == 1){
  83.     //print to serial port
  84.     Serial.print(Str1[8], HEX);
  85.     Serial.print(Str1[7], HEX);
  86.     Serial.print(Str1[6], HEX);
  87.     Serial.print(Str1[5], HEX);
  88.     Serial.println();
  89.     //print to XBee module
  90.     xbee.print(Str1[8], HEX);
  91.     xbee.print(Str1[7], HEX);
  92.     xbee.print(Str1[6], HEX);
  93.     xbee.print(Str1[5], HEX);
  94.     xbee.println();
  95.     delay(100);
  96.     //check_for_notag();
  97.   }
  98. }

  99. void read_serial()
  100. {
  101.   seek();
  102.   delay(10);
  103.   parse();
  104.   set_flag();
  105.   print_serial();
  106.   delay(100);
  107. }

  108. void seek()
  109. {
  110.   //search for RFID tag
  111.   rfid.write((uint8_t)255);
  112.   rfid.write((uint8_t)0);
  113.   rfid.write((uint8_t)1);
  114.   rfid.write((uint8_t)130);
  115.   rfid.write((uint8_t)131);
  116.   delay(10);
  117. }

  118. void set_flag()
  119. {
  120.   if(Str1[2] == 6){
  121.     flag++;
  122.   }
  123.   if(Str1[2] == 2){
  124.     flag = 0;
  125.   }
  126. }
複製代碼






歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/) Powered by Discuz! X3.2