RFID tagid, should tagid read match with printed id ?

Hi,

I just received the 125Kz RFID reader with Wiegand interface. (compliments on the service ! :slight_smile:)
The example code provided doesn’t produce sensible output on my Seeduino v328, therefore I created my own sketch (attached at bottom of this post).

I get 5 different codes for my 5 tags (3 keyrings + 2 cards) which is fine, however the codes read do not match the codes printed on the keyrings.

Now the main question is: should the codes read match the printed codes ?

E.g. skipping the parity bits at the front and back one of my tokens returns:
011000001110001101100110

Looking at the data sheet it seems that this should be interpreted as the last 3 bytes of a 4 byte long value.
(translation of the datasheet could be improved though :wink: )

As a long the bit sequence produces 6349670
The example code provided produces 4 decimals (although the latter is always 0 !)
Reading the bit string as 3 separate bytes produces: 96 227 102

The code on the keyring however is 0010427545.

If the codes read via RFID should match the printed codes then I am very curious what kind of coding is being used !! :slight_smile:

Kind regards,

Hans

// RFID Wiegand interface v3
// J. Klunder , September 3, 2009

// which ports to use
int data0 = 8;
int data1 = 9;

long card_num=0;

int bitnum;
    
boolean processBit(int d1){
   switch (bitnum) {
      case 0: // parity even 
        break;
      case 25: // parity odd + ready
        bitnum=0;
        return(true);
        break;
      default:
        if (d1 == 0){
           bitSet(card_num,24-bitnum);
        }
        break;
  }
  bitnum++;
  return(false);
}

void setup(){
  Serial.begin(9600);
  pinMode(data0 , INPUT);
  pinMode(data1 , INPUT);
  bitnum=0;
}

void loop(){
  int d0 = digitalRead(data0);
  int d1 = digitalRead(data1);
  if (d0 != d1){
    // we got signal ;-)
    if (processBit(d1)){
      // we got a complete sequence
      Serial.println(card_num,DEC);
      card_num=0; //reset card_number 
    }
    delayMicroseconds(80); // Data impulse width delay 80us
  }
}   

I’ve noticed the same data-ID/printed-ID mismatch as well.

jklu thank you so much for this nice easy to understand code… it helped me very much for my “diplomarbeit” (masterthesis) about homeautomation with the arduino :slight_smile:

the c-code in the shop didnt work properly… it read in wrong values.
but yours is perfect :slight_smile:

best regards from hamburg
simon