having difficulties with computer's ps/2

i took a ps/2 cable and in one end i plugged it in the computer's ps/2 outlet (mouse, not keyboard) and the other end is cut and the clock and the data wires are connected to the arduino's pin 13 and pin 12.

I'm trying to read data from the computer (i could do it before but now for some reason it doesn't work)

this is the code for the reading:

char mouse_read(void)
  char data = 0x00;
  int i;
  char bit = 0x01;

  //  Serial.print("reading byte from mouse\n");
  /* start the clock */
  while (digitalRead(MCLK) == HIGH);
  delayMicroseconds(5);  /* not sure why */
  while (digitalRead(MCLK) == LOW); /* eat start bit */
  //this is where the program is stuck

the program waits for the computer to set the MCLK pin HIGH, but it doesnt do it, and therefore it is stuck. anyone could help me with that?

Clock and data are open collector, are you using pull-ups?

i don't think i quite understood. what is open collector? and pull-ups? (perhaps you are talking about pull up resistor, but im not using any resistors here, just connecting the wires directly to the arduino)

here is a schematic i was working on after reading about open collector output, but still it doesnt help.

that circuit would just short out your data lines and keep a constant logical zero. i think you just need the resistors to 5 volts and get rid of that connection to ground.

ok i took out the wires that connect to the ground.

think you just need the resistors to 5 volts

you mean the 5 volts of the ps/2 wire that comes out of the computer instead of te 5 volts of the arduino?

id go with the 5 volts of the arduino. also, remember to connect the ground of the computer to the ground of the arduino

A couple of things to note. First if you hacked code from the PS2 library from the playground, then you should not need pull-ups. gohi/golo will use the internal pullups on the arduino io pins. No external parts needed.

Not sure exactly what the problem is you are having. However, the PS2 library in the playground was for a device to communicate with the arduino (ie plug the mouse into the arduino). The protocol from the host side is different. For example, it is the device that generates the clock, even when it is the host that transmits.
There should be a link to a page about the PS2 protocol, if not google for it. It will tell you lots of details about how the host/device talk to each other.


I kept my answer brief because you "had this working before."

GND of the PS2 port should be connected to your Arduino's ground. Grounds always get connected together, they are the reference.

Then you need a resistor (at least 10K) connected from CLK to 5V and your Arduino. Same for Data. If you have your PS2 and Arduino GND connected together, it doesn't matter which 5V source you use.

More information on the PS2 protocol and port: http://www.computer-engineering.org/ps2protocol/

to ckiick and CMiYC, i have already read about the ps/2 protocol (from host to device and from device from host) including the one from computer-engineering.org and it says the host pulls the clock low and then releases it high, and thats exactly what i'm doing, i'm waiting for the host to pull it low and then release it but apparently it does pull it low but does not release it. here is my new schematic:

really frustrating :frowning:

anyone has any ideas?

Just out of interest, how are you writing to the ps/2 port?

i still haven't written to the port, just reading. but i guess ill have to send data using the MDATA pin and at the same time switch the MCLK pin on and off, because the device is the one who generates the clock pulses.

I was confused by the

I'm trying to read data from the computer (i could do it before but now for some reason it doesn't work)


well, if you connect a ps/2 cable to the ps/2 outlet of the computer (no matter if there is a mouse on the other end or just cut wires) the computer sends data over the ps/2 outlet because it is trying to find out the co-ordinates (not exactly) of the mouse. and i'm trying to read the data the computer sends.

ah! I see, I thought the computer just passively listened for clock & data pulses but I have just had a read about it and I see it is a bit more complicated than that.

I have never considered using the ps/2 ports before.