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.
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 :
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
Indeed, as the error message tells, PS2Mouse is in my opinion never introduced as a type, if not in Arduino.h, which I doubt.
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 */
}
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.