Hello, I posted earlier about a memory problem and it was fixed. I hope you can all help me with this one.
I have an RFID tag read, compared to a database, then returned true or false. After it checks the database it compares it to the hard-coded "Master Tag". If it is this tag it enters "Admin Mode" and waits for another tag and stores it. Right now I'm just trying to get it to read it and print it in Admin Mode and it's not working. I'll post the Serial output after the code.
#include <SoftwareSerial.h>
#include <SD.h>
SoftwareSerial mySerial(2, 4);
int resetpin = 3; //Reader reset pin.
int ledpin = 7; //Status LED pin.
int CS_pin = 10;
void setup() {
Serial.begin(9600); //Initialize main serial connection.
mySerial.begin(9600); //Initialize reader serial connection.
pinMode(resetpin, OUTPUT); //Define reset pin as an output.
pinMode(ledpin, OUTPUT); //Define the LED pin as output.
pinMode(CS_pin, OUTPUT);
digitalWrite(resetpin, HIGH); //Pull the reset pin high.
Serial.println("Initializing SD Card");
if (!SD.begin(CS_pin)) {
Serial.println("Card Failed. Quitting");
return;
}
Serial.println("SD Card Ready");
Serial.println("Waiting for Tag");
}
void loop() {
char readByte, addByte[13], tagString[13], mastertag[13] = {
'4', 'E', '0', '0', '0', '4', '3', 'D', '3', '8', '4', 'F' };
int index = 0, filesize;
boolean reading = false, cardready = false;
while (mySerial.available() > 0) {
readByte = mySerial.read();
if(readByte == 2) reading = true;
if(readByte == 3) reading = false;
if(reading && readByte != 2 && readByte != 10 && readByte != 13){
tagString[index] = readByte;
index ++;
}
}
printtag(tagString);
if (strlen(tagString) != 0) {
if (database(tagString) == true) {
Serial.println("Match Found");
digitalWrite(ledpin, HIGH);
delay(1000);
digitalWrite(ledpin, LOW);
}
else {
Serial.println("No Match Found");
}
}
if (compare(mastertag, tagString)) {
Serial.println("Master Tag Found, Entering Admin Mode");
resetreader();
index = 0;
while (cardready == false) {
if (mySerial.available() > 0) {
while (mySerial.available() > 0) {
for (int f = 0; f < 12; f++) {
addByte[index] = mySerial.read();
index++;
}
}
Serial.println("Done Reading");
Serial.print(addByte[0]);
Serial.print(addByte[1]);
Serial.print(addByte[2]);
Serial.print(addByte[3]);
Serial.print(addByte[4]);
Serial.print(addByte[5]);
Serial.print(addByte[6]);
Serial.print(addByte[7]);
Serial.print(addByte[8]);
Serial.print(addByte[9]);
Serial.print(addByte[10]);
Serial.print(addByte[11]);
Serial.println();
cardready = true;
}
}
}
cleartag(tagString);
resetreader();
delay(200);
}
void resetreader() {
digitalWrite(resetpin, LOW);
digitalWrite(resetpin, HIGH);
delay(150);
}
boolean compare(char one[], char two[]) {
for (int i = 0; i < 12; i++) {
if (one[i] != two[i]) {
return false;
}
}
return true;
}
void cleartag(char one[]) {
for (int i = 0; i < strlen(one); i++) {
one[i] = 0;
}
}
void printtag(char one[]) {
int printer = 0;
if (!strlen(one) == 0) {
for (int i = 0; i < 12; i++) {
Serial.print(one[i]);
printer++;
}
if (printer == 12) {
Serial.println();
}
}
}
boolean database(char one[]) {
char sdarray[13];
boolean match = false;
File logread = SD.open("log.txt", FILE_WRITE);
logread.seek(0);
while (logread.available() && match == false) {
for (int i = 0; i < 12; i++) {
sdarray[i] = logread.read();
}
if (strlen(sdarray) != 0) {
if (compare(sdarray, one) && match == false) {
match = true;
logread.close();
return true;
}
}
}
if (match == false && !logread.available()) {
logread.close();
return false;
}
}
here is the Serial Output.
4E00043D384F
No Match Found
Master Tag Found, Entering Admin Mode
Done Reading
ÿÿÿÿÿÿÿÿÿÿÿ
4E000456D8C4
No Match Found