Pages: [1]   Go Down
Author Topic: Ps2 mouse not working  (Read 464 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an old PS2 mouse. I cut the cable, and connected the GND wire to one of the Leonardo's GND pins, the VCC wire to the 5V pin, the CLK wire to pin 11, and the DATA wire to pin 12. I then uploaded this sketch.

Code:
#include <ps2.h>

/*
 * an arduino sketch to interface with a ps/2 mouse.
 * Also uses serial protocol to talk back to the host
 * and report what it finds.
 */

/*
 * Pin 5 is the mouse data pin, pin 6 is the clock pin
 * Feel free to use whatever pins are convenient.
 *Modified to be 12, 13 instead of 6,5
 */
PS2 mouse(12, 13);

/*
 * initialize the mouse. Reset it, and place it into remote
 * mode, so we can get the encoder data on demand.
 */
void mouse_init()
{
  mouse.write(0xff);  // reset
  mouse.read();  // ack byte
  mouse.read();  // blank */
  mouse.read();  // blank */
  mouse.write(0xf0);  // remote mode
  mouse.read();  // ack
  delayMicroseconds(100);
}

void setup()
{
  Serial.begin(9600);
  mouse_init();
}

/*
 * get a reading from the mouse and report it back to the
 * host via the serial line.
 */
void loop()
{
  char mstat;
  char mx;
  char my;

  /* get a reading from the mouse */
  mouse.write(0xeb);  // give me data!
  mouse.read();      // ignore ack
  mstat = mouse.read();
  mx = mouse.read();
  my = mouse.read();

  /* send the data back up */
  Serial.print(mstat, BIN);
  Serial.print("\tX=");
  Serial.print(mx, DEC);
  Serial.print("\tY=");
  Serial.print(my, DEC);
  Serial.println();
//  delay(20);  /* twiddle */
}

When I open the serial monitor and move the mouse, nothing shows up on the serial monitor. Can anybody help me troubleshoot?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I cut the cable, and connected the GND wire to one of the Leonardo's GND pins, the VCC wire to the 5V pin, the CLK wire to pin 11, and the DATA wire to pin 12. I then uploaded this sketch.
which says that you are using pins 12 and 13, not 11 and 12. Why is that?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whoops. I meant to say 12 and 13 for everything. Typo on my part. Sorry.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can anybody help me troubleshoot?
Add a Serial.print() to setup() to see when it gets called. Before and after mouse_init() would be best. Maybe mouse_init() never returns.
Logged

Pages: [1]   Go Up
Jump to: