EEPROM save and recall

G'day all I am fairly new to coding, and I'm learning. I was wondering if someone would be kind enough to steer me in the right direction on how to store the outputted decodeded wiegand data into the arduino eeprom, so whenever I introduce a card to the reader it saves the decoded data onto the arduino eeprom. Also I would like to have a way to use the serial monitor to confirm that the data was saved as well as a way to retrieve the data and see it on the serial monitor. For example: Press S in serial monitor and it saves, or press a button on my bread board and it saves to location on eeprom, the data does not get overwritten when I introduce a new card, but if I already swiped the same card it checks against what is already saved and gives message "card already entered". After that I would like to work on date and time stamping the saved info, so I can use a menu structure to scroll and pick. Any help would be appreciated. I have looked through the internet for 2 days to try to understand how to accomplish this but questions are not fully answered :frowning:

#define MAX_BITS 100                 // max number of bits 
#define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse.  

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

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

// interrupt that happens when INTO goes low (0 bit)
void ISR_INT0()
{
  //Serial.print("0");
  bitCount++;
  flagDone = 0;
  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;
  weigand_counter = WEIGAND_WAIT_TIME;  
}

void setup()
{
  pinMode(13, OUTPUT);  // LED
  pinMode(2, INPUT);     // DATA0 (INT0)
  pinMode(3, INPUT);     // DATA1 (INT1)
  
  Serial.begin(9600);
  Serial.println("RFID Readers");
  
  // 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;
}

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;
    
    Serial.print("Read ");
    Serial.print(bitCount);
    Serial.print(" bits. ");
    
    // we will decode the bits differently depending on how many bits we have
    // see www.pagemac.com/azure/data_formats.php for mor info
    if (bitCount == 35)
    {
      // 35 bit HID Corporate 1000 format
      // facility code = bits 2 to 14
      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];
      }
      
      printBits();
    }
    else if (bitCount == 26)
    {
      // standard 26 bit format
      // facility code = bits 2 to 9
      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];
      }
      
      printBits();  
    }
    else {
      // you can add other formats if you want!
     Serial.println("Unable to decode."); 
    }

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

void printBits()
{
      // I really hope you can figure out what this function does
      Serial.print("FC = ");
      Serial.print(facilityCode);
      Serial.print(", CC = ");
      Serial.println(cardCode); 
}

Did you write your code in italics?
Then please read the how to use this forum stick post and edit you post to include the correct code tags.
Then we can talk.

Thanks Grumpy!! I should have figured that out....So can we now talk? Would love to learn and see where I need to go with this. Any help would be appreciated

Thanks for making the change.

First off you need to know how many bits the Wiegand data is. Put the data in a long int 32 bits or less or a long long 64 bits or less.
These examples are for 64 bit data tokens.
Next do you actually want to enroll every new token you see?

Anyway to save a token in EEPROM you need something like this:-

 void saveToken(int point){ // saves the token in EEprom memory at point
    EEPROM.write(point, (tokensOnBoard[0] >> 24) & 0xff);
    EEPROM.write(point+1, (tokensOnBoard[0] >> 16) & 0xff);
    EEPROM.write(point+2, (tokensOnBoard[0] >> 8) & 0xff);
    EEPROM.write(point+3, tokensOnBoard[0] & 0xff);
    EEPROM.write(point+4,value[6]);
    EEPROM.write(point+5,value[7]);
    EEPROM.write(point+6,value[8]);
 }

Where point is the memory location in the EEPROM you want to save it.
In this implementation then there is a token (and some other data) every 7 bytes

Now to search the memory to see if a token is already stored then you can use this:-

 int matchToken(unsigned long token){
   int i = 0;
   boolean found = false;
   while( found == false && i < 1000){
     if( EEPROM.read(i) == ((token >> 24)& 0xff) &&  EEPROM.read(i+1) == ((token >> 16)& 0xff)
             &&  EEPROM.read(i+2) == ((token >> 8)& 0xff) &&  EEPROM.read(i+3) == (token & 0xff) ){
               found = true;
           }
           if(!found) i +=7; // move on to the start of the next entry
   }
   if(found) return i; else return -1;
 }

Finally to search for a free space to store a token
use this:-

 int findFreeEntry(){
   int i = 0;
   boolean found = false;
   while( found == false && i < 1000){
     if( EEPROM.read(i) == 0xff && EEPROM.read(i+1) == 0xff && EEPROM.read(i+2) == 0xff && EEPROM.read(i+3) == 0xff ) found = true;
     if(!found) i +=7;
    }
      if(found) return i; else return -1;
 }

Grumpy, thank you so much for the exceptional reply and how quick it was!!!....but I am being ignorant here, and I am not the best at placing what you wrote where in this RFID sketch. If I could see the modified sketch it would help me understand, where I can go back and research what has been modified. I am not that great yet to fully understand what it is I need to do. I thought it would have been cool to save decoded card data onto eeprom and have a way to access the arduino eeprom to see it on the serial monitor. Scan-->Save on eeprom--> retrieve data and see it on the monitor. As it reads in the sketch it is 26bit wiegand, and 35bit wiegand. I know It may seem like I am dumb here, it may be straight forward to some, but I am just starting out and I need the "EEPROM book for dummie"s version. Again Grumpy thanks for the reply and the ever sufficient (i'm assuming) answer and I am very greatful for that, but I do need someone to hold my hand while I do this. Please Grumpy Help me further?

sorry grumpy...forgot that the wiegand decoded code 8 bit facility code and the next is a 16 bit card code, the first and last are parity

bent:
sorry grumpy...forgot that the wiegand decoded code 8 bit facility code and the next is a 16 bit card code, the first and last are parity

That matters not from the storage point of view. If you have a maximum of 35 bits the you can store one of those in only five bytes.
Basically EEPROM stors data one byte at a time so when you have multi byte data like an int or long int you have to break it down into individual bytes in order to store it. You also need to know where to store it. EEPROM is just a free field of memory you can store bytes anywhere, but it is easier if they are next to each other.

Maybe you need to do a few tutorials first to get the hang of coding.

Again thanks Grumpy!! Yes you are correct, I am reading about memory and storage. I do understand all that. What I get stuck on is the code snippet you gave me, you have...

EEPROM.write(point, (tokensOnBoard[0] >> 24) & 0xff);

the "tokensOnBoard[0]" this is from code you wrote for a project, so I need to put my declaration in here somewhere, but I get stuck on what it is I need to place here. So I am thinking in place of "tokensOnBoard[0]" I need to put "facilityCode |= databits*"*
or...."facilityCode" and "cardCode" respectively?
again thanks for your help, and I know this can be frustrating with code noobs like me!!

The tokensOnBoard[0] is the long int that contains the whole of your token board. Do not split it up into facility code and access code at this stage just store the whole of what you have read.
As I said the code is breaking that variable down into seprate bytes because you can only store bytes in memory. The language does it for you normally but for EEPROM you have to do it yourself.

Thank you very much Grumpy you have been a great help. I will try what you have suggested