How to Register a USB Keypad?

Hello everyone,
I have a gear head keypad Robot or human? and I can't figure out how to get it to register on my arduino.

I'm trying to follow this http://www.libelium.com/tienda/catalog/includes/languages/english/pdf/LIFE_HACKS-WINNER-ARDUINO_SECURITY.pdf project. The code is copied except I added in a relay.

When I plug the keypad into the ps/2 adapter, connected to my arduino, the numlock LED lights up for a short second, then it shuts off.
When I plug the keypad into a computer, nothing happens for about 5 seconds, then you get messages on your monitor saying the computer is looking for new hardware. Then it found new hardware. Lastly, you can use your new hardware.
I don't of course get any of this on my arduino.

Does anyone know how to register such a keypad?

#define DEBUG 0
#define VERSION "v0.7 17Apr2008"

//SCANCODES PS/2 KEYBOARDS

#define SCAN_ENTER 0xE0
#define SCAN_BREAK 0xf0
byte scanCodes[10] = {0x70,0x69,0x72,0x7A,0x6B,0x73,0x74,0x6C,
0x75,0x7D};
char characters[10] = {'0','1','2','3','4','5','6','7','8','9'};
int quantityCodes = 10;

//KEYBOARD HANDLING VARS
byte dataValue;

// PINS
int clockPin = 3; //KEYBOARD CLK
int dataPin = 2; //KEYBOARD DAT
int soundPin = 9; // TEST
int servoPin = 10;
int closePin = 7;// DOOR "Switch"
int speakerPin = 12; //Optional Speaker VCC
int relay = 1;                                                  //What I added

// PASSWORD
char mypass[11]="12345\0";
char pass[11];
int passlen=0;
char letra;

void setup()
{
    pinMode(dataPin, INPUT);
    pinMode(clockPin, INPUT);
    pinMode(closePin, INPUT);
    pinMode(speakerPin, OUTPUT);
    pinMode(relay, OUTPUT);               //What I added
        if (DEBUG)
        {
            Serial.begin(9600);
            analogWrite(soundPin,100);
            Serial.println("ARDUINO DOOR OPENER ONLINE");
            Serial.println(VERSION);
        }
    startupSound();
}

void loop()
{
    dataValue = dataRead();
        if (dataValue == SCAN_BREAK)
        {
            dataValue = dataRead(); // Reading the key that wasepressed
            dataValue = dataRead(); // Wait for and read a new key
        }
    pinMode(clockPin,OUTPUT);
    digitalWrite(clockPin,LOW);
        for (int i = 0; i < quantityCodes; i++)
        {
            byte temp = scanCodes[i];
            if (temp == dataValue || dataValue == SCAN_ENTER)
        {
    letra=characters[i];
        if (DEBUG) Serial.println(letra);
        // If enter read
            if(dataValue == SCAN_ENTER)
               {
                digitalWrite(clockPin,HIGH);
                pinMode(clockPin,INPUT);
                dataValue = dataRead();
                pinMode(clockPin,OUTPUT);
                digitalWrite(clockPin,LOW);
                    
                    if(dataValue == 0x5A)
                        {pass[passlen+1]='\0';
                         if (strcmp(pass,mypass)==0) 
                        {Serial.println("Abriendo");OpenDoo();
                         }
                          else {errorSound(); for (int i=0;i<=passlen; i++)
                   {Serial.print(pass[i]);} 
                           }

                    Serial.println();
                        for (int i=0; i<=10; i++) pass[i]='\0';
                      passlen=0;
                  }
                    }

 //if not enter read
       else
                     {pass[passlen]=letra;
                      if (DEBUG)
                            {
                          Serial.print(letra); Serial.print(" ");
                          Serial.print(pass[passlen]);Serial.print(" ");
                    Serial.print(passlen);
                    Serial.print(" PASS="); for (int i=0; i<=passlen; i++)
                    Serial.print(pass[i]); Serial.println();
                     }
                       passlen++;
                         
                               if (passlen==10) passlen=0;
                         }
                         dataValue = 0;
                      letra=0;
    
//delay(200);
                                   }
                         }

                           digitalWrite(clockPin,HIGH);
                           pinMode(clockPin,INPUT);
                            }

void OpenDoor()
{

  // OPEN
digitalWrite(relay, HIGH);                            //What I added
delay(3000);
 
analogWrite(servoPin,40);
openSound();
delay(3000);
analogWrite(servoPin,0);
    while (!digitalRead(closePin)) delay(250);

//CLOSE
digitalWrite(relay, LOW);           //What I added

analogWrite(servoPin,220);
closeSound();
delay(2000);
analogWrite(servoPin,0);
}

int dataRead() {
byte val = 0;
int v = 0;
    while (digitalRead(clockPin)); // Waiting for LOW
        while (!digitalRead(clockPin));// Waiting for HIGH
            while (digitalRead(clockPin)); // Waiting for LOW
                for (int offset = 0; offset < 8; offset++)
                            {
                    while (digitalRead(clockPin)); // Waiting for LOW
                    val |= digitalRead(dataPin) << offset; // Adding to byte
                        while (!digitalRead(clockPin)); // Waiting for HIGH
                            }
                        while (digitalRead(clockPin)); // Waiting for LOW
                            while (!digitalRead(clockPin)); // Waiting for HIGH
                                while (digitalRead(clockPin)); // Waiting for LOW
                                    while (!digitalRead(clockPin)); // Waiting for HIGH
return val;
                }

void errorSound()
                {
    int n = 2000;
        for (int vez=0;vez<2;vez++){
            for (int _=0;_<30;_++){
                delayMicroseconds(n);
                digitalWrite(speakerPin, HIGH);
                delayMicroseconds(n);
                digitalWrite(speakerPin, LOW);
            }
        
        delay(50);
    }
}

void openSound()
{
    int n = 300;
        for (int vez=0;vez<3;vez++){
            for (int _=0;_<100;_++){
                delayMicroseconds(n);
                digitalWrite(speakerPin, HIGH);
                delayMicroseconds(n);
                digitalWrite(speakerPin, LOW);
            }
        delay(100);
        }
    }

void closeSound()
{
    int n = 300;
        for (int vez=0;vez<2;vez++){
            for (int _=0;_<100;_++){
                delayMicroseconds(n);
                digitalWrite(speakerPin, HIGH);
                delayMicroseconds(n);
                digitalWrite(speakerPin, LOW);
            }
        delay(100);
        }
    n = 450;
        for (int _=0;_<110;_++){
            delayMicroseconds(n);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(n);
            digitalWrite(speakerPin, LOW);
        }
    }

void startupSound()
{//RE MI DO DO. SOL
    int note = (1/587.33)*500000;
        for (int _=0;_<100000/note;_++){
            delayMicroseconds(note);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(note);
            digitalWrite(speakerPin, LOW);
        }
    note = (1/659.26)*500000;
        for (int _=0;_<100000/note;_++){
            delayMicroseconds(note);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(note);
            digitalWrite(speakerPin, LOW);
        }
    note = (1/523.25)*500000;
        for (int _=0;_<100000/note;_++){
            delayMicroseconds(note);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(note);
            digitalWrite(speakerPin, LOW);
        }
    
    note = (1/261.63)*500000;
        for (int _=0;_<100000/note;_++){
            delayMicroseconds(note);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(note);
            digitalWrite(speakerPin, LOW);
        }
     
    note = (1/392.00)*500000;
        for (int _=0;_<200000/note;_++){
            delayMicroseconds(note);
            digitalWrite(speakerPin, HIGH);
            delayMicroseconds(note);
            digitalWrite(speakerPin, LOW);
        }
    }

I understand why you would want to use a cheap readily available keypad like what you described, but adapting the PS/2 connector to a couple input pins is just the beginning. I'd be surprised if implementation of the NumLk didn't take some cooperation from the Arduino. The behaviour you are seeing may well be it's way of saying "yes I'm ON, I'll light my LED while I initialize."
Take a look at some of the PS2 keyboard/pad code in the Playground if you haven't already.

Don't expect the same thing to happen on the Arduino as with Windows. There's a ton of code behind the plug and play behavior you describe when plugging your keypad into windows.

Since you are using pins 2 and 3, which also happen to have interrupts available on them you could write an interrupt driven data read function that would let the Arduino loop and do something besides just sit and wait for the clock pin to change state.

In important note: most programmers use indentation to make their code more readable. It is very hard to visually follow the program flow in the code that you posted.

Did that PS/2 adapter come with the keypad?

Not everything USB can be made to work with PS/2: the gadget has to be specifically designed to do that.

Ran

The ps/2 adapter was something I had laying around.

I tried to copy exactly what these guys did. Please watch their video to get a better understanding. http://hacknmod.com/hack/arduino-keypad-security-system/

Basically, the project looked easy enough, and it really is, except for this dang keypad. I know they got it to work somehow, I just can't figure out how.

If you notice, they just gave a link to ebay, for cheap keypads. Maybe I need a cheaper one?

I know I could buy a keypad off sparkfun, but I would like to see if I could get this one to work!!

I might try and just use a rotary dialer off a phone if I can't get this to work...?

Thanks for the help.

maybe you can open it up and get the actual 'keypad' stuff before it goes to a chip to translate it to usb. So you would have the normal keypad, but rerouted to the arduio bypassing the chips.

The LIFE HACKS code is definitely expecting a PS2 keyboard interface and not USB. The USB interface on your keypad will be adding all sorts of USB overhead stuff to the protocol which I don't think your PS2 adapter will sort out in a way that the code will be happy with. Have you got a full PS2 keyboard that you can try it out with?

Thanks for the reply! I have actually tried an old Dell PS2 keyboard and the same thing seems to happen. When power is provided to the arduino, the keyboard numlock/caps lock/scroll lock, turn on for an instant then turn off.
I measured 5 volts getting to the keyboard, but the LED's won't stay on, even when I press the keys.
I'm wondering if I need to do something with the PS2 keyboard library?Arduino Playground - H
I'm quite knew at programing and electronics, so please feel free to give me any advice.
Thanks!

The lights come on for a few seconds because the keyboard does a reset when power is applied and its a way of checking the lights work. After that they won't come on again as neither the LIFE HACKS code nor the PS2Keyboard library sends commands to turn the lights on - so pressing shift-lock for example won't put the shift-lock light on.

For the LIFE HACKS code you should NOT have the PS2Library included - they both drive the PS2 interface but in different ways. The LIFE HACKS code uses Arduino pins 2 & 3 (and polls the CLK line), the PS2Keyboard code uses pins 3 & 4 (and uses interrupts on the CLK line).

If you have the keyboard correctly connected to pins 2 & 3 then for the LIFE HACKS code and don't have PS2Keyboard library included then I would expect it to work unless there is a problem with the LIFE HACKS code - and I wouldn't know about that.

One thing to try is to make sure the keyboard is plugged in BEFORE applying power to Arduino and then only pressing the relevent number pad keys. Keyboard code is very sensitive to getting out of sync and a clean power-on is essential.

If you want to read up a bit about PS2 keyboards and how they work, look at this page: http://www.beyondlogic.org/keyboard/keybrd.htm It will explain why the codes are what they are and what the LIFE HACKS code is trying to do when driving PS2 CLK and DATA.

If you do want to try the PS2Keyboard code then I have written a new version here: Arduino Playground - PS2KeyboardExt2 and this version does control the shift-lock light when you press the shift lock key. To use this code however you will need to re-wire the kbd to pins 3 & 4 and re-write the code to use the PS2Keyboard library functions of keyboard.available() and keyboard.read()

To use this code however you will need to re-wire the kbd to pins 3 & 4 and re-write the code to use the PS2Keyboard library functions of keyboard.available() and keyboard.read()

@ mhead10, I suggest you do try to use the PS2KeyboardExt2 code that armless linked to above, but only try to run the example from that page.

So re-wire the keyboard CLK and DATA pins from the keyboard to Arduino pins 3 and 4 respectively. Then download the PS2Keyboard.h and PS2Keyboard.cpp files from the bottom of Arduino Playground - PS2KeyboardExt2 and install them in the library folder of your Arduino software (exact location depends on what version of the Arduino IDE you have).

But don't try to re-write your code yet, just copy and paste the example sketch that armless provides at the link above and run that first. You should see letters on the serial monitor when you type on the keyboard that's attached to your Arduino. Don't forget to set the serial monitor to 9600 baud, to match the baud rate in that example sketch.

Just trying to keep the number of changes to a minimum here ...