Go Down

Topic: RFID Tag reader (Read 382 times) previous topic - next topic

ziplock

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: [Select]
if (bytesread == 10, code == tagOne)

Can anyone help?



Code: [Select]
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);
     }
   }
 }
}

madworm

#1
Apr 12, 2009, 03:04 am Last Edit: Apr 12, 2009, 03:04 am by madworm Reason: 1
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: [Select]
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;
}

• 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!

Anachrocomputer

Code: [Select]
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').

Go Up