NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Sensors, Actuators, and Robotics » Talking to your mouse
January 02, 2012 by pcbolt |
After checking out the Nerdkit video for PS2 Keyboards, I thought it would be pretty easy to extend that knowledge by interfacing with a PS2 Mouse. Well, after a little bit of cutting and stripping I wired an old mouse to the ATmega168 and figured I'd get mouse messages scrolling across my LCD in no time. No joy. Turns out message reporting is disabled at mouse power up so you have to talk to it first (send enable code F4) before you can listen. I found a few websites that completely steered me in the wrong direction. One said you just set up a clock signal on one line and data on the other and you're talking. That didn't work. Fortunately the website referenced in the Nerdkit project page (Chapweske) had a link to the guts of the PS2 protocol. Turns out the mouse always generates the clock pulse and reads your data on the high portion of the cycle. The Chapweske page gives a step by step guide for doing this (12 steps in all...just like AA). The one thing that is different is the way he turns pins on and off. Since the protocol is using "Clock/Data high" as its idle state, Chapweske suggests making the clock/data pin low by making it an output pin and writing a '0' to it. Makes sense. For making it high he suggests just turning the pin to an input. OK, I tried it but got some odd forms on the oscilloscope trace, not only that but the mouse didn't like it. So I went back to keeping the pins as outputs and writing 1 or 0 as needed. This worked better but now the 12 steps needed modifying for the stop bit and the ACK bit. Lots of hair-pulling/trial-and-error here but finally success at last! This actually provides a pretty good input controller, since you get 2D movement, and a combo of 8 states through 3 buttons. Might make for a more compact servo-squirter control. All in all, a fun project. Who knew you couldn't believe everything you read on the internet? |
---|---|
January 02, 2012 by missle3944 |
Pcbolt, Sounds pretty cool. I'd never thought of interfacing a mouse to the nerdkit. Does the mouse have a microcontroller or is it just discrete logic? I think we would all enjoy a video of your project :) -Dan |
January 02, 2012 by Drwish |
I agree with Dan. Sounds interesting what you're doing over there! A video would be cool =P |
January 02, 2012 by pcbolt |
Dan - The mouse does have a tiny MCU inside. It actually does most of the work in this project. It provides the clocking, interprets mouse movement through some optical sensors and wheels, and sends info out the data line. You can also send codes to it for resolution, sensitivity etc. It might take me a while to put up a video, but it might not take to long to post a diagram and some pics (maybe some code too!). Except for talking to the mouse, this project is almost identical to the Nerdkit PS2 Keyboard video. And yes finally getting it to work was pretty cool. |
January 04, 2012 by pcbolt |
Drwish/Dan - No video, but I thought you might like some pics... Simple wiring - LCD display showing right mouse button down Clock signal - Data signal - |
February 18, 2012 by Jalex |
Hi Dan
That looks pretty close to what I want to do. I would like to look at your code if you still have it.
I am only interested in reading one wheel as I want to see if I can covert the numbers to 0/360 to show position of a slowly rotating object. I could also use the mouse clicks for sending other data as well.
So far most of my work has been in parallel data ttl stuff.
I am a programmer too though so have written a lot for the ATmega168 with good success. |
February 18, 2012 by pcbolt |
Jim - I'll try to get some code up very soon. By default, the mouse will not report scroll wheel data, you have to send it a coded sequence to enable the scroll data. I was able to get it to work though and in the process was able to control the resolution and reporting rates. The scroll data reports just a movement number from +127 to -128 and I don't think it's related to angular movement (I could be wrong though). I found one wheel "click" reports 1 or 2 (not consistently) and also a + or - to indicate direction. The PS/2 protocol is more closely related to the SPI protocol but the master/slave relationship is blurred somewhat. If you get through the NK keyboard tutorial, be sure to check out the links posted to the Chapweske site. It's actually pretty interesting. If you're really brave, you can tear into the mouse PCB and see the wheels triggering an optical sensor which is translated to movement by the mouse MCU. |
February 18, 2012 by Rick_S |
You could look at rotary gray code encoders and if you are just wanting to monitor position of a single rotary axis. You wouldn't have to mess with the mouse interaction then. Rick |
February 18, 2012 by pcbolt |
Jim - Check out the Library->Projects for the code used in my mouse project. |
Please log in to post a reply.
Did you know that an electroluminescent backlight for an LCD panel requires hundreds of volts AC to run? Learn more...
|