Hello everybody,
I want to record RFID card numbers on SD Card. but I couldn't do it. I am using Arduino Uno, Catalex SD Card Module, RDM 6300 RFID Card Reader.
Here the codes I wrote. No matter RFID Card read, it is displaying only -1. Please correct my codes.
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
SoftwareSerial RFID(0,1); // RX and TX
int i;
File myFile;
void setup()
{
RFID.begin(9600);
Serial.begin(9600);
if (RFID.available() > 0)
{
i = RFID.read();
Serial.print(i, DEC);
Serial.print(" ");
}
pinMode(SS, OUTPUT);
while (!Serial) {
;
}
if (!SD.begin(4)) {
Serial.println("SD initialization failed!");
return;
}
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to testfile.txt...");
myFile.println(RFID.read());
myFile.close();
Serial.println("done.");
} else
{
Serial.println("error opening test.txt");
}
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else {
Serial.println("error opening test.txt");
}
}
void loop()
{
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Data is recording to test.txt ...");
int chk = RFID.read();
myFile.print(" User ID: ");
myFile.println(RFID.read());
myFile.close();
Serial.println("Recorded.");
} else {
Serial.println("File couldn't open.");
}
delay(1000);
}
(Code tags added by moderator, extra blank lines removed)