Pages: [1]   Go Down
Author Topic: RFID Tag reader  (Read 357 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I modified some code so that the Arduino will light an LED in the event of the proper RFID tag being presented. It doesn't work, and I can't fix it. The problem seems to be at the line :
Code:
if (bytesread == 10, code == tagOne)

Can anyone help?



Code:
char tagOne[12] = "0415ED3917";   // put the values for your tags here  
int rstPin = 2;
int ledPin = 13;
int val = 0;
char code[10];
int bytesread = 0;

void setup() {
  Serial.begin(2400);
  pinMode(rstPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(2, LOW);
}

void loop() {
  // read in and parse serial data:

  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }
          code[bytesread] = val;         // add the digit          
          bytesread++;                   // ready to read next digit  
        }
      }
      if(bytesread == 10, code == tagOne) {              // if 10 digit read is complete
        digitalWrite(ledPin, HIGH);
        Serial.print(code);
      }
    }
  }
}
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think you can compare arrays like that. The array's name 'tagOne' is a pointer to the first element of the array (I think).

You'd have to rewrite your code to something like:

Code:
if ( (bytesread == 10) && (check_for_equal_arrays(code,tagOne,array_length) == 1) ) {
   // do this, do that
}

char check_for_equal_arrays(char *array1, char *array2, int array_length) {
 int ctr;
 for (ctr = 0; ctr < array_length; ctr++) {
   if ( array1[ctr] == array2[ctr] ) {
     /*  nothing to do */
   }
   else {
     return 0;
   }
 }
 return 1;
}
« Last Edit: April 11, 2009, 08:04:22 pm by madworm » Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(bytesread == 10, code == tagOne) {

Something odd here!  What are you trying to do with the comma on this line?  There is a comma operator in C (and C++), but it's rarely used.  It discards the value of the first expression ('bytesread == 10' in this case) and uses the value of the second expression ('code == tagOne').
Logged

Pages: [1]   Go Up
Jump to: