Go Down

Topic: PS/2 keyboard (Read 3547 times) previous topic - next topic

baum

Hi all-
I have a PS/2 keyboard, and it won't work. It works when plugged into the computer, but when I plug it into the arduino, nothing happens. I downloaded the PS/2 Keyboard library, and still nothing. I plugged my multimeter into the keyboard, and there isn't even a signal from the data pin. I tested 5V and Ground, and there working. I double checked my wiring, too. Any ideas?

James C4S

There are two libraries PS2Keyboard and PS2KeyboardEXT.  Which one are you using?  If you are using PS2Keyboard, which version of that are you using.  There are a couple of different download options in the Playground.

Even though the PS2Keyboard playground page has a schematic, it might be helpful to state how you are connecting to the Arduino (and post the code you are using.)
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

baum

Few things:
I got the libraries from the Arduino playground (PS2 ext), and my code is the example bundled in the library:
Code: [Select]
/*  PS2Keyboard library example
 
 PS2Keyboard now requries both pins specified for begin()

 keyboard.begin(data_pin, irq_pin);
 
 Valid irq pins:
    Arduino:      2, 3
    Arduino Mega: 2, 3, 18, 19, 20, 21
    Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
    Teensy 2.0:   5, 6, 7, 8
    Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
    Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
    Sanguino:     2, 10, 11
 
 for more information you can read the original wiki in arduino.cc
 at http://www.arduino.cc/playground/Main/PS2Keyboard
 or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
 
 Like the Original library and example this is under LGPL license.
 
 Modified by Cuninganreset@gmail.com on 2010-03-22
 Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
 
#include <PS2Keyboard.h>

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

PS2Keyboard keyboard;

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

void loop() {
 if (keyboard.available()) {
   
   // 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);
   }
 }
}


As for the multimeter:
I realize that I couldn't see the actual pulses, but there is NOTHING coming up on it... just  0 milliAmps, 0 volts.

Connection:

I striped the wire, and used the wikipedia article
http://en.wikipedia.org/wiki/Ps2_connector
for the wires.
Yellow to Ground
Red to +5V
Green(CLK) to pin 5
White(DATA) to pin 8

And nothing shows up in the Serial Monitor.
According to my volt meter, the 5V is being delivered, but te CLK and DATA are dead.

P.S. I have a Duemilanove

baum

Sorry about that. I did install PS/2 Keyboard from the playground, and then installed PS2 ext. Before all this, I had PS/2 mouse http://www.arduino.cc/playground/ComponentLib/Ps2mouse
but that didn't work. I know it says mouse, but it was supposed to work for keyboards, too, as the devices work on the same protocol.

baum

Well, I jus tested it, and with the multimeter positive pole on the red wire, all three other wires return 5Vs.... so your right. Wikipedia could have been wrong.
I have a red, white, green, and yellow wire, plus an outside mesh thing which returns nothing. What would you suggest?

James C4S

Quote
I striped the wire, and used the wikipedia article
http://en.wikipedia.org/wiki/Ps2_connector
Since you cut the connector anyway, have you verified with your meter's continuity tester to verify the pinout / colors?  I wouldn't rely on the wikipedia article.

Quote
And nothing shows up in the Serial Monitor.
Nothing?  Not even the "Keyboard Test" message you have in your setup()?  You might add a serial.println() after the if "(keyboard.available())."  Then you'll at least know your if-else-cases are being checked.

Quote
According to my volt meter, the 5V is being delivered, but te CLK and DATA are dead.
Keep in mind that CLK and DATA are both open-collector outputs from the keyboard.  So without a pull-up resistor, you probably won't see them change.  (From what I can tell, the libraries enable the internal pull-ups, so you don't need to worry about this.)

Start by verifying you have the pin-out of your connector correct.  Like I said, don't rely on the Wikipedia's color code for the wires.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Osgeld

#6
Sep 19, 2010, 10:31 pm Last Edit: Sep 19, 2010, 10:31 pm by Osgeld Reason: 1
heh last ps/2 keyboard I tore apart the wire colors were random AND the silkscreen was wrong

wire colors are a horrid way of figuring out connections anyway, they mean nothing and no one has ever stuck to whatever people seem to think they should be
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

baum

Question 1: I stripped the main, thick, black, cable ( that comes out of the keyboard itself), to find five more inside. 4 were colored (as I have mentioned), one was uninsulated. Wikipedia claimed that red was Vs, yellow was GND, green was clk, white was data. There was no mention of the uninsulated one. I tested these wires, using wikipedia's chart for reference. None seemed to be working.
2. Before I stripped the main cable, I plugged it in to a computer, and it worked. Then I stripped it.
3. I didn't confirm, I only reference the chart on wikipedia's PS/2 connector article (which I have posted the link somewhere)
4. At the beginning of the program, the Arduino outputs "Keyboard Test" to the Serial monitor. This came up, just nothing else did.

Just a side note....
The PS/2 plug has 6 pins--- but only 5 wires. The four I have told you are pins 1, 3, 4, 6, but no one seems to know what pins 2 and 6 do. So since I have 5 wires, one of them could be the wire for pin 2 or 6.
I don't know.

The problem can't be software-- this library has worked for others. So it must be hardware/wiring.

Also-- the problem is not only trying to get the data to the arduino-- it seems as though the keyboard isn't getting power. The caps, num, and scroll lock lights won't light up when pressed as they did when plugged into a computer.

baum

I looked at the plug, and I tried the following connections:
Yellow is CLK
Green is DATA
Red and White are power
I'm not sure what the uninsulated is, nothing happened when I connected it to ground or 5Vs.

baum

How do you suggest I figure out the wires?

mowcius

Quote
Well, I jus tested it, and with the multimeter positive pole on the red wire, all three other wires return 5Vs.... so your right. Wikipedia could have been wrong.
I have a red, white, green, and yellow wire, plus an outside mesh thing which returns nothing. What would you suggest?

Are you sure you looked at the right pinout, the plug pinout rather than the mirrored socket pinout.

When you connect 5V and Gnd you should get the LEDs on the keyboard flash. This normally occurs and is a nice way to know that they are the right way round.

Mowcius

baum

I no linger have the plug head (alas...). I have 5 cords
Red
White
Uninsulated (Protective GND...?)
Green
Yellow

Common sense says that the red and white should be power.. but those don't work. I don't want to randomly try every combination for fear of shorting out my arduino, so has anyone ever tried this project, know how to find the cords, and/or now what colors it should be? ( I have an old Dell keyboard, if that helps)

P.S. I'm sorry if I'm not being clear/helpful/whatever-- I'm only trying.


Osgeld

#12
Sep 21, 2010, 01:22 am Last Edit: Sep 21, 2010, 01:24 am by Osgeld Reason: 1
common since goes out the window when your making 10,000 keyboards an hour for a nickel each in china

colors mean nothing until you document them yourself, you should be able to open the keyboard and figure out which one is ground (cause it will be the common connection tween everything) , after that your just going to have to poke around until you find power, easy take 5 volts 3 wires until the keyboard lights blink on and off like they do when turning on your computer

after that its a 50/50 shot which one is clock and data
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Osgeld

Quote
If you are lucky, there will be names on the PC board that identify where the wires connect.


and as I already mentioned I have had 1 that they couldnt even bother to get the silkscreen right, so its a gamble
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

westfw

The pinout at the connector is standardized; the meat of what people are telling you to look at the cut-off end of the cable that has the connector, and figure out which color goes to which pin.  THAT will tell you which color is which, regardless of whether the cable is "standard colored" or not.  If it wasn't right at the pins, it wouldn't have worked on a PC either.

If you carefully take apart the keyboard so that you can see the circuit board inside, it is usually pretty easy to tell which pins are +5/GND.  There will usually be  a nice polarized cap connected between the PCB traces for GND and +5.  Here's a picture of a keyboard's PCB (this happens to be a USB keyboard, but a PS/2 will look very similar.)  The black tubular bit in the middle is the cap I'm talking about...


Go Up