Hi,
I am having problems using a PS2 mouse on my Arduino Mega and wondered if anyone else has experienced this as I am out of ideas how to resolve it:
I am building a robot which uses a PS2 mouse to tell how far it has moved along the ground and how far it has turned.
This is working reasonably well apart from the mouse seems to just randomly stop responding resulting in the robot going out of control. I have tried different power supplies, different pins on the Arduino, even a different PS2 library but every time I think I have resolved the problem it comes back
The robot can work for some considerable time without problem, then suddenly this problem seems to start happening
It is annoying as apart from this I think I have resolved all my problems and the robot is ready to start using
see AlanEsq.com is for sale | HugeDomains for more info on the project
The script can be seen here: AlanEsq.com is for sale | HugeDomains
but I am not doing anything clever regarding the mouse, just keeping a track of how far along the ground it has travelled, so I don't think it is a software problem on my side (although I could be doing something obviously wrong?)
the relevant bit of code is below:
The PS2 library I am using is this one: http://thepotterproject.net/TPPNews/?page_id=180
but I had the same problem with the original version
while ( qtemp == 0 ) { // keep checking mouse reading
mouse.getData(&mouseInfo); // get a reading from the mouse
mxpos = mxpos + mouseInfo.x; // update current mouse data
mypos = mypos + mouseInfo.y; // update current mouse data
// check if target reached yet
if ( ndirect == 1 ) { // forward
// moving forward so y will be increasing
if ( mypos > num ) qtemp = 1;
}
else if ( ndirect == 2 ) { // reverse
// moving backwards so y will be decreasing
if ( abs(mypos) > num ) qtemp = 1;
}
else if ( ndirect == 3 ) { // right
// moving right so x will be decreasing
if ( abs(mxpos) > num ) qtemp = 1;
}
else if ( ndirect == 4 ) { // left
// moving left so x will be increasing
if ( mxpos > num ) qtemp = 1;
}
//lcdshow ( "" , String(mxpos) + " , " + String(mypos) );
} // end of while