How to connect Magnetic Card Reader to Arduino, PS/2????

Hello,

I am trying to hook up my magnetic card reader to my Arduino Uno and display the data into the serial terminal or store in a variable. The mag reader I purchased is located here https://www.sparkfun.com/products/11096
and it comes with a PS/2 male and female and a RS 232 female connectors. I have no idea which connectors I should use, but I decided to go with the female PS/2. (Please let me know if this is a bad decision)

Currently I have cut of the female PS/2 and stripped the wires back to see
BLACK,RED,GREEN,WHITE.
I know that BLACK = gnd, RED = 5v, GREEN and WHITE must be clock and data? vice versa?

My sketch (not really mine) compiles while using the PS/2 library. The latest lib I found is PS2Keyboard (version 2.4) found here https://github.com/PaulStoffregen/PS2Keyboardl along with the example sketch I have been using found here http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html, also seen below.

#include <PS2Keyboard.h>

const int DataPin = 5;
const int IRQpin =  8;

PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  Serial.println("Keyboard Test:");
}

void loop() {
  if (keyboard.available()) {
    Serial.println("WORKING");//to see if statement is runninf DEBUGING
    // read the next key
    char c = keyboard.read();
    
    // check for some of the special keys
    if (c == PS2_ENTER) {
      Serial.println();
    } else if (c == PS2_TAB) {
      Serial.print("[Tab]");
    } else if (c == PS2_ESC) {
      Serial.print("[ESC]");
    } else if (c == PS2_PAGEDOWN) {
      Serial.print("[PgDn]");
    } else if (c == PS2_PAGEUP) {
      Serial.print("[PgUp]");
    } else if (c == PS2_LEFTARROW) {
      Serial.print("[Left]");
    } else if (c == PS2_RIGHTARROW) {
      Serial.print("[Right]");
    } else if (c == PS2_UPARROW) {
      Serial.print("[Up]");
    } else if (c == PS2_DOWNARROW) {
      Serial.print("[Down]");
    } else if (c == PS2_DELETE) {
      Serial.print("[Del]");
    } else {
      
      // otherwise, just print all normal characters
      Serial.print(c);
    }
  }
}

I just can’t seem to get any output. I have done some debugging and I don’t think the if statement keyboard.available() is even running. Therefore the sketch isn’t picking up the magnetic reader??? I really don’t know. If I had to guess, it’s probably because I used the wires from the female PS/2 and not male, but I have no clue.

Please let me know if anyone needs more information to solve this problem.

Thanks so much in advance,

Zeta

The product page and datasheet for that card reader imply that the PS/2 port is only used for power, and that the actual data appears on the serial port (DB9 connector.) That explains the two connectors - you plug one end into your PC, and the other end into a regular keyboard. The card reader siphons off a bit of the power that the PC normally sends to the keyboard, but otherwise lets the keyboard communicate normally.

There's another common type of "reader" (particularly common with bar code scanners) that plugs in this way, and actually sends the data from the keyboard OR the reader, so that the PC can't tell whether the keystrokes come from the keyboard or the reader. I guess this is what you were expecting, but I don't think it's what you have.

You should be able to read from the serial port with the SoftwareSerial library (and possibly some external hardware.) You'd want to use the "inverse_logic" option for interfacing with minimal hardware.

Thanks so much, I’ll try this right away. :slight_smile: