Wiegand RFID reader with arduino

RFID reader, Reader/Writer, Tag.....

Wiegand RFID reader with arduino

Postby Granada » Tue Nov 11, 2014 8:47 pm

Hi, I'm still new to arduino. I got a problem with this wiegand reader when using Arduino Mega. I attached the program that I copypasted (and edited abit). I suspect my problem is the MEGA did not received the signal from the reader. Can anyone help me with this?


Code: Select all
#define DATA0 20
#define DATA1 21
#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");                    //to check wether the interupt works or not
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 

}

// interrupt that happens when INT1 goes low (1 bit)
void ISR_INT1()
{
  Serial.print("1");                   //to check wether the interupt works or not
  databits[bitCount] = 1;
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
}   


void setup()
{

  pinMode(DATA0, INPUT);             //green wire or wiegand reader
  pinMode(DATA1, INPUT);             //white wire or wiegand reader

  Serial.begin(9600);
  Serial.println("put your card");

  // binds the ISR functions to the falling edge of INTO and INT1
  attachInterrupt(2, ISR_INT0, FALLING); 
  attachInterrupt(3, 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. ");
  }


  if (bitCount == 26)
  {
    // standard 26 bit format
    // facility code = bits 2 to 9
   
    for (int i=1; i<9; i++)
    {
      facilityCode <<=1;
      facilityCode |= databits[i];
    }

    // card code = bits 10 to 23
     
    for (int i=9;i<25; i++)
    {
      cardCode <<=1;
      cardCode |= databits[i];
    }
     
    Serial.print("FC = ");
    Serial.print(facilityCode);
    Serial.print(", CC = ");
    Serial.println(cardCode);
   
  }

  else
  {
    // if not 26 bit wiegand reader, it wll display comment below
    Serial.println("No Card Detected");
  }
 
}
Granada
Fledgling
 
Posts: 1
Joined: Tue Nov 11, 2014 8:37 pm

Return to RFID

Who is online

Users browsing this forum: No registered users and 1 guest