controlling mouse cursor with pushbuttons

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello people!!

After going through the tutorials posted here and implementing them, I was just wondering if it is possible to control the mouse cursor on my laptop monitor through pushbuttons by my atmega32a. Please suggest what topics/concepts do I need to master before attempting this Herculean task! Please provide me the correct direction as right now I am all clueless! Do I need to understand how my mouse driver works ? So many questions to answer!!

Thank you so much for your reply.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

noob_geek wrote:
Do I need to understand how my mouse driver works

Not how the driver itself works, but the events that it feeds into Windows.

 

For questions about Windows internals, go to MSDN - the Microsoft Developer Network: https://msdn.microsoft.com/en-gb...

 

Possibly the easiest (sic) way to do it would be with a USB microcontroller and have it be a HID (Human Interface Device) and send mouse movement events.

 

You might be able to find some documentation of the Serial Mouse protocol(s), and implement that?

 

But none of this is "noob" or beginner stuff

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To do this you would probably want to use a mega AVR with USB interface. If you do then you would likely use "LUFA" software. If you look at that I seem to remember it has a demo that is very close to what you want to do in fact.

 

(exactly how controllable a mouse is using just up/down/left/right buttons is another question entirely!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you so much for the fast reply!

I was just browsing the forum and stumbled upon it:

https://www.avrfreaks.net/forum/u...

What about the link posted by JohanEkDahl ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

USBasp is a pretty often used programmer which uses V-USB as a software USB stack for a m8 which has no hardware USB.

V-USB also implements HID "endpoints" (a usb technical term).

 

http://www.fischl.de/usbasp/

https://www.obdev.at/products/vu...

 

I think tinkering with V-USB is one of the best ways to learn how low level USB stuff works.

I've looked (breefly) into uC's with hardware USB support but because of the complexity of USB (and USB hardware & Lots of USB software) loads of configuration options it is hard to fully understand. I got completely lost in "LUFA" which looks like a big blob of ... to my poor damaged brain cells.

But if you have a reasonable background in understanding C and programming AVR's then following the program flow through V-USB is a relatively gentle learning curve.

 

There are also a bunch of complete examples for sending HID info on the obdev site:

https://www.obdev.at/products/vu...

 

Also note that V-USB can only use low speed usb signalling (@ 1500kbps) which is low enough for a very cheap logic analyser to capture.

Searching for "24M 8CH" on ali will direct you to a USD 5 "salaea clone logic analyser" which works pretty well with the open source sigrok/pulseview combination.

Pulseview also has decoders built in for USB signals.

 

https://www.aliexpress.com/whole...

http://sigrok.org/wiki/Supported...

 

And only after typing the above I see now that you've already found V-usb from link #4...

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Wed. Jul 19, 2017 - 11:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Addition:

Just for kicks I've done a little experiment with Pulseview.

I've connected one end of my USD 5 Saleae clone to a usb hub and started Pulseview.

I've also connected the other end (LA data input) of the Saleae clone to the D+ and D- lines of a USBasp programmer.

Then I set up Pulseview and plugged the USBasp into the same USB hub.

 

On the first try I captured a whole lot of signal transitions on the LA channels (Brown D+ and Black D-).

Then I added the "USB Signalling" decoder, which added the two "signal" traces

This added "Keep alive",  Start "End of Packet" signals on the "bits" trace (Not shown in screen dump).

On the "symbols" trace it added "J", "K", "SE0" names.

Then I added the "USB Packet" decoder on top of the "USB Signalling" decoder.

This added a whole lot of extra meaning to the 2 meagre D+ and D- lines.

I can se now Sync, Ack, Nak, Data, PID, CRC5, CRC16 and more stuff.

I've captured about 850ms of data and each ms "something" happens on which you can zoom in.

7 out of 8 are "keep alive" events, so there are still more than a 100 packets to analyse from the first change of the USB bus which starts the USB initialisation / discovery / whatever.

 

Note:

Usb does some "bit stuffing" to generate extra flanks in signals. For example, in the screenshot you can see a data byte 0x00 but it is sent as an alternating bunch of "J" and "K" symbols.

This makes the raw USB data very hard to interpret for normal human beings. I've also heard something vague about 8/10 encoding to prevent more than 5 consecutive bits without a level change to ease bit synchronisiaton. Good luck decoding that directly from the D+ / D- lines without help from software.

 

Note 2:

This is the first time in my life ever that I've captured USB data with a LA and I do not have much understanding of the USB protocol, but I'm very much impressed with what you can do nowaday's with the open source Sigrok/Pulseview combination and USD 5 worth of hardware and how it can aid in understanding pretty complex protocols such as USB.

Attachment(s): 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Thu. Jul 20, 2017 - 12:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

8/10rll is most likely used in high speed USB - it is used in sata and pciExpress protocols.

For low and full speed USB, bit stuffing is used.

Thanks for the insight into using pulseview - i have no immediate need to analyse USB, but I'll keep it in mind.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Arduino Leonardo has an internal USB  interface.  There are several libraries included with the Arduino distribution that demonstrate how to control mouse and keyboard inputs using the Arduino Leo that has been plugged into the USB port on a PC.

 

Here is a link to a reasonably priced Leo with free shipping and a USB cable:

http://www.ebay.com/itm/Leonardo...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

noob_geek wrote:

Hello people!!

After going through the tutorials posted here and implementing them, I was just wondering if it is possible to control the mouse cursor on my laptop monitor through pushbuttons by my atmega32a. Please suggest what topics/concepts do I need to master before attempting this Herculean task! Please provide me the correct direction as right now I am all clueless! Do I need to understand how my mouse driver works ? So many questions to answer!!

Thank you so much for your reply.

 

When you say 'control', what do you intend, exactly ?

A standard mouse is relative, do you need absolute or relative control ?

Absolute would need a tablet driver, but those do exist.

 

An alternative approach is to find a ball mouse, and wire into the quadrature encoders and the buttons. 

Now you have simple MCU mouse control, without needing to know any USB.

 

Yet another approach, if you want absolute/tablet mode, is to use a serial port to emulate a tablet. Any MCU could do this.

 

Google find this

https://hiddenfreak.wordpress.co...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sigrok has almost 100 different protocol decoders.

Among which are some Atmel specific such as the PDI

http://sigrok.org/wiki/Protocol_...

http://sigrok.org/wiki/Protocol_...

 

Protocol decoders are also continuously  added.

They are writen in Python and usually have no more than a few pages of code. (I2C decoder is 10kB).

Also the idea of protocol "stacking" means less work for writing a decoder on top of an already known bus.

For example the nRF24L01+ decoder, which is stacked on top of the SPI decoder.

And being able to copy code from similar decoders and the decoder howto also helps to dive into writing a decoder yourself.

http://sigrok.org/wiki/Protocol_...

 

But I'll try to stop my rant / hyjack of this thread right here.

If it continues then please split it in a separate thread, Pulseview is certainly worth it.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This post is a little old. But if you are still looking to this, the easy way. You can take apart an old mechanical mouse or trackball. Break out the multimeter and logic analyzer and figure out how it works. I bet you will find two rotary encoders on two axis. If so those produce a gray code. That you can easily emulate with the uC. You may be able to pull down the rotary encoder pins. Then you can let the mouse’s controller do the heavy lifting.

I suggest first try on an old computer first, If you have one. Especially if you are new to electronics. And if don’t have a logic analyzer, get one. I have one from www.saleae.com and the app for it is easy to use.

I did something similar many years ago with a cheap keyboard for a simple control panel to trigger Ctrl + w, etc.. If you are just starting out. This would be educational  and fun to try…

“If at first the idea is not absurd, then there is no hope for it.” ― Albert Einstein