[SOLVED] RFID Prox Card -> Reader -> Wiegand -> Arduino -> Controller

I'm looking to make a sort of proxy out of the arduino. The arduino would sit in between an HID ProxPoint reader and a VertX controller. but i'm having some code problems.

I can read data in from the reader fine. And almost always can process that data and print it to the Serial Port after processing.

However, for whatever reason, when the either of the following conditions exist, the card value incorrectly changes after processing:

  1. PINs 8 & 9 (out put pins) are connected to the controller
  2. I try to digitalWrite() to the output PINs when they are connected to the controller.

For example, here's a snip of my code, this fails when pins 8 and 9 are connected to the DATA 0 and DATA 1 ports of the controller

    if (reader1 & mask) {
      Serial.print("1"); 
      digitalWrite(toVertX_D1, LOW);
      delayMicroseconds(50);
      digitalWrite(toVertX_D1, HIGH);
    } else {
      Serial.print("0");
      digitalWrite(toVertX_D0, LOW);
      delayMicroseconds(50);
      digitalWrite(toVertX_D0, HIGH);
    }

however if i comment out the delays and writes this code works fine:

    if (reader1 & mask) {
      Serial.print("1"); 
      //digitalWrite(toVertX_D1, LOW);
      //delayMicroseconds(50);
      //digitalWrite(toVertX_D1, HIGH);
    } else {
      Serial.print("0");
      //digitalWrite(toVertX_D0, LOW);
      //delayMicroseconds(50);
      //digitalWrite(toVertX_D0, HIGH);
    }

Here are some outputs:

Via serial with the controller connected to PIN 8&9 (same card read over and over) and the writes/delays uncommented

(binary strings should always be the same)

R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010111101010101010001
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010111101010101010001
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010110010011010010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010111101010101010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010110010011010010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1010110101011010010101

Now if i disconnect PINs 8&9 (no code change), everything works fine

(notice binary strings are the same)

R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101
R1: 263F95 SC:19 C: 8138
1001100011111110010101
1001100011111110010101

Odd.. any ideas?

UPDATE:
A friend recommended copying reader1 to a new variable before writing it. The thought here is that the writes were somehow causing the interrupts, and changing reader1. well it worked!

Here's the writeCard() function now:

void writeCard() {
  //unsigned long mask = 2097152; 
  // unsigned long mask = 0x100000;
  // In Binary: 100000000000000000000
  unsigned long mask = 0x200000;
  // In Binary: 1000000000000000000000
  
  //unsigned long mask =0x100000;                      
  //int count=0;
  for (short x=1; x<23; x++) {
    //Serial.print("\nMask: ");
    //Serial.println(mask,BIN);
    if (reader1 & mask) {
      Serial.print("1"); 
      digitalWrite(toVertX_D1, LOW);
      delayMicroseconds(50);
      digitalWrite(toVertX_D1, HIGH);
    } else {
      Serial.print("0");
      digitalWrite(toVertX_D0, LOW);
      delayMicroseconds(50);
      digitalWrite(toVertX_D0, HIGH);
    }
    //delayMicroseconds(1);
    mask >>= 1;
    //count++;
  }
  Serial.println();
}