3

I'm toying with a PS/2 mouse module. I'd like to connect it to my computer somehow so I could observe the data it's broadcasting when I'm moving the mouse. I program in Python so I want a way to get access to that stream in Python. How can I do that? I own both a PC and a Raspberry Pi, so if it's easier on the Raspberry Pi, I can use that.

(I'm an electronics newbie so please explain things that may seem obvious to you.)

2
  • 1
    Did you try plugging it in? – Ignacio Vazquez-Abrams Jun 1 '14 at 23:39
  • @Ignacio I don't want to use it as a mouse on the computer, I want to get access to the data coming from the mouse using Python. – Ram Rachum Jun 2 '14 at 21:35
1

It is not exactly clear what you mean by a "PS/2 mouse module".

The PS/2 mouse outputs serial data at 5V TTL levels. It would be possible to connect to GPIO using a level converter.

You will be able to find many references on the web which describe the pins, but then if all you want to do is discover the protocol this is already well documented.

1

You can plug it into the USB port(s) of the Pi using a PS2 to USB converter - example.

To view the data sent from the mouse, install xev (i think it is part of the x11-utils package).

You can then run xev in a terminal (or xev -event mouse to get data only from the mouse) - here is a small example of the data you might get (from a USB touchpad, bit different):

EnterNotify event, serial 25, synthetic NO, window 0x2c00001,
    root 0xc5, subw 0x0, time 41235311, (174,139), root:(176,212),
    mode NotifyNormal, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

MotionNotify event, serial 25, synthetic NO, window 0x2c00001,
    root 0xc5, subw 0x0, time 41235321, (174,139), root:(176,212),
    state 0x0, is_hint 0, same_screen YES

MotionNotify event, serial 25, synthetic NO, window 0x2c00001,
    root 0xc5, subw 0x0, time 41235338, (164,123), root:(166,196),
    state 0x0, is_hint 0, same_screen YES

Note: xev needs to be run from a terminal on a graphical desktop so it can work, it doesn't seem to work from a TTY.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.