after some more work, i was able to get the write operation working. Here is the code i used:
//Code to write data to Parallax RFID reader/writer 28440 from Arduino
//Program writes to one of the 29 user-defined addresses (3-31) as define by whichSpace
//The four bytes to be written are defined by first, second, third, and fourth
//Coded by vgrhcp
#include <NewSoftSerial.h>
#define RFID_WRITE 0x02
#define txPin 6
#define rxPin 8
#define whichSpace 4
#define first 1
#define second 26
#define third 3
#define fourth 27
NewSoftSerial 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.print(RFID_WRITE, BYTE);
mySerial.print(whichSpace, BYTE);
mySerial.print(first, BYTE);
mySerial.print(second, BYTE);
mySerial.print(third, BYTE);
mySerial.print(fourth, BYTE);
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);
}
I just have one problem now...my code writes data as bytes, as it must for the RFID writer to understand it (i tried writing as DEC and HEX, but it did not work). However, the read code that uberdude wrote and i modified prints the values it reads as HEX. So the issue is that if you write, say, 26 as one of the bytes onto a card and then read it, it will come up as 1A, which is the HEX value that corresponds to 26. To solve this, you must change the read procedure form printing HEX to DEC like so:
//Code to read data from Parallax RFID reader/writer 28440 via Arduino
//Program reads data from one of the 29 user-defined addresses (3-31) as define by whichSpace
//Writen by vgrhcp based on code by uberdude
#include <NewSoftSerial.h>
#define RFID_READ 0x01
#define txPin 6
#define rxPin 8
#define whichSpace 4
NewSoftSerial mySerial(rxPin, txPin);
int val;
int runs = 0;
void setup()
{
Serial.begin(9600);
Serial.println("RFID Read 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.print(RFID_READ, BYTE);
mySerial.print(whichSpace, BYTE);
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 not 1, then there has been an error and the RFID tag was not read correctly.In this case we don't really care about the resultant values, so they can be suppressed
{suppressAll();}
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print("1st:");
Serial.println(val, DEC);
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print("2nd:");
Serial.println(val, DEC);
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print("3rd:");
Serial.println(val, DEC);
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print("4th:");
Serial.println(val, DEC);
Serial.println("-----------------");
}
delay(750);
}
these two codes are now fully compatible with each other; so long as the whichSpace is set to the same value (3-31) in each program, the reader will read whatever was written by the writer. Enjoy!