Pages: [1]   Go Down
Author Topic: Reading Data that was written in RFID tag  (Read 1115 times)
0 Members and 1 Guest are viewing this topic.
Singapore
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,
I have here a Parallax RFID Read/Write Module: http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/ProductID/688/List/0/Default.aspx?SortField=ProductName,ProductName
and a EM4x50 tag: http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/ProductID/689/List/0/Default.aspx?SortField=ProductName,ProductName

I have tested the programming using these 2 codes
Reading:
Code:
#include <SoftwareSerial.h>
#define RFID_READ 0x01
#define txPin 6
#define rxPin 8

SoftwareSerial mySerial(rxPin, txPin);
int val;
int runs = 0;

void setup()
{
  Serial.begin(9600);
  Serial.println("RFID Read/Write Test");
  mySerial.begin(9600);
  pinMode(txPin, OUTPUT);   
  pinMode(rxPin, INPUT);     
}

void suppressAll()                                //suppresses the "null result" from being printed if no RFID tag is present
{
    if(mySerial.available() > 0)
    { mySerial.read();
      suppressAll();
    }
}

void loop()
{
 int val;
  mySerial.print("!RW");
  mySerial.write(byte(RFID_READ));
  mySerial.write(byte(32));

  if(mySerial.available() > 0)
  {     
    val = mySerial.read();                        //The mySerial.read() procedure is called, but the result is not printed because I don't want the "error message: 1" cluttering up the serial monitor
      if (val != 1)                                   //If the error code is anything other than 1, then the RFID tag was not read correctly and any data collected is meaningless. In this case since we don't care about the resultant values they can be suppressed
       {suppressAll();}                             
  }     


 if(mySerial.available() > 0) {     
    val = mySerial.read();
    Serial.print("1st:");
    Serial.println(val, HEX);
    }

if(mySerial.available() > 0) {       
    val = mySerial.read();
    Serial.print("2nd:");
    Serial.println(val, HEX);
    }

if(mySerial.available() > 0) {     
    val = mySerial.read();
    Serial.print("3rd:");
    Serial.println(val, HEX);
    }

if(mySerial.available() > 0) {         
    val = mySerial.read();
    Serial.print("4th:");
    Serial.println(val, HEX);
    Serial.println("-----------------");
    } 

delay(750);
}

writting:
Code:
#include <SoftwareSerial.h>
 #define RFID_WRITE 0x02
 #define txPin 6
 #define rxPin 8

 #define whichSpace 4

 #define first 1                 // first, second, thrid, and fourth are four arbitrary values which will be written to the RFID tag at address whichSpace
 #define second 26
 #define third 3
 #define fourth 27

SoftwareSerial mySerial(rxPin, txPin);

void setup()
{
  Serial.begin(9600);
  Serial.println("RFID Write Test");
  mySerial.begin(9600);
  pinMode(txPin, OUTPUT);     
  pinMode(rxPin, INPUT);     
}


void suppressAll()                                      //Keeps error code & the "write confirmation" codes from being printed in the serial monitor       
{
    if(mySerial.available() > 0)
    { mySerial.read();
      suppressAll();
    }
}

 void loop()
{
  int val;

  mySerial.print("!RW");
  mySerial.write(byte(RFID_WRITE));
  mySerial.write(byte(whichSpace));
  mySerial.write(byte(first));
  mySerial.write(byte(second));
  mySerial.write(byte(third));
  mySerial.write(byte(fourth));

if(mySerial.available() > 0) {       
    val = mySerial.read();
    if (val == 1)                                        //If data was written successfully
      { Serial.println("Data written succesfully!");
        suppressAll();
      }
    else suppressAll();                                  //If an error occured during writing, discard all data recieved from the RFID writer
    }
delay(250);
}
Both codes are taken from http://arduino.cc/playground/Learning/ParallaxRFIDreadwritemodule and are working properly.

Here's my problem, I want to read the data that has been written into the tag but I do not know how. I do not quite understand the "whichSpace" of the writting code. Can somebody explain it to me and how I can go about solving this problem? Thank you.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void suppressAll()                                //suppresses the "null result" from being printed if no RFID tag is present
{
    if(mySerial.available() > 0)
    { mySerial.read();
      suppressAll();
    }
}
Recursive calls like this are not a good idea.

Code:
       {suppressAll();}                           
Alittlewhitespacewouldbeagoodidea.

Quote
Both codes are taken from http://arduino.cc/playground/Learning/ParallaxRFIDreadwritemodule and are working properly.

Here's my problem, I want to read the data that has been written into the tag but I do not know how.
Is the first code working, or not. It looks like it reads all the data. Does it, or doesn't it?
Logged

Singapore
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The first code only reads from the EM-4100 tag (read only tag): http://www.parallax.com/Store/Accessories/Hardware/tabid/162/ProductID/115/List/1/Default.aspx?SortField=ProductName,ProductName
not sure if it reads written data.

what I have is the EM4x50 tag.

The difference between these 2 tags is that the EM-4100 (read only) contains a unique 10 digit ID, while the EM4x50 (read and write) tag contains a unique read-only serial number (one of 2^32, or 4,294,967,296 possible combinations) and 116 bytes of user data area stored in a non-volatile EEPROM (Electrically Erasable Read Only Memory).
Logged

Singapore
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to write a value based on the number of counts detected by a sensor, is it possible to add a variable, for example "sensorCount" and write it into  the tag? And then program the reading code to read "sensorCount"?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is it possible to add a variable, for example "sensorCount" and write it into  the tag? And then program the reading code to read "sensorCount"?
If you are able to write any data to the card, this should be possible. If not, then I don't see how.
Logged

Maine
Offline Offline
Sr. Member
****
Karma: 14
Posts: 418
Caution: Explosives in use.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you need to write data to the card? If the Arduino will be doing the reads later on, then you can just assign the value to the ID number of the card.
Logged

"Anyone who isn't confused really doesn't understand the situation."

Electronic props for Airsoft, paintball, and laser tag -> www.nightscapetech.com

Singapore
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I am doing a point system using the RFID. The sensor does a count and the rfid adds the number of counts and writes to the card. And the RFID must be able to read the points in the card. BUt I am not sure how to do it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!
I have exactly the same problem you mention. I'm trying to give loyalty points to certain customers. This points are written and stored on the tag. Then I need to read that data, but don´t know how I can do that. Has anyone tried to read data stored on tag EM4450 with  Parallax Module? Could you give me some guidance or share your code? thanks a lot for your answers.
Logged

Earth
Offline Offline
Edison Member
*
Karma: 53
Posts: 1883
My browser no longer is binding static IP, Floating is the way to go.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hope your customers are not got hold Arduino, otherwise he could add points himself.
The CPU RFID is needed, say same one use at e-passport. smiley
« Last Edit: February 08, 2013, 07:24:00 pm by sonnyyu » Logged

Pages: [1]   Go Up
Jump to: