I am currently building something, and it works fine as I am testing the device.
Basically the project would scan student RFID cards, then record another set of RFID cards to their accounts(in the SD card).
All is going well, but until I add more “Student Accounts”, the data that was stored before cannot be read anymore, but as i test the card, the data is there, but it just doesn’t seem to be read when the new code is flashed.
Here’s a copy of the code:
#include <SoftwareSerial.h>
#include <SD.h>
SoftwareSerial RFID(2, 3);
int i;
int c;
int pi;
String pie;
String readID;
String readB;
String cID;
String cB;
String bookS;
String BB;
int R = 6;
int B = 5;
int Re = 7;
void setup()
{
RFID.begin(9600);
Serial.begin(9600);
pinMode(R, INPUT);
pinMode(B, INPUT);
pinMode(Re, INPUT);
while (!Serial)
{;}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
}
void scan()
{
if (RFID.available() > 0)
{
i = RFID.read();
c = c + 1;
pie += i;
}
if (c == 14)
{
c = 0;
pi = 0;
readID = pie;
pie = "";
}
}
void loop()
{
int Rx = digitalRead(R);
int Bx = digitalRead(B);
int Rex = digitalRead(Re);
if ((Rx == 1))
{
readS();
Rx = 0;
}
if ((Rx == 0))
{}
if ((Bx == 1))
{
borrow();
Bx = 0;
}
if ((Bx == 0))
{}
if ((Rex == 1))
{
returnBooks();
Rex = 0;
}
if ((Rex == 0))
{
}
}
void readS()
{
scan();
if ((readID == "24848484848565555565270663"))
{
Serial.println("Oginne Lapuz");
cID = readID;
File oginneFile = SD.open("oginne.txt");
if (oginneFile) {
while (oginneFile.available())
{
Serial.write(oginneFile.read());
}
oginneFile.close();
}
else
{
Serial.println("No Borrowed books");
}
readID = "";
i = 0;
bookS = "";
}
if ((readID == "24848484848566556576851683"))
{
Serial.println("Darryl Cacho");
cID = readID;
File darrylFile = SD.open("darryl.txt");
if (darrylFile) {
while (darrylFile.available())
{
Serial.write(darrylFile.read());
}
darrylFile.close();
}
else
{
Serial.println("No Borrowed books");
}
readID = "";
i = 0;
bookS = "";
}
if ((readID == "24865484856575348665354543"))
{
Serial.println("Mayee Perdon");
cID = readID;
File mayeeFile = SD.open("mayee.txt");
if (mayeeFile) {
while (mayeeFile.available())
{
Serial.write(mayeeFile.read());
}
mayeeFile.close();
}
else
{
Serial.println("No Borrowed books");
}
readID = "";
i = 0;
bookS = "";
}
if ((readID == "24865484856576966556849533"))
{
Serial.println("Fae");
cID = readID;
File faeFile = SD.open("fae.txt");
if (faeFile) {
while (faeFile.available())
{
Serial.write(faeFile.read());
}
faeFile.close();
}
else
{
Serial.println("No Borrowed books");
}
readID = "";
i = 0;
bookS = "";
}
}
void borrow()
{
scan();
if ((cID == "24848484848565555565270663") && (i == 3))
{
books();
File oginneFile = SD.open("oginne.txt", FILE_WRITE);
Serial.println(bookS);
oginneFile.println(bookS);
oginneFile.close();
i = 0;
}
if ((cID == "24865484856575348665354543") && (i == 3))
{
books();
File mayeeFile = SD.open("mayee.txt", FILE_WRITE);
Serial.println(bookS);
mayeeFile.println(bookS);
mayeeFile.close();
i = 0;
}
if ((cID == "24848484848566556576851683") && (i == 3))
{
books();
File darrylFile = SD.open("darryl.txt", FILE_WRITE);
Serial.println(bookS);
darrylFile.println(bookS);
darrylFile.close();
i = 0;
}
if ((cID == "24865484856576966556849533") && (i == 3))
{
books();
File faeFile = SD.open("fae.txt", FILE_WRITE);
Serial.println(bookS);
faeFile.println(bookS);
faeFile.close();
i = 0;
}
}
void books()
{
if ((readID == "24857484849556570685654573"))
{
bookS = "Book of cheese";
readID = "";
}
if ((readID == "24857484849557066516968663"))
{
bookS = "Book of math";
readID = "";
}
if ((readID == "24857484849556570515156503"))
{
bookS = "Engineering Electromagnetics";
readID = "";
}
if ((readID == "24857484849564851555754663"))
{
bookS = "Engineering Communications";
readID = "";
}
}
void returnBooks()
{
if ((cID == "24848484848565555565270663"))
{
SD.remove("oginne.txt");
Serial.println("Books are cleared for Oginne Lapuz");
}
if ((cID == "24848484848566556576851683"))
{
SD.remove("mayee.txt");
Serial.println("Books are cleared for Mayee Perdon");
}
if ((cID == "24865484856575348665354543"))
{
SD.remove("darryl.txt");
Serial.println("Books are cleared for Darryl Cacho");
}
}
Thanks for any input!