Created
March 22, 2012 20:49
-
-
Save jatkins/2164214 to your computer and use it in GitHub Desktop.
RFID Reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial rfid(9,11); | |
SoftwareSerial wire(2,3); | |
int SerialResetPIN = 6; | |
int SerialSleepPIN = 7; | |
int RFIDResetPin = 10; | |
void setup() { | |
Serial.begin(9600); | |
wire.begin(9600); | |
rfid.begin(9600); | |
pinMode(SerialResetPIN, OUTPUT); | |
pinMode(SerialSleepPIN, OUTPUT); | |
pinMode(RFIDResetPin, OUTPUT); | |
digitalWrite(RFIDResetPin, HIGH); | |
digitalWrite(SerialResetPIN, HIGH); | |
digitalWrite(SerialSleepPIN, LOW); | |
} | |
void loop() { | |
char tagString[13]; | |
int index = 0; | |
boolean reading = false; | |
while(rfid.available()) { | |
int readByte = rfid.read(); | |
if(readByte == 2) reading = true; | |
if(readByte == 3) reading = false; | |
if(reading && readByte != 2 && readByte != 10 && readByte != 13) { | |
tagString[index] = readByte; | |
index ++; | |
} | |
} | |
checkTag(tagString); | |
clearTag(tagString); | |
resetReader(); | |
} | |
void checkTag(char tag[]) { | |
if(strlen(tag) == 0) return; | |
Serial.println(tag); | |
wire.write(tag); | |
} | |
void clearTag(char one[]) { | |
for(int i = 0; i < strlen(one); i++){ | |
one[i] = 0; | |
} | |
} | |
void resetReader() { | |
digitalWrite(RFIDResetPin, LOW); | |
digitalWrite(RFIDResetPin, HIGH); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment