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:
#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:
#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 Arduino Playground - 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.