I'm trying to connect a Genius mouse to an Arduino using a PS2 mouse sketch, but it will not initialise the mouse

StackOverflow https://stackoverflow.com/questions/10583050

  •  08-06-2021
  •  | 
  •  

Question

I have been using the mouse sketch at the bottom of this message (written by someone else) to try to get the motion data out of a PS/2 mouse. I have checked the specification for this mouse which says that it is PS/2 compatible. However, when I run it it appears to stop at the first line of mouse_init where it says, "mouse.write(0xff); // reset". This is a call to a function in ps2.h. ps2.h has been around since 2008 and has been used in a number of projects, so I assume it is okay, but I was wondering if there might be some peculiar features of USB mice connecting as PS/2 mice that this library was never designed to cope with. Does anyone have any experience that might shed some light on this?

I have been able to determine that mouse.write is changing the state of my Genius mouse, but it gets stuck at the point where the Mouse is supposed to bring the clock state low so that the host can proceed to transmit data. Before mouse.write starts the clock state is low, but it gets pushed high by the host a few lines into mouse.write and stays there. The mouse never pulls it low again. Any thoughts on what the trouble might be would be greatly appreciated.

#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.
 */
PS2 mouse(6, 5);

/*
 * 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 */
}
Was it helpful?

Solution

Solved it. As it turns out the Genius mouse I brought is not backward compatible with PS/2 even though the specification says it is. They must have exchanged the sensor chip for one where the PS/2 capability was not present at some point. I now have another USB mouse which is doing the job I wanted perfectly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top