An USB Inertial Mouse with FreeIMU and Arduino Leonardo in 10 lines of code
Submitted by fabio on Mon, 2012-07-23 18:20.
Today the Arduino team officially presented the Arduino Leonardo with a video from Massimo Banzi, while it's been a while that the board has been launched and available for sale.
I really like the Arduino Leonardo and I'm already using it in some projects.. today however, I decided to make a simple little example program which shows the potential of the Arduino Leonardo.
I connected one of my FreeIMU to the Leonardo, wrote a bunch of lines of code and then, I had a simple USB inertial mouse! The code for this example is attached below.
Here is a video demonstration and a little explanation on how it works!
Kudos to the Arduino team for this great board!
| Attachment | Size |
|---|---|
| FreeIMU_inertial_mouse_leonardo.ino | 1.14 KB |



Have you gotten to get it to work with Bluetooth?
Hey Fabio, I've followed much of your work, which has helped me immensely in my school projects. I just built a similar mouse to work with the Leonardo and an ArduIMU v3. The code is working when using the USB connection; however, I can't get it to work over Bluetooth. I can transmit and receive data via BT, but I can't get the actual mouse to move. I think the mouse.move()command works through the USB connection (using the emulated VCP port) but not through the UART hardware which allows one to connect via BT (the second serial port--If I understand this all correctly). I would greatly appreciate any help you could give me--your knowledge and experience greatly surpasses mine.
One more thing
I forgot to add that when I connect via USB, my Device Manager shows the Leonardo as an HID and gives it 2 serial COM ports. But when paired and then connected via BT, it doesn't show as an HID--it just gives the 2 COM ports.
Unfortunately, it's not that
Unfortunately, it's not that simple. The Mouse class of the Arduino Leonardo will work only when the Leo is connected to the USB. It won't work when connected via Bluetooth. As you said, your bluetooth module creates a Serial port for you, but not a Keyboard/Mouse device.
So, in order to implement something like that you have two possibilities:
Hope this helps.
Yes, thank you! That clears
Yes, thank you! That clears everything up for me. Do you have any idea why Arduino haven't implemented the Mouse class to work over serial(BT)? the only Human Interaction development anyone cares about it is wireless. Few people would actually use an interface device that is still tethered.
Inertial mouse
Hello, I've done similar inertial mouse adding wireless bluetooth technology: http://www.youtube.com/watch?v=iqPQRv7-3Zc
By the way, your blog is priceless, keep up the good work.
Nice!
Nice!
Post new comment