Pages: [1]   Go Down
Author Topic: Different RFID-Codes via different sketches...but which result is true?  (Read 266 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tested some sketches with the same rfid-reader and there same tags but there are some differences in the resulting tag codes. At first I have tried this sketch

with the following results:

Tag1 -> 244  49666

Tag2 -> 129  42492

Then I have tried a modified Version from

where the results are:

Tag1 -> 50547704 respective 385  9724

Tag2 -> 32080900 respective 244  514

this is the modified code:

/* Crazy People
 * By Mike Cook April 2009
 * Three RFID readers outputing 26 bit Wiegand code to pins:-
 * Reader A (Head) Pins 2 & 3
 * Interrupt service routine gathers Wiegand pulses (zero or one) until 26 have been recieved
 * Then a sting is sent to processing

volatile long reader1 = 0;
volatile int reader1Count = 0;

void reader1One(void) {
  reader1 = reader1 << 1;
  reader1 |= 1;

void reader1Zero(void) {
  reader1 = reader1 << 1;

void setup()
  // Attach pin change interrupt service routines from the Wiegand RFID readers
  attachInterrupt(0, reader1Zero, RISING);//DATA0 to pin 2
  attachInterrupt(1, reader1One, RISING); //DATA1 to pin 3
  // the interrupt in the Atmel processor mises out the first negitave pulse as the inputs are already high,
  // so this gives a pulse to each reader input line to get the interrupts working properly.
  // Then clear out the reader variables.
  // The readers are open collector sitting normally at a one so this is OK
  for(int i = 2; i<4; i++){
  pinMode(i, OUTPUT);
   digitalWrite(i, HIGH); // enable internal pull up causing a one
  digitalWrite(i, LOW); // disable internal pull up causing zero and thus an interrupt
  pinMode(i, INPUT);
  digitalWrite(i, HIGH); // enable internal pull up
  // put the reader input variables to zero
  reader1 = 0;
  reader1Count = 0;
  //digitalWrite(13, HIGH);  // show Arduino has finished initilisation

void loop() {
  if(reader1Count >=26){
//Serial.print(" Reader 1 ");
 // Serial.println("A");
 //Serial.println(reader1& 0xfffffff);
 int serialNumber=(reader1 >> 1) & 0x3fff;
 int siteCode= (reader1 >> 17) & 0x3ff;

 Serial.print("  ");
  reader1 = 0;
  reader1Count = 0;

Manchester (England England)
Online Online
Brattain Member
Karma: 634
Posts: 34566
Solder is electric glue
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code from the Crazy People includes the parity bits at the start and end of the code. This is not normally considers as part of the token value and will be excluded from the first example.
For Crazy people it did not matter so I didn't bother checking the parity and just used the whole number.

Pages: [1]   Go Up
Jump to: