Nano Project Programming Issue

New to arduino so if anyone could help me out I would really appreciate it. I found a project I wanted to work on that would be beneficial to my industry (low voltage security). Seemed simple enough, board layout, programming file completed (all in link below). Followed instructions, but I cannot get it to verify (keep getting errors). I used the same Arduino version and SDFAT library (my main issue).

Project: http://www.bishopfox.com/resources/tools/rfid-hacking/attack-tools/
Other Tutorial: Guide to building the Tastic RFID Thief

Note: I am not using this for it's intended purpose. Many times I have customers with existing access control systems that would like to switch hardware, but use their existing cards. This tool will help me verify quickly whether or not I can do that with the system I sell. I don't need the SD card function, I just didn't want to deviate from the tutorial because of my limited knowledge.

My main issues:

  1. After adding the SDFAT library (same one as indicated in the tutorial) and making sure it was in the correct folder, when I go to import it, nothing happens other than creating a blank return in the sketch. If I go to verify, it states "sdfat does not name a type" and from what I found it is not seeing the library. I placed the library in both the library folder under the main Arduino folder and the one in my documents. When I go to import, it shows it both under the main included libraries and the "contributed" ones. Even when trying to use one or the other, I get the same result.

  2. I found the updated SDFAT library from early 2015. When I import this, it does add it to the sketch, but then there are multiple other errors I don't understand.

Hoping someone can help me out with this or help me update the code if it's necessary. Thank you

Sigh....

Code please.

My apologies. Have to break it up due to character restriction. Part 1 of 2

#include <SoftwareSerial.h>

#include <ArduinoStream.h>
#include <bufstream.h>
#include <ios.h>
#include <iostream.h>
#include <istream.h>
#include <ostream.h>
#include <Sd2Card.h>
#include <Sd2PinMap.h>
#include <SdBaseFile.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <SdFatmainpage.h>
#include <SdFatStructs.h>
#include <SdFatUtil.h>
#include <SdFile.h>
#include <SdInfo.h>
#include <SdStream.h>
#include <SdVolume.h>

#define MAX_BITS 100                 // max number of bits 
#define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse.  
#define txPin 4 // White wire from Serial LCD screen
const int LCDdelay = 10;  // conservative, 2 actually works


unsigned char databits[MAX_BITS];    // stores all of the data bits
volatile unsigned int bitCount = 0;
unsigned char flagDone;              // goes low when data is currently being captured
unsigned int weigand_counter;        // countdown until we assume there are no more bits

volatile unsigned long facilityCode=0;        // decoded facility code
volatile unsigned long cardCode=0;            // decoded card code

// Breaking up card value into 2 chunks to create 10 char HEX value
volatile unsigned long bitHolder1 = 0;
volatile unsigned long bitHolder2 = 0;
volatile unsigned long cardChunk1 = 0;
volatile unsigned long cardChunk2 = 0;


// SD card variables
const uint8_t chipSelect = 10; // CS from SD to Pin 10 on Arduino
SdFat sd; // file system object for SD card
SdFile file; // file object
char dataFile[] = "cards.txt"; // file to save card ids to


///////////////////////////////////////////////////////
// Process interrupts

// interrupt that happens when INTO goes low (0 bit)
void ISR_INT0()
{
  //Serial.print("0");
  bitCount++;
  flagDone = 0;
  
  if(bitCount < 23) {
      bitHolder1 = bitHolder1 << 1;
  }
  else {
      bitHolder2 = bitHolder2 << 1;
  }
    
  weigand_counter = WEIGAND_WAIT_TIME;  
  
}

// interrupt that happens when INT1 goes low (1 bit)
void ISR_INT1()
{
  //Serial.print("1");
  databits[bitCount] = 1;
  bitCount++;
  flagDone = 0;
  
   if(bitCount < 23) {
      bitHolder1 = bitHolder1 << 1;
      bitHolder1 |= 1;
   }
   else {
     bitHolder2 = bitHolder2 << 1;
     bitHolder2 |= 1;
   }
  
  weigand_counter = WEIGAND_WAIT_TIME;  
}

///////////////////////////////////////////////////////
// LCD setup - 20x4
SoftwareSerial LCD(0, txPin);

void lcdPosition(int row, int col) {
  LCD.write(0xFE);   //command flag
  LCD.write((col + row*64 + 128));    //position 
  delay(LCDdelay);
}


void lcdPositionLine2() {
  LCD.write(0xFE);   //command flag
  LCD.write(0x45);
  LCD.write(0x40);
  delay(LCDdelay);
}

void lcdPositionLine3() {
  LCD.write(0xFE);   //command flag
  LCD.write(0x45);
  LCD.write(0x14);
  delay(LCDdelay);
}

void lcdPositionLine4() {
  LCD.write(0xFE);   //command flag
  LCD.write(0x45);
  LCD.write(0x54);
  delay(LCDdelay);
}

void clearLCD(){
  LCD.write(0xFE);   //command flag
  LCD.write(0x51);   //clear command.
  delay(LCDdelay);
}

void serCommand(){   //a general function to call the command flag for issuing all other commands   
  LCD.write(0xFE);
}

void setLCDContrast() {
  LCD.write(0xFE);   //command flag
  LCD.write(0x52);
  LCD.write(40);	//value 1 to 50 (50 is highest contrast)
  delay(LCDdelay);
}


void setLCDBrightness() {
  LCD.write(0xFE);   //command flag
  LCD.write(0x53);
  LCD.write(5);  //value 1 to 8
  delay(LCDdelay);
}


///////////////////////////////////////////////////////
// SETUP function
void setup()
{
  pinMode(13, OUTPUT);  // LED
  pinMode(2, INPUT);     // DATA0 (INT0)
  pinMode(3, INPUT);     // DATA1 (INT1)
  
  Serial.begin(57600);
  Serial.println("RFID Readers");
  
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  
  setLCDContrast();
  setLCDBrightness();
  
  // Setup output pin to SD card
  pinMode(10, OUTPUT);
  pinMode(chipSelect, OUTPUT);
  
  
  // Initialize SD card
  while(!sd.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("No SD Card!");
    clearLCD();
    LCD.print("No SD Card!");  
  }
  // Commented out with no LCD
  if(!sd.init(SPI_HALF_SPEED, chipSelect)) {
    clearLCD();
    LCD.print("Problem with SD card");
  }
  else {
    clearLCD();
    LCD.print("SD card initialized.");
  }
 
  
  // binds the ISR functions to the falling edge of INTO and INT1
  attachInterrupt(0, ISR_INT0, FALLING);  
  attachInterrupt(1, ISR_INT1, FALLING);

  weigand_counter = WEIGAND_WAIT_TIME;
}


///////////////////////////////////////////////////////
// LOOP function
void loop()
{
  // This waits to make sure that there have been no more data pulses before processing data
  if (!flagDone) {

    
    if (--weigand_counter == 0)
      flagDone = 1;	
  }
  
  // if we have bits and we the weigand counter went out
  if (bitCount > 0 && flagDone) {
    unsigned char i;
    
    getCardValues();
    getCardNumAndSiteCode();
       
    printBits();
    writeSD();

     // cleanup and get ready for the next card
     bitCount = 0; facilityCode = 0; cardCode = 0;
     bitHolder1 = 0; bitHolder2 = 0;
     cardChunk1 = 0; cardChunk2 = 0;
     
     for (i=0; i<MAX_BITS; i++) 
     {
       databits[i] = 0;
     }
  }
}

///////////////////////////////////////////////////////
// PRINTBITS function
void printBits()
{
      // I really hope you can figure out what this function does
      Serial.print(bitCount);
      Serial.print(" bit card. ");
      Serial.print("FC = ");
      Serial.print(facilityCode);
      Serial.print(", CC = ");
      Serial.print(cardCode);
      Serial.print(", 44bit HEX = ");
      Serial.print(cardChunk1, HEX);
      Serial.println(cardChunk2, HEX);
      
      clearLCD();
      LCD.print(bitCount);
      LCD.print(" bit card.");
      lcdPositionLine2();
      LCD.print("Facility = ");
      LCD.print(facilityCode);
      lcdPositionLine3();
      LCD.print("Card = ");
      LCD.print(cardCode);
      lcdPositionLine4();
      LCD.print("44bitHEX= ");
      LCD.print(cardChunk1, HEX);
      LCD.print(cardChunk2, HEX);
      
      delay(2500);
      clearLCD();
}


///////////////////////////////////////////////////////
// SETUP function
void getCardNumAndSiteCode()
{
     unsigned char i;
  
    // we will decode the bits differently depending on how many bits we have
    // see www.pagemac.com/azure/data_formats.php for more info
    // also specifically: www.brivo.com/app/static_data/js/calculate.js
    switch (bitCount) {

      
    ///////////////////////////////////////
    // standard 26 bit format
    // facility code = bits 2 to 9  
    case 26:
      for (i=1; i<9; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
      
      // card code = bits 10 to 23
      for (i=9; i<25; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }
      break;

    ///////////////////////////////////////
    // 33 bit HID Generic    
    case 33:  
      for (i=1; i<8; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
      
      // card code
      for (i=8; i<32; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }    
      break;

    ///////////////////////////////////////
    // 34 bit HID Generic 
    case 34:  
      for (i=1; i<17; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
      
      // card code
      for (i=17; i<33; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }    
      break;
 
    ///////////////////////////////////////
    // 35 bit HID Corporate 1000 format
    // facility code = bits 2 to 14     
    case 35:  
      for (i=2; i<14; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
      
      // card code = bits 15 to 34
      for (i=14; i<34; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }    
      break;

    }
    return;
  
}

Part 2 of 2. The entire code zip file can be downloaded at http://www.bishopfox.com/download/814/ if you choose. Thank you for taking the time to look at this.

//////////////////////////////////////
// Function to append the card value (bitHolder1 and bitHolder2) to the necessary array then tranlate that to
// the two chunks for the card value that will be output
void getCardValues() {
  switch (bitCount) {
    case 26:
        // Example of full card value
        // |>   preamble   <| |>   Actual card value   <|
        // 000000100000000001 11 111000100000100100111000
        // |> write to chunk1 <| |>  write to chunk2   <|
        
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 2){
            bitWrite(cardChunk1, i, 1); // Write preamble 1's to the 13th and 2nd bits
          }
          else if(i > 2) {
            bitWrite(cardChunk1, i, 0); // Write preamble 0's to all other bits above 1
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 20)); // Write remaining bits to cardChunk1 from bitHolder1
          }
          if(i < 20) {
            bitWrite(cardChunk2, i + 4, bitRead(bitHolder1, i)); // Write the remaining bits of bitHolder1 to cardChunk2
          }
          if(i < 4) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i)); // Write the remaining bit of cardChunk2 with bitHolder2 bits
          }
        }
        break;

    case 27:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 3){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 3) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 19));
          }
          if(i < 19) {
            bitWrite(cardChunk2, i + 5, bitRead(bitHolder1, i));
          }
          if(i < 5) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 28:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 4){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 4) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 18));
          }
          if(i < 18) {
            bitWrite(cardChunk2, i + 6, bitRead(bitHolder1, i));
          }
          if(i < 6) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 29:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 5){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 5) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 17));
          }
          if(i < 17) {
            bitWrite(cardChunk2, i + 7, bitRead(bitHolder1, i));
          }
          if(i < 7) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 30:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 6){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 6) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 16));
          }
          if(i < 16) {
            bitWrite(cardChunk2, i + 8, bitRead(bitHolder1, i));
          }
          if(i < 8) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 31:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 7){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 7) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 15));
          }
          if(i < 15) {
            bitWrite(cardChunk2, i + 9, bitRead(bitHolder1, i));
          }
          if(i < 9) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 32:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 8){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 8) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 14));
          }
          if(i < 14) {
            bitWrite(cardChunk2, i + 10, bitRead(bitHolder1, i));
          }
          if(i < 10) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 33:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 9){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 9) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 13));
          }
          if(i < 13) {
            bitWrite(cardChunk2, i + 11, bitRead(bitHolder1, i));
          }
          if(i < 11) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 34:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 10){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 10) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 12));
          }
          if(i < 12) {
            bitWrite(cardChunk2, i + 12, bitRead(bitHolder1, i));
          }
          if(i < 12) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 35:        
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 11){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 11) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 11));
          }
          if(i < 11) {
            bitWrite(cardChunk2, i + 13, bitRead(bitHolder1, i));
          }
          if(i < 13) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 36:
       for(int i = 19; i >= 0; i--) {
          if(i == 13 || i == 12){
            bitWrite(cardChunk1, i, 1);
          }
          else if(i > 12) {
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 10));
          }
          if(i < 10) {
            bitWrite(cardChunk2, i + 14, bitRead(bitHolder1, i));
          }
          if(i < 14) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;

    case 37:
       for(int i = 19; i >= 0; i--) {
          if(i == 13){
            bitWrite(cardChunk1, i, 0);
          }
          else {
            bitWrite(cardChunk1, i, bitRead(bitHolder1, i + 9));
          }
          if(i < 9) {
            bitWrite(cardChunk2, i + 15, bitRead(bitHolder1, i));
          }
          if(i < 15) {
            bitWrite(cardChunk2, i, bitRead(bitHolder2, i));
          }
        }
        break;
  }
  return;
}


//////////////////////////////////////
// Begin code for SD card
void writeSD() {
  
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    ofstream file(dataFile, ios::out | ios::app);
 
  
    // if the file is available, write to it:
    if (file) {
      file << bitCount;
      //file << dec << bitCount;
      file << " bit card: ";
      file << hex << cardChunk1;
      file << hex << cardChunk2;
      file << ", FC = ";
      //file << facilityCode;
      file << dec << facilityCode;
      file << ", CC = ";
      //file << cardCode;
      file << dec << cardCode;
      file << ", BIN: ";
      for (int i = 19; i >= 0; i--) {
        file << bitRead(cardChunk1, i);
      }
      for (int i = 23; i >= 0; i--) {
        file << bitRead(cardChunk2, i);
      }
      file << endl;
      
      // print to the serial port too
      Serial.println("Wrote data to SD card");
    }
    else {
      clearLCD();
      LCD.print("Error writing to file");
    }
}

// End code for SD card

And here is a list of my errors.

Tastic_RFID_Arduino_Code:93: error: 'SdFat' does not name a type
Tastic_RFID_Arduino_Code:94: error: 'SdFile' does not name a type
Tastic_RFID_Arduino_Code.cpp: In function 'void setup()':
Tastic_RFID_Arduino_Code:220: error: 'sd' was not declared in this scope
Tastic_RFID_Arduino_Code:220: error: 'SPI_HALF_SPEED' was not declared in this scope
Tastic_RFID_Arduino_Code:226: error: 'sd' was not declared in this scope
Tastic_RFID_Arduino_Code:226: error: 'SPI_HALF_SPEED' was not declared in this scope
Tastic_RFID_Arduino_Code.cpp: In function 'void writeSD()':
Tastic_RFID_Arduino_Code:657: error: 'ofstream' was not declared in this scope
Tastic_RFID_Arduino_Code:657: error: expected `;' before 'file'
Tastic_RFID_Arduino_Code:661: error: 'file' was not declared in this scope
Tastic_RFID_Arduino_Code:665: error: 'hex' was not declared in this scope
Tastic_RFID_Arduino_Code:669: error: 'dec' was not declared in this scope
Tastic_RFID_Arduino_Code:680: error: 'endl' was not declared in this scope