{ 2007 10 07 }
Microcontroller RFID Reader
/*
Microcontroller RFID Reader
Language: Wiring/Arduino
Reads data serially from a Parallax or ID Innovations ID12
RFID reader.
*/
#define tagLength 10 // each tag ID contains 10 bytes
#define startByte 0x0A // for the ID Innovations reader, use 0x02
#define endByte 0x0D // for the ID Innovations reader, use 0x03
#define dataRate 2400 // for the ID Innovations reader, use 9600
char tagID[tagLength]; // array to hold the tag you read
int tagIndex = 0; // counter for number of bytes read
int tagComplete = false; // whether the whole tag's been read
void setup() {
// begin serial:
Serial.begin(dataRate);
}
void loop() {
// read in and parse serial data:
if (Serial.available() > 0) {
readByte();
}
if(tagComplete == true) {
Serial.println(tagID);
}
}
/*
This method reads the bytes, and puts the
appropriate ones in the tagID
*/
void readByte() {
char thisChar = Serial.read();
Serial.print(thisChar, HEX);
switch (thisChar) {
case startByte: // start character
// reset the tag index counter
tagIndex = 0;
break;
case endByte: // end character
tagComplete = true; // you have the whole tag
break;
default: // any other character
tagComplete = false; // there are still more bytes to read
// add the byte to the tagID
if (tagIndex < tagLength) {
tagID[tagIndex] = thisChar;
// increment the tag byte counter
tagIndex++;
}
break;
}
}