Difference between revisions of "Interfacing with a mouse"

From Mech
Jump to navigationJump to search
Line 14: Line 14:


== PS/2 Interface ==
== PS/2 Interface ==

== Circuit ==
The relevant part of the breadboard adapter data sheet can be seen below.

(image)

The mouse, as can be seen in the breadboard adapter schematic, now has four conduits indirectly attached to it. In order to operate, the mouse needs power, so the 5v and ground are used to power the mouse. The other two pins are actually used as both inputs and outputs. The mouse needs to first receive a signal before it can output a signal. The mouse also generates its own clock signal. More about this can be found in the PS2 protocol section.

Instead of using the resistors seen in the breadboard adapter schematic, it is actually preferable to use this schematic because the PIC also needs to send data to the mouse.

(image)

The clock and data lines connect directly to the clock and data lines of the breadboard adapter. Note: there should be a resistor between the microcontroller outputs C/D and the base of the transistors. We also found that the buffers were unnecessary.

Basically, the microcontroller needs to be able to have two way communication with the mouse. So if the PIC wants to send data to the mouse, data will equal output D inverted, and Clock will equal output C inverted. Once the mouse starts sending data (and the outputs of C/D are set low), the clock and data lines are normally held at 5v, but are then set low if the mouse sends logic low. More information about this operation can be found here: http://www.computer-engineering.org/ps2protocol/

A great way to trouble shoot, debug, and see the final result is to use an LCD screen to display the information that the mouse is sending to the PIC. More information about LDCs and the flex code we used can be found here: http://hades.mech.northwestern.edu/wiki/index.php/C_Example:_Parallel_Interfacing_with_LCDs

Revision as of 01:29, 12 February 2009

Original Assignment

Interface the PIC with a PS/2 optical mouse and display (x,y) position data on either an LCD screen (see, e.g., C Example: Serial LCD or C Example: Parallel Interfacing with LCDs) or the PC (e.g., in Matlab or hyperterminal).

Overview

Ione Lynx-M9 mouse

The goal of the project is to interface the PIC184520 with a PS/2 mouse - specifically, an ione Lynx-M9 Wheel Optical mouse with a USB to PS/2 adapter. The mouse's XY coordinates will be displayed on an LCD screen and will be updated when the mouse moves.

The PS/2 connector is traditionally used to connect mice and keyboards to computer systems. The connector uses six pins: clock, data, 5V, GND and two that are not connected. The PS/2 connector is fully documented here: PS/2 connector. We used a Parallax PS/2 to Breadboard Adapter to connect the optical mouse to the PIC18. Documentation and ordering information for the adapter can be found here: Breadboard Adapter.

PS/2 to breadboard adapter

On this page you will find the steps to use a PS/2 mouse's output to meet your needs. The code, circuit diagram, and notes about the interface are included. This is currently a work in progress, but should be a good foundation for those looking to build on it and be able to use a PS/2 mouse in their own projects.

PS/2 Interface

Circuit

The relevant part of the breadboard adapter data sheet can be seen below.

(image)

The mouse, as can be seen in the breadboard adapter schematic, now has four conduits indirectly attached to it. In order to operate, the mouse needs power, so the 5v and ground are used to power the mouse. The other two pins are actually used as both inputs and outputs. The mouse needs to first receive a signal before it can output a signal. The mouse also generates its own clock signal. More about this can be found in the PS2 protocol section.

Instead of using the resistors seen in the breadboard adapter schematic, it is actually preferable to use this schematic because the PIC also needs to send data to the mouse.

(image)

The clock and data lines connect directly to the clock and data lines of the breadboard adapter. Note: there should be a resistor between the microcontroller outputs C/D and the base of the transistors. We also found that the buffers were unnecessary.

Basically, the microcontroller needs to be able to have two way communication with the mouse. So if the PIC wants to send data to the mouse, data will equal output D inverted, and Clock will equal output C inverted. Once the mouse starts sending data (and the outputs of C/D are set low), the clock and data lines are normally held at 5v, but are then set low if the mouse sends logic low. More information about this operation can be found here: http://www.computer-engineering.org/ps2protocol/

A great way to trouble shoot, debug, and see the final result is to use an LCD screen to display the information that the mouse is sending to the PIC. More information about LDCs and the flex code we used can be found here: http://hades.mech.northwestern.edu/wiki/index.php/C_Example:_Parallel_Interfacing_with_LCDs