Go Down

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

John_Ryan

ok, so that solved my problem.

Here's the revised code including the TextString library:-

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1185507207/30

I'm reading from 8 input switches, if one is pressed, then a reading is taken from the Parallax RFID. If a tag is recognized, all 8 LED's in the 3rd array of 8 LED's flashes. Otherwise, a LED corresponding to the switch pressed, is flashed.

So that's handy for when I need to demo a standalone version. Otherwise, the intent is to check valid tags against a database of tag's stored in a web based .txt file. That parts handled by processing/php so a connection is needed for it to operate (till I buy an Arduino BT).

Loic

Nice!  :)

I'll try it with my reader code first thing tomorrow. It's 2pm now (Belgium), so I better start off fresh tomorrow morning. I'll keep you updated. Thanx again for helping me out.

Cheers, Loïc  

John_Ryan

You should be able to use comma's to separate the tags:-

TextString myTags = TextString(5500); // enough for about 500 with comma's

myTags.setArray("1010101010,1010101011,1010101012,");

Then add a comma after the tag is scanned, and use:-

if (myTags.contains("1010101010,")) {
  // checks if myString contains the subString "1010101010,"
}

The 168 should hold over a thousand unique tags, not bad considering the readers ex China off eBay store 500 and cost about the same as an Arduino, but don't do all the cool stuff Arduino's can do.

Loic

#13
Sep 07, 2007, 11:10 pm Last Edit: Sep 07, 2007, 11:14 pm by Loic Reason: 1
Finally it works!!! This code reads the tag and compares it to a multidimensional array of known tags. If the tag matches to one in the array then an action is executed (blinking a led).
Here's the code:

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

#define rxPin 7
#define txPin 2

#define TAG_LEN 12
#define ARR_LEN 2
// set up a new serial
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
int bytes_read = 0;
char target_tag[ARR_LEN][TAG_LEN] =
{{0x00, 0x00, 0xdd, 0x8e, 0x96, 0x0e, 0x00, 0x01, 0x04, 0xe0, 0x10, 0xc8 },
{0x00,  0x00, 0x1b, 0x4e, 0xc1, 0x0d, 0x00, 0x01, 0x04, 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
     
 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] = Serial.read();
    bytes_read++;  // ready to read next digit
    }
 }
 //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){
   for(int i=0; i<bytes_read; i++){
         Serial.print(code[i], HEX);    //print out the byte at the specified index
           Serial.print(",");
   }
   for(int i = 0; i < ARR_LEN; i++)
   {
     if(memcmp(code, target_tag[i], TAG_LEN) == 0 )
     {
         digitalWrite(ledPin, HIGH);
         delay(500);
         digitalWrite(ledPin, LOW);
         delay(500);
     }
   
   }
   Serial.flush(); //flush serial buffer
}

 Serial.println();
 delay(100);
 bytes_read = 0;
 
 }



Now I'll start cleaning up the code and post a tutorial at the Arduino Playground.
Thank you everybody for the support!
Kind Regards, Loïc

John_Ryan


Go Up