using an arduino to reverse engineer a usb mouse
Moderators: adafruit_support_bill, adafruit

using an arduino to reverse engineer a usb mouse

by berko on Fri Jan 04, 2013 10:54 pm

Hi,
I am hoping to use an old usb mouse to do some cool stuff.
some of the ideas i have is a tachometer/speedometer for my bike.
or some kind of data logger for a little motorized car i am building, the type of robot that senses an object and then turns. using the mouse sensor to keep track of its movements can then later be used to map a room, or objects in a room...
anyhoo.....
what i have done so far is taken the mouse apart and gotten the board out and figured what the pin outs are.
applied 5 volts/ground to the correct pins and confirmed that the button, for example, has 5 volts getting to it when open. 0 volts when pressed.
i then try to see what voltage was at the data pins and i got none. but this may be because i was measuring voltage between -D and +D and i am not sure if that is correct. according the wikipedia page (http://en.wikipedia.org/wiki/Universal_Serial_Bus) it seems that i should be getting between 0 and .3 volts for low and 2.8 and 3.6 for Hi but i am not seeing anything on my meter regardless if i push the button or not.

so, my questions are:
1) should i see voltage at the Data pins?
2) can i connect them to a analog pin on my UNO and then read what the mouse is spitting out on the serial port?
3) any other advice or knowledge to get me started?

thanks,
jon
User avatar
berko
 
Posts: 57
Joined: Sat Aug 04, 2012 5:44 pm

Re: using an arduino to reverse engineer a usb mouse

by westfw on Sat Jan 05, 2013 2:05 am

USB is a complicated protocol that sends messages consisting of number of bytes of data, sent one bit at a time at substantial datarates (1.5 Mb/s for "low speed" USB.)
Reading a USB "device" like a mouse using an Arduino is essentially hopeless; you need a special hardware peripheral to support talking to USB devices, and the Arduino doesn't have it (in fact, very few microchips have it.) (The Arduino ADK can do this, at least in theory.)

Now, if you have one of the MANY mice that can "talk" either USB or PS/2 protocols, depending on what kind of port it's actually plugged in to (typically using a physical adaptor that looks like this: Image, you could be MUCH more successful talking to it with PS/2 protocols. But you'll have to research how to spoof it into talking PS/2 if you no longer have the adapter.
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: using an arduino to reverse engineer a usb mouse

by berko on Sat Jan 05, 2013 7:28 am

thanks westfw,
i do have an adapter like that, so i will plug it in and see if i can get it to work.
best,
jon
User avatar
berko
 
Posts: 57
Joined: Sat Aug 04, 2012 5:44 pm

Re: using an arduino to reverse engineer a usb mouse

by adafruit_support_rick on Sat Jan 05, 2013 1:45 pm

The Adafruit ATmega32U4 Breakout Board, the Teesny 2.0, the Arduino Leonardo, and the Arduino Micro all have the ability to directly host USB devices like mice, keyboards, flash-drives, etc. This is because they are based on the ATmega32u4 processor, which has built-in USB support, instead of the ATmega328, which does not.
User avatar
adafruit_support_rick
 
Posts: 12308
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: using an arduino to reverse engineer a usb mouse

by berko on Sat Jan 05, 2013 2:55 pm

Thanks driverblock. Very helpful
User avatar
berko
 
Posts: 57
Joined: Sat Aug 04, 2012 5:44 pm

Re: using an arduino to reverse engineer a usb mouse

by westfw on Sat Jan 05, 2013 4:07 pm

the 32u4 contains only USB device support, which enables it to BE a mouse, keyboard, etc. To connect to a usb device like a mouse, the chip would have to have USB host support, which is much less common.

The Teensy 2, leonardo, and Arduino Micro will NOT talk to a USB mouse.
I think Teensy 3 is capable of USB host mode and has a USB OTG connector, but I don't know if there is any SW support for this yet.
User avatar
westfw
 
Posts: 1373
Joined: Fri Apr 27, 2007 12:01 pm
Location: SF Bay area

Re: using an arduino to reverse engineer a usb mouse

by adafruit_support_rick on Sat Jan 05, 2013 4:42 pm

westfw wrote:the 32u4 contains only USB device support, which enables it to BE a mouse, keyboard, etc. To connect to a usb device like a mouse, the chip would have to have USB host support, which is much less common.


D'Oh!! You're right. Mea culpa.

Never mind...
User avatar
adafruit_support_rick
 
Posts: 12308
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: using an arduino to reverse engineer a usb mouse

by berko on Wed Jan 09, 2013 11:16 am

Hey Guys,
I found this one the web....

interfacing-an-optical-mouse-sensor-to-your-arduino

thanks Matt Richardson

thought i would share for those of you also interested.
Once i get it all figured out (different chip then in the article and he says the library needs updating) i will post more info.
Feel free to do the same if you get it figured out first.

-jon
User avatar
berko
 
Posts: 57
Joined: Sat Aug 04, 2012 5:44 pm