It sends the read command via software serial to the rfid reader. Next it reads in the Tag code via hardware serial. Finally it prints a nice tag code to the computer!

Now the problematic part;As a next step I wanted to compare the tag code to a list of known tags and then do a certain action (for example blink a led). I've been struggling with this for a week now so I decided to ask for some help. This is one of my numerous attempts

// set up a new serial portSoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);int serIn; // var that will hold the bytes-in read from the serialBufferbyte serInString[12]; // array that will hold the different bytesint serInIndx = 0; // index of serInString[] in which to inser the next incoming byteint serOutIndx = 0; // index of the outgoing serInString[] array;int ledPin = 13; // LED connected to digital pin 13char Tag1[] = "001B4EC1D014E0D57B"; //known tag code, should become a list of 50+ tags

// 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()){ serIn = serialRead(); //read Serial serInString[serInIndx] = serIn; //insert the byte you just read into the array at the specified index serInIndx++; //update the new index }

//feedback that something was received Serial.println ("Processing Tag"); }

//reset all the functions to be able to fill the string back with content Serial.flush(); //flush serial buffer serOutIndx = 0; serInIndx = 0; }

//slows down the visualization in the terminal Serial.println(); delay(200);}

The tag code "001B4EC1D014E0D57B" is the code that I have copied from serial monitor after reading a tag. All my attempts won't make the led blink Can someone please help me, I would like to put 50+ tags in the memory that trigger a certain action.

Also, I just glanced at it but your loop function doesn't look right. You are asking for a new tag every time you run loop and apparently assuming that the data will be returned immediately. This is not necessarily the case. You are also assuming that the data is made available in a single uninterupted stream, and this is almost certainly wrong. Look at the part of the code where you are reading the data; that section probably needs a re-write.

Quote

I would like to put 50+ tags in the memory that trigger a certain action.

Hmm, the ATmega8 only has 1k of RAM, and your target strings are about 10 bytes long, so that's half the available memory just to store the strings you are matching against. It'll probably work, as long as the rest of your code isn't too memory intensive, but you should be aware you are approching the limits of the device and method you're using.

Of course, the 168 has twice the RAM and there are methods for storing data in program space (flash), but they're not as straightforward as the methods you use now.

I've been trying your suggestions for the last 24hours but with no success. The code that prints the tag code back to the serial monitor was modified from code I found on the web, I'm not such good coder to be able to rewrite it with a new approach to getting the tag codes reported. But as far as printing nice unique tag codes to the serial monitor this code works perfectly, so I'm not sure the "compare tag code to list" problem I'm having is to find in the way this original code works. But being a "C" noob I could be totally wrong. Next thing I tried was using the <string.h> library, trying memcmp and strcmp. No succes , but again could be my semi-noobness

String functions are not appropriate, as you are working with chinks of binary data, not strings. Specifically, C strings are null terminated arrays, which means a byte containgin 0x00 will occur after the contents of the string. In the example you are playing with, there is a null in the first array element, which means that is a zero length string as far as strcmp() and friends are concerned. memcmp may be better, but I haven't checked the docs on that one myself.

// loop here until we get the required number of bytes back from the reader // this code will fail unpredicably in the event of communication errors while (bytes_read < TAG_LEN) while (Serial.available() > 0) tag_read[bytes_read++] = Serial.read();

// compare the tag we read to see if it matches if (memcmp(tag_read, target_tag, TAG_LEN)) do_something();}

This is off the cuff, so there may be errors, especially at the boundary conditions...

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.

@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: 00FFFFFFDDFFFFFF8EFFFFFF96E014FFFFFFE010FFFFFFC800FFFFFF989FFFFFF96E014FFFFFFE0FFFFFF857B001B4EFFFFFFC1D014FFFFFFE0FFFFFFD57B This is the output for the same 3 tags using a "byte" variable:00DD8E96E014E010C80098996E014E0857B001B4EC1D014E0D57BThese 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

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.

// 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"); }

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.

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).

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: