RFID & SD card confusion

Hello people,

First off I’m a complete novice first introduced to Arduino about a month ago.

Im trying to save RFID tag numbers to an SD card, i’ve tried what feels like 5 thousand different ways to do this without success. Im using this RFID reader(http://littlebirdelectronics.com.au/products/grove-125khz-rfid-reader) with a Standard Arduino Uno and this SD card shield(http://www.ebay.com.au/itm/181588149535?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)

Both parts will work separately(tested and working) but I can’t seem to get the right code going. Its based on (http://www.seeedstudio.com/wiki/Grove_-_125KHz_RFID_Reader) which will give me the RFID tag number in the Serial monitor but I can’t seem to save it to the SD card.

#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>


SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count=0;
File EBBtags;
// counter for buffer array 
void setup()
{
 SoftSerial.begin(9600);               // the SoftSerial baud rate   
 Serial.begin(9600); 
   // the Serial port of Arduino baud rate.

}

void loop()
{
 if (SoftSerial.available())              // if date is coming from software serial port ==> data is coming from SoftSerial shield
 {
   while(SoftSerial.available())          // reading data into char array 
   {
     buffer[count++]=SoftSerial.read();     // writing data into array
     if(count == 64)break;
 }
   EBBtags = SD.open("Bandicoot.txt", FILE_WRITE);
   Serial.write(buffer,count);
   EBBtags.write(buffer,count);
   EBBtags.close();    // if no data transmission ends, write buffer to hardware serial port
   clearBufferArray();              // call clearBufferArray function to clear the stored data from the array
   count = 0;                       // set counter of while loop to zero


 }
 
 if (Serial.available())            // if data is available on hardware serial port ==> data is coming from PC or notebook
   SoftSerial.write(Serial.read());       // write it to the SoftSerial shield
}
void clearBufferArray()              // function to clear buffer array
{
 for (int i=0; i<count;i++)
   { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

I’ve tried adding this, which i’ve understood is how you open,write and close a file.

   EBBtags = SD.open("Bandicoot.txt", FILE_WRITE);
   EBBtags.println(FEW DIFFERENT COMBINATIONS IN HERE);
   EBBtags.close();

HELP? What am I doing wrong? Everything? probably.

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

  while(SoftSerial.available())          // reading data into char array
    {
      buffer[count++]=SoftSerial.read();     // writing data into array
      if(count == 64)break;
  }
    EBBtags = SD.open("Bandicoot.txt", FILE_WRITE);
    Serial.write(buffer,count);
    EBBtags.write(buffer,count);

Serial doesn't work like this. Your processor is much faster than the serial input.

SoftwareSerial SoftSerial(2, 3);

Can you post a picture of the SoftSerial that you attached to the Arduino?

Wouldn’t rfid make a more meaningful name? That way, you COULD post a picture of the RFID reader that you attached to the Arduino.

void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

Just in case some function blows the first STOP sign, put up some more. Maybe the function will get the hint by the 15th or 20th STOP sign. WRONG!

// if date is coming from software serial port ==> data is coming from SoftSerial shield

No, I REALLY need to see a picture of this SoftSerial shield!

Thanks nick, i've had a read over other that link and yeah the serial.write was a hail mary.

How would you go about saving the RFID tag to an SD card?

Fair enough it probably would Paul, but as i mentioned above that part of the code was copied from a website and works just fine. Its getting from there to an SD card that I need help with.

but as i mentioned above that part of the code was copied from a website and works just fine

That does NOT mean that stupid stuff should not be corrected.

I did an RFID project recently: Gammon Forum : Electronics : Microprocessors : RFID readers for access control / event management / parties

A simpler one: Gammon Forum : Electronics : Microprocessors : Simple RFID security system

Both show how to gather the RFID code from a card before deciding what to do with it. First hint it, you don't expect the entire card data to arrive at once. You wait for a terminator, or the correct number of bytes, depending on the type of reader.

Did you managed to solve your problem? I can suggest a solution

I store my RFID tags' UID information on SD card as filenames. It's simplest solution i can guess of and using this way in my RFID project. Of course you are limited with 6 bytes due to 8.3 filename limitation, also you won't need to search in text files for information simple SD.exist() function will be enough. If you are good with 6 bytes, you can create files as "XXXXXXXX.XXX" where Xs will be the data of your choice.

char filename[] = "XXXXXXXX.DAT";  // 4 bytes enough in my case.
char extension[] = "DAT";  
byte readCard[4];

When RFID host reads a Tag program stores it's 4 byte UID information on readCard variable
Need to convert data to char

void getFilename() {  // We will store UIDs as files on SD card
  sprintf(filename, "%02x%02x%02x%02x.%s", readCard[0], readCard[1], // Convert readCard data to char and append extension
          readCard[2], readCard[3], extension);
}

Finally create a file on SD card

void writeID () {
  getFilename(); // You should call it wherever need
  File filewrite = SD.open(filename, FILE_WRITE);
  filewrite.close();
  if (SD.exists(filename)) {
    Serial.println(F("Succesfully added ID record"));
  }
  else {
    Serial.println(F("Failed to add record"));
  }
}

In my case program checks if scanned tag have its own file on SD card and decides what to do next, you can check my project here

You may have a problem with your 9 character file name.