Go Down

Topic: rfid compare tag code (Read 4 times) previous topic - next topic

brianbr

Quote
String functions are not appropriate, as you are working with chinks of binary data, not strings.  


The Parallax RFID Reader from Grand Designs sends a start byte of 0x0A, then ten hexadecimal digits in ASCII, then a stop byte 0x0D. Its all 'printable ASCII' so string functions are appropriate. Tie off the ID string by replacing the stop byte with 0x00, then use strcmp() to match to your array of valid IDs.


cheers ... BBR

Loic

#6
Aug 30, 2007, 07:18 pm Last Edit: Aug 30, 2007, 07:19 pm by Loic Reason: 1
@John Ryan: In the past I've tried to modify the parallax rfid code for weeks in a row without any succes (see my other forum post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1186246253/15).
After this I finally succeeded in printing the the tag codes to serial monitor by modifying some other code I found on the web. But with this last code (the code I posted at the beginning of this topic) I noticed that by changing the variable "serInString" from char to byte the output was always smaller and more equal in length rather than being always different from tag to tag. This is the output for 3 tags using a "char" variable:
00FFFFFFDDFFFFFF8EFFFFFF96E014FFFFFFE010FFFFFFC8
00FFFFFF989FFFFFF96E014FFFFFFE0FFFFFF857B
001B4EFFFFFFC1D014FFFFFFE0FFFFFFD57B
This is the output for the same 3 tags using a "byte" variable:
00DD8E96E014E010C8
0098996E014E0857B
001B4EC1D014E0D57B
These are all printed with the command "Serial.print((serInString[serOutIndx]), HEX );"
I mention all this because maybe the whole problem of comparing the tags to a list is related to this. I've also spotted in the basic stamp code that the tags are in this format
Code: [Select]
'Valid tags

Tag1         DATA     $00, $00, $7B, $7D, $90, $F2, $36, $07, $07, $F2, $03, $7D

Tag2         DATA     $00, $00, $7D, $7D, $1E, $1F, $E0, $E6, $EF, $6E, $04, $04
Thus being 12 hex numbers while I only have 9 in two tags and even one tag (0098996E014E0857B) with 17 character that  I even can't split into HEX (if you know what I mean)

@brianbr: I've tried the "strcmp" command but with no succes, the led flashes, but only when wrong tags a presented. Maybe it's related to the problems described above.

Does anyone see any light in this mess? :-/ Any help is really appreciated.

Kind Regards, Loic

John_Ryan

I've got the same problem, in a round about kind of way. While, my tag checking will be handled outside Arduino, I'd still like a more portable version checking tags inside Arduino.

But, converting char to string I haven't found a means to do that yet, and have spent the better part of two days searching.

Loic

@John Ryan: I would be happy to work together to solve this!

I've reworked my previous code based on the all suggestions. Still no luck :(
This is it:

Code: [Select]
#include <SoftwareSerial.h>

#define rxPin 7
#define txPin 2

#define TAG_LEN 12

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

int ledPin = 13;
int serIn;
byte code[TAG_LEN];             // var that will hold the bytes-in read from the serialBuffer
byte bytes_read = 0;
char target_tag[] = {0x00, 0x1b, 0x4e, 0xc1, 0xd0, 0x14, 0xe0, 0xd5, 0x7b };

void setup()  {
 // define pin modes for tx, rx, led pins:
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 pinMode(ledPin, OUTPUT);
 mySerial.begin(19200); // set the data rate for the SoftwareSerial port
 Serial.begin(19200);      // opens serial port, sets data rate to 19200 bps
}


void loop () {
 
 
 mySerial.print(0xfa, BYTE); //request Tag code
 
 // only if there are bytes in the serial buffer execute the following code
 if(serialAvailable()) {    
   
   //keep reading from serial untill there are bytes in the serial buffer
    while (serialAvailable() && bytes_read < TAG_LEN){                //read Serial        
       code[bytes_read] = serialRead(); //insert the byte you just read into the array at the specified index
       bytes_read++;                    //update the new index
    }
   
    //feedback that something was received
    Serial.println ("Processing Tag");
 }
 
 //do somenthing else perhaps wait for other data.
 Serial.println ("NO TAG ");
 
 //print out later in the loop the sentence only if it has actually been collected;
 if( bytes_read >= TAG_LEN) {
     Serial.print("Tag ID= ");      
     
     //loop through all bytes in the array and print them out
     for(bytes_read=0; bytes_read < TAG_LEN; bytes_read++) {
         Serial.print((code[bytes_read]), HEX);    //print out the byte at the specified index
         //serInString[serOutIndx] = "";            //optional: flush out the content
     }
   if (memcmp(code, target_tag, TAG_LEN) > 0) { //if received tag code == to listed tag code
         digitalWrite(ledPin, HIGH); //do something (blink a led)
         delay(500);
         digitalWrite(ledPin, LOW);
         delay(500);
       }
     //reset all the functions to be able to fill the string back with content
     bytes_read = 0;
 }
   
 //slows down the visualization in the terminal
 Serial.flush(); //flush serial buffer
 Serial.println();
 delay(200);
}


I really can't think of anything else to do. Any help is appreciated.


Regards, Loïc

John_Ryan

That would be good. I need to compare the char variable that the tag is stored, against literals eg. "3300960185". It's not mission critical in my case, but the problems become a nag that I'd like to solve, and it would be nice to have a portable version.

My latest discoveries:-

http://www.arduino.cc/en/Tutorial/TextString

So I'll take a look at it this evening and see what it does.

Someone here also got 3 tags individually recognized, the english is broken, and I couldn't find any code.

http://www.sarades.no/index.php?paged=2

Go Up