PS2 Library with Arduino 1.0 - Example does not run

Hi, I am trying to connect a PS2 mouse to my Arduino Duemilanova with the ps2 library under Arduino 1.0.

When I run the sketch PS2Mouse that comes with the library it gives following error:

ps2_mouse.cpp:17:1: error: ‘PS2Mouse’ does not name a type
ps2_mouse.cpp: In function ‘void setup()’:
ps2_mouse.cpp:22:3: error: ‘mouse’ was not declared in this scope
ps2_mouse.cpp: In function ‘void loop()’:
ps2_mouse.cpp:31:3: error: ‘MouseInfo’ was not declared in this scope
ps2_mouse.cpp:31:13: error: expected ‘;’ before ‘mouseInfo’
ps2_mouse.cpp:32:3: error: ‘mouse’ was not declared in this scope
ps2_mouse.cpp:32:18: error: ‘mouseInfo’ was not declared in this scope

I used this library and this sketch before and it worked fine, but now it seems to refuse its service!
I did use an older version of arduino before, but even there it doesn´t work anymore.

does any one have an idea on this??

Simple fix, usually. WProgram.h must be changed to Arduino.h in the .h and .cpp files.

Thanks for the quick reply!

I already changed WProgram.h to Arduino.h in the .h file.
In the .cpp file is no WProgram.h!

So there must something else not working!

Where is the library located? Sketch folder or IDE folder?

using ubuntu it is in:

/usr/share/arduino/libraries/ps2

So I guess the IDE folder.

Try putting it in your sketch folder. Make a "libraries" folder and drop it in. Also make sure it is not double foldered.

Ok, I moved it to:
/home/couscous/sketchbook/libraries/ps2/ps2.h

But the error message stays identical!

I read through the file ps2_mouse.cpp :

  1. I don´t get how arduino can find it, it was in a subfolder, somewhere strange:
    /home/couscous/sketchbook/ps2_mouse/libraries/ps2/examples/ps2_mouse/applet/ps2_mouse.cpp

  2. Indeed, as the error message tells, PS2Mouse is in my opinion never introduced as a type, if not in Arduino.h, which I doubt.

ps2.cpp (3.05 KB)

ps2_mouse.cpp (1.47 KB)

In your library folder:
{
PS2 folder contents:
{
Example folder
PS2.h
PS2.cpp
Keywords.txt
}
}

If anything, reinstall it.

It works,

Reistalling alone wasn´t enough though, I had to delete the Arduino folder manually before reinstalling with Ububtu software center.

I keep my ps2 library with all the other libraries in the Arduino IDE folder in usr/share/arduino/libraries, that seems to work fine.

There is a subsequent problem though, I dont see anything on the serial monitor. The monitor works with other sketches. I tried other sketches and it worked. But maybe this is another topic for another day!

Thanks for the help so far.

the ps2mouse code:

#include <ps2.h>

/*
 * 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 */
}

Check the baud rate in the lower right corner of the serial monitor, make sure it is set to 9600.

Hi, I am trying to connect a PS2 mouse to my Arduino Due with the ps2 library under Arduino 1.0.

The Due needs 1.5.1+.

Oooh, sorry, its an Arduino Duelimanove, i didnt read the name untill the end! So I´m fine with 1.0?

I checked the boudrate, it was set to 9600 per default. I tried some other boudrates too, but not even the usual chatter appeared, nor did I see any LED flashing.