Magnetic strip card reader project

This seems to be the document that shows the bit timing:

STROBE is a digital input to the ASIC and should be normally held high. When the DATA line goes low at the end of a card swipe, STROBE should be pulsed low twice to complete the required “handshake” and shift out stored data in the ASIC buffer to the DATA output.

Each track is 608 bits, starting with the first 1-bit scanned. As you continue to strobe, the head sends Track A, Track B, and Track C bits in the order the bits were read. Then Track C, Track B, and Track A bits, each in reverse bit order. The pattern then repeats until you reset the head (power off?)

Sounds easy enough. 76 bytes per track. 3 or 6 tracks, depending on if you want to store the reversed versions or not.

const byte StrobePin = 2;
const byte DataPin = 3;
const byte PowerPin = 4;

byte ForwardABuffer[76];
byte ForwardBBuffer[76];
byte ForwardCBuffer[76];
byte BackwardABuffer[76];
byte BackwardBBuffer[76];
byte BackwardCBuffer[76];

byte ReadByte()
{
  byte b = 0;
  for (int i = 0; i < 8; i++)
  {
    digitalWrite(StrobePin, LOW);
    b <<= 1;
    b |= !digitalRead(DataPin); // LOW = 1 and HIGH == 0
    digitalWrite(StrobePin, HIGH);
  }
  return b;
}

void ReadTrack(byte buffer[76])
{
  for (int i = 0; i < 76; i++)
    buffer[i] = ReadByte();
}

void ResetHead()
{
  // Power down the head
  digitalWrite(PowerPin, LOW);

  delay(10);

  // Power up the head
  digitalWrite(PowerPin, HIGH);

  delay(10);
}

void setup()
{
  pinMode(DataPin, INPUT);

  digitalWrite(StrobePin, HIGH);
  pinMode(StrobePin, OUTPUT);

  // Power up the head
  pinMode(PowerPin, OUTPUT);
  digitalWrite(PowerPin, HIGH);
}

void loop()
{
  if (digitalRead(DataPin) == LOW)
  {
    // Falling Edge means data is ready

    // Strobe twice to get to the data
    digitalWrite(StrobePin, LOW);
    digitalWrite(StrobePin, HIGH);
    digitalWrite(StrobePin, LOW);
    digitalWrite(StrobePin, HIGH);

    ReadTrack(ForwardABuffer);
    ReadTrack(ForwardBBuffer);
    ReadTrack(ForwardCBuffer);
    ReadTrack(BackwardCBuffer);
    ReadTrack(BackwardBBuffer);
    ReadTrack(BackwardABuffer);

    ResetHead();

    // Process the raw bits here
    
  }
}
2 Likes