A little venture with electronics – Mousing

As per wiring up the LCD, the PS2 mouse should again have been a simple process. Again the libraries are provided and there are plenty of examples. I ripped up an old tablet (no drivers for that since Win95) to get an inline female PS2 socket which was wired into the prototyping board.

I also found a particularly promising example from the Practical Arduino site. Along with a wikipedia article that clarified some of the pinouts for the socket and that I needed to connect the mouse to a couple of the Arduino’s digital ports.

However, the example code provided would not compile. The error reported with the PS2 mouse library was a reference to a missing file, wconstants.h. A quick google showed me that this header file was deprecated for my Arduino version and replaced by Arduino.h. There are some other changes and “Make Magazine” have a good article on the differences from earlier arduino versions.
I made the change and compiled and uploaded the sketch. It worked fine except if I moved the mouse more than a couple of milimeters when it crashed and rebooted the arduino. The data types for X and Y co-ordinated were integers so I guessed it was an overflow error.

Looking back at the Arduino Playground, I was lead to the PS2 mouse library at the Potter Project. Again, I needed to change #include “WProgram.h” to #include “Arduino.h” to get things to compile. This library seemed more promising in that it had long int for the co-ordinates so I put together the following test programme which works quite nicely.

  • //Mouse test
  • #include <Wire.h>
  • #include “ST7036.h”
  • #include “PS2.h”
  • //Pin definitions
  • #define MOUSE_DATA 5
  • #define MOUSE_CLOCK 6
  • PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA);
  • ST7036 lcd = ST7036 ( 2, 16, 0x7C );
  • void setup()
  • {
  •   lcd.init();
  •   lcd.on();
  •   lcd.setCursor(0, 0);
  •   mouse.init();
  •   lcd.print(“Hello mouse!”);
  •   delay(2000);
  •   lcd.clear();
  • }
  • void loop()
  • {
  •   MouseInfo data;
  •   mouse.getData(&data);
  •   lcd.setCursor(0, 0);
  •   lcd.clear();
  •   lcd.print(data.cX); // X Movement Data
  •   lcd.print(“,”);
  •   lcd.print(data.cY); // Y Movement Data
  •   lcd.print(” – “);
  •   lcd.print(data.cScroll); // Scroll
  •   delay(10);
  • }

Here’s a short video of it in action.

Having put this together I found Gecho’s wheel truing project where he mentions that there are some settings for changing the precision of the mouse sound worth investigating.

My next step is to prototype some of the mechanics and ensure that the mouse is going to read the rotary position as desired.

One thought on “A little venture with electronics – Mousing

  1. Islam Mahmoud says:

    Thanks a lot
    gona try this
    I think with a little hacks it could work well with my mapping and navigation robot

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available