4

I want to read data from a mouse with the help of Arduino. I want to calculate relative motion between two objects. My questions are

1) Is it possible?

2) How is mouse interfaced with Arduino?

  • 2
    Are you asking about a USB mouse, a PS/2 mouse or a serial mouse? – John Honniball Nov 20 '14 at 14:30
  • 2
    If you can get hold of a PS/2 mouse or a serial mouse it would be much easier. – pjc50 Nov 20 '14 at 14:50
  • The mouse interface used by the Amiga looks like it is as simple as a mouse interface could possibly become. But an Amiga mouse may not be that easy to come by, so using PS/2 may be a better idea for that reason. – kasperd Nov 20 '14 at 17:14

2 Answers2

5

For a USB mouse, the data transfer is very complicated. First of all the host (computer) must discover the presence of the mouse (it may have been hot-plugged). Then, the host must find a device driver, and in the case of a mouse, this will be a HID (Human Interface Device) generic driver. Finally, the host will open USB endpoints and actually transfer mouse motion data in the form of X,Y co-ordinates and button up/down bits.

This is something that's hard to do with an Arduino. You'd need to get a USB host interface shield, and then write a sketch (program) to drive it. If you really want to interface a mouse with an Arduino, you may find it easier to get a PS/2 mouse (an obsolete PC-compatible standard) or a serial mouse (another obsolete standard, seen on all types of computers), or a quadrature mouse (very raw interface going directly to button switches and motion sensors).

John Honniball
  • 2,799
  • 11
  • 10
  • While obsolete, devices with old PS/2 and serial interfaces are still manufactured and it is possible to buy them. There are a lot of old systems out there in various industries (e.g. medical, retail) that do not get upgraded for a variety of reasons (cost, if it ain't broke don't fix it) and they need replacement parts. –  Nov 20 '14 at 18:45
4

1). Is it possible?

Yes, of course. If your Arduino has a USB interface (more accurately USB device interface or OTG), it'll be easier.

2). The former PS/2 mouse and the modern USB mouse, or Bluetooth wireless mouse (also use USB interface). The former two are easier to implement on MCU.

The PS/2 is easy to implement, but it's a bit outdated. So, may you want to try USB. Then you need known USB protocol, particularly HID class protocol.


Update:

As you choose to use PS/2, then you can go here: http://www.computer-engineering.org/ps2protocol/, it's really easy, you can implement it using only two pins, a clock and a data pin.

diverger
  • 5,828
  • 5
  • 43
  • 79