Go Down

Topic: interfacing with a USB mouse (Read 86633 times) previous topic - next topic

jfranchino

I have an optical mouse that I'd like to grab x-y movement data from.

I started with a PS/2 mouse and I got it working as described here:
http://www.arduino.cc/playground/ComponentLib/Ps2mouse

But my optical mouse is USB. I tried using a USB-PS/2 converter but the light on the mouse didn't even light up.

Help!

Thanks in advance if you have any tips!

Cheater

The short answer: No. ;)

The long answer: You could but it would take ages and its very complex.

I'm surprised a USB to PS/2 converter didnt work though.

mem

#2
Feb 21, 2008, 11:05 pm Last Edit: Feb 21, 2008, 11:07 pm by mem Reason: 1
I am not sure why Cheater has responded with a negative answer. There should be no problem with  a typical optical mouse using that library code. The mouse is actually responding to the same protocol as the PS2 mouse, its just the connector that is different. But when first connected it will be in low power mode and you wont see the LEDs light up until you send the initialize command and read some data.

So I am also surprised that the USB to PS2 converter didn't work (although I haven't connected mine that way).  I have tried a number of different USB optical mice through a USB socket  salvaged from a discarded USB hub wired into my Arduino and it works great. You may want to try using lower resistance pull-ups, I found 2.2k ohms works well. I'd be surprised if you can't get yours going.

Cheater

Quote
I am not sure why Cheater has responded with a negative answer.

Well I was more talking about interfacing with USB.

If the PS/2 converter didnt work then it either wont work or something needs a little tweak.

jfranchino

mem- Thanks for being encouraging!

re: resistors
I'm not using pull-up resistors anywhere. Should I be?

re: initialize
The program I'm using (from http://www.arduino.cc/playground/ComponentLib/Ps2mouse) does some init (just sending 0xff and 0xf0), but even with that the USB optical mouse doesn't light up or send any data. Is there some other init code I should send?


kg4wsv

Sorry, but Cheater is on track.  It doesn't matter if it's an optical mouse, keyboard, printer, scanner, or whatever, the Arduino is not capable of acting as a USB host controller.  If you're not seeing detailed explanations on why, that's probably because the subject has been hashed out before, more than once on this forum.

No one is being negative, just realistic.  The Arduino is a great tool, but it doesn't solve this problem.

If your USB mouse happens to have one of those PS/2 adapters with it, you can probably get it to work with the PS/2 interface.

-j


mem

#6
Feb 22, 2008, 11:30 pm Last Edit: Feb 22, 2008, 11:33 pm by mem Reason: 1
Quote
Sorry, but Cheater is on track.  It doesn't matter if it's an optical mouse, keyboard, printer, scanner, or whatever, the Arduino is not capable of acting as a USB host controller.  If you're not seeing detailed explanations on why, that's probably because the subject has been hashed out before, more than once on this forum.

No one is being negative, just realistic.  The Arduino is a great tool, but it doesn't solve this problem.

If your USB mouse happens to have one of those PS/2 adapters with it, you can probably get it to work with the PS/2 interface.

-j

You have jumped to the conclusion that all USB mice need to have a USB host controller and that is not the case. All three of the optical mice with USB connectors I have happend to try are working quite happily with my arduino. I expect they all did come with PS2 adapters although I use the USB plug directly.

I would not be surprised if there were mice around, particulalry the wireless ones,  that did not support the legacy PS2 protocol and they would need USB host support. But I can confidently say, based on connecting a bunch of optical wired mice to my arduino,  that there seem to be plenty around that do support the legacy protocol and don't need any change to the PS2 code posted in the playground.


mem

#7
Feb 22, 2008, 11:42 pm Last Edit: Feb 23, 2008, 09:13 am by mem Reason: 1
Quote

re: initialize
The program I'm using (from http://www.arduino.cc/playground/ComponentLib/Ps2mouse) does some init (just sending 0xff and 0xf0), but even with that the USB optical mouse doesn't light up or send any data. Is there some other init code I should send?

re: resistors I'm not using pull-up resistors anywhere. Should I be?


My Init code does the same as yours, but I also set the resolution (I doubt that is necessary but I needed the highest resolution available) and do a status get. I will try it tomorrow to find the minimum code to get out of sleep mode.

Edit: tested with just the init code and it is enough to get out of sleep mode.

Code: [Select]
boolean Mouse::Init()
// initialise the mouse, return true if mouse is available
{
 gohi(_ClockPin);
 gohi(_DataPin);

 if(! IsResponding())
     return false; // Mouse is not responding!  

 mouse_write(0xff);    /*send reset */
 mouse_read();  /* ack unsigned char */
 mouse_read();  /* blank */
 mouse_read();  /* blank */
 mouse_write(0xf0);  /* remote mode */
 mouse_read();  /* ack */
 delayMicroseconds(100);
 return true; // if here, tell caller that the mouse is available
}


My init code calls a function that checks to see if a mouse is connected (the published code will hang waiting for a response that will not occur if a mouse is not connected). I attach it below for the sake of completeness
Code: [Select]
boolean Mouse::IsResponding()
{
 /* Function will return true if a mouse is connected and is responding */
 gohi(_DataPin);
 gohi(_ClockPin);
 delayMicroseconds(300);
 golo(_ClockPin);
 delayMicroseconds(300);
 golo(_DataPin);
 delayMicroseconds(10);
 gohi(_ClockPin);
 for(uint8_t i = 0; i < 200; i++) {
     if(digitalRead(_ClockPin) == LOW){    /* wait for mouse to take control of clock); */
        gohi(_ClockPin);
        delay(50);  // wait for mouse to time out
        return true;   // The mouse has responded          
     }
     delay(1);
 }
 return false;  // mouse did not grab clock
}



Try 2k pull-up resistors on the clock and data lines, I found that at least one mouse needed them.

kg4wsv

Quote
You have jumped to the conclusion that all USB mice need to have a USB host controller and that is not the case.

No, I actually said if your USB mouse comes with a PS/2 adapter it will likely work as PS/2.  The controller looks for either USB or PS/2 signal levels and behave accordingly (much the same way an iPod nano jack will behave as an audio output or USB interface, depending on what signals it sees).

If it's a purely USB device, though, it's a different story.

-j


mem

#9
Feb 22, 2008, 11:49 pm Last Edit: Feb 23, 2008, 09:19 am by mem Reason: 1
Quote
Quote
You have jumped to the conclusion that all USB mice need to have a USB host controller and that is not the case.

No, I actually said if your USB mouse comes with a PS/2 adapter it will likely work as PS/2.  The controller looks for either USB or PS/2 signal levels and behave accordingly (much the same way an iPod nano jack will behave as an audio output or USB interface, depending on what signals it sees).

If it's a purely USB device, though, it's a different story.

-j

The point I was making was that all the corded Optical mice i have tried with USB connectors  are not purely USB devices and work very well with the arduino mouse library.

edit: Rereading the posts on this thread I think people looking for advice on interfacing USB  mice could come away thinking that it's problem that can't be easily solved with an Arduino. My conclusion is that if you use a USB mouse that is capable of working with a PS2 adapter in legacy mode then you can easily get this working with the Arduino using the published mouse library.

All of the old USB mice that I had lying around worked, including this one:
http://www.amazon.com/Microsoft-D58-00026-Intellimouse-Optical-Mouse/dp/tech-data/B00005TQ08/ref=de_a_smtd?ie=UTF8&qid=1203752856&sr=8-1

Mice that are USB only, including many modern wireless mice are not a good choice, but if you pick one of the many low cost or older mice that do support legacy PS2 mode then your Arduino is more than capable of interfacing with it.

Have fun!


follower

Ah, so what you're saying is that some mice with a USB connector can actually communicate with the PS/2 protocol over that connector not that it's possible to communicate with a USB mouse using the USB protocol. That wasn't entirely clear to me from earlier in the thread.

--Phil.

mem

#11
Feb 23, 2008, 03:27 pm Last Edit: Feb 23, 2008, 03:38 pm by mem Reason: 1
Yes Phil , I was saying that a great many low cost mice with USB connectors will probably work with the Arduino using the mouse legacy protocol support over the USB physical interface. Advanced interface (HID) features are not available, and HID only mice won't work, but the original poster wanted x-y co-ordinates and that is supported on the legacy protocol.

But mostly I wanted to make clear that although every USB mouse won't work, because it should be easy to find one that will, one should not be discouraged from connecting one up. I am very happy with how easy it was to get on old Microsoft optical USB mouse working as an optical rotary encoder on one of my first Arduino projects.

And of course mice and keyboards are a special case because there is USB support for the legacy protocol. I do completely agree with cheater and kg4wsv's views on the complexity of supporting a true USB host interface.

jfranchino

Thanks for all your help, people.

I'll try the pull up resistors. It's a really small "travel mouse", so maybe it has some quirks.

If the pull up resistors don't do the trick, should there be some way that I could use a FTDI FT232RL cable? Or am I missing something here?
JF

mem

#13
Feb 28, 2008, 04:56 pm Last Edit: Feb 28, 2008, 04:56 pm by mem Reason: 1
If you have an old PC that doesn't have USB you could try the mouse through a USB to PS2 adapter.

If not but your PC is running windows, I would think a good test that a mouse supports legacy PS2 mode would be boot in Safe Mode using DOS prompt and see if the mouse connected to the PS2 port using the adapter can control the cursor. If it does than I would think it will probably work with the Arduino with pull-up resistors.

If not then you may need to find another mouse.

Cheater

Quote
If the pull up resistors don't do the trick, should there be some way that I could use a FTDI FT232RL cable? Or am I missing something here?

The FTDI stuff is USB to serial only. It wont do USB HID (Human Interface Device) stuff.

Go Up