geekhack

geekhack Projects => Making Stuff Together! => Topic started by: inornate on Thu, 28 March 2019, 16:10:39

Title: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: inornate on Thu, 28 March 2019, 16:10:39
Hi, geeks.

This is yet another attempt to make a DIY mouse, but using Arduino.

# TL;DR

# Introduction
I spotted an old thread "DIY PMW-3360 Gaming mouse", https://geekhack.org/index.php?topic=89837 (https://geekhack.org/index.php?topic=89837) and I hope to resurrect the project. I got a PMW3360 sensor module, which is still one of the best in mice market, from Tindie and attempted to get it to work.

The MrJohnK's original Arduino examples (https://github.com/mrjohnk/PMW3360DM-T2QU (https://github.com/mrjohnk/PMW3360DM-T2QU)) doesn't work quite well with fast movement (e.g., https://github.com/mrjohnk/PMW3360DM-T2QU/issues/22 (https://github.com/mrjohnk/PMW3360DM-T2QU/issues/22))

In the other hand, the most successful attempts for interfacing PMW3360 family so far have been done by qsxcv et al. with a combination of Teensy 2.0 + PMW 3366 (or PMW 3360) sensor, as like in https://www.overclock.net/forum/375-mice/1561041-reverse-engineering-3366-a-35.html#post26314321 (https://www.overclock.net/forum/375-mice/1561041-reverse-engineering-3366-a-35.html#post26314321) and  https://www.youtube.com/watch?v=nyb6M89QrWI&t=1s (https://www.youtube.com/watch?v=nyb6M89QrWI&t=1s). They used a bulk transfer to minimize the communication cost between the module and MCU, which works better at high speed.

As Arduino is an easy and handy platform than a cumbersome AVR-GCC coding on Teensy, I feel like I need a complete set of examples which can drive the module on Arduino IDE.

# Implementation Example
[attachimg=4]
[attachimg=5]

# Download
Go https://github.com/SunjunKim/PMW3360_Arduino (https://github.com/SunjunKim/PMW3360_Arduino) and hit the download link. Detailed instruction is provided on the README.

# What it does
- PMW3360DM-Burst: Minimal burst reading (Serial outputs x/y displacements)
- PMW3360DM-Mouse: A functional high-performance mouse implementation
- PMW3360DM-Camera: A raw sensor image capture

# Mouse firmware demo
## DIY mouse (PMW3360) vs. Logitech G502 (PMW3366)
Test method: Logged with MouseTester v1.5 https://www.overclock.net/forum/375-mice/1590569-mousetester-software-reloaded.html (https://www.overclock.net/forum/375-mice/1590569-mousetester-software-reloaded.html)
In dual mouse mode. I shaked the two mice together, one in straight and one in reverse. The logged data will result in negative to each other. Both mice set to the same CPI, 1200.


Blue: G502 / Green: DIY
=> Almost equivalent performance.
[attachimg=1]
[attachimg=2]
[attachimg=3]
 
## Playing Osu! with DIY mouse
=> Gamer-grade performance. No flaw in action (except my poor Osu! score...)
Title: Re: Open source, DIY PMW3360 Gaming Mouse with Arduino
Post by: nevin on Thu, 28 March 2019, 17:06:34
Awesome! Thanks!
There's a couple of us working on one as well. Will definitely check it out!
Title: Re: Open source, DIY PMW3360 Gaming Mouse with Arduino
Post by: inornate on Sat, 30 March 2019, 13:52:31
Some interesting example surfaces captured with the "Camera" firmware:
=> 36x36 images with SQUAL (=surface quality, higher is better) value.

Logitech G440 Mousepad
[attachimg=1]

Anodized Aluminum (=Apple MacBook Retina 2013)
[attachimg=2]

Fabric (a t-shirt)
[attachimg=3]

A4 print paper
[attachimg=4]

Printed character (by a laser printer) on A4 paper
[attachimg=5]

Office desk (white)
[attachimg=6]

Leather
[attachimg=7]
Title: Re: Open source, DIY PMW3360 Gaming Mouse with Arduino
Post by: nevin on Sat, 30 March 2019, 14:57:35
On your git page you mention the encoder. it should work, as long as it's mechanical and not optical (which it looks like it is).
Here's a link to buxtronix who's worked with the 3360 as well.
http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
https://github.com/buxtronix/arduino/tree/master/libraries/Rotary (arduino rotary library & examples)

gipetto on overclock did a optical scroll wheel as well (https://www.overclock.net/forum/375-mice/1561041-reverse-engineering-3366-a-42.html#post27056577)



Also, attached is what our group is running on Teensy 2.0s. I only made a small adjustment to the resolutions in the profiles.
Quote
the edit/changes to this copy of the firmware:
uint8_t dpis[] = {7, 13, 19};
## representing 800, 1400, 2000 dpi
   - now, if the 800 & 2000 are in the wrong orientation to what you prefer we can switch it as it's saying that the first number "800" is profile 2, "1400" is profile 1/default, and "2000" is profile 3

// The first number is for Profile 2 (rear side button)
// The second number is for profile 1 (Default profile)
// The third number is for profile 3 (front side button)

(looks like this addresses the 16bit motion data too, look in usb_mouse.c). I'm waiting for parts to arrive to piece mine together. I've only been messing with the firmware & researching up to this point.

One thing i would like to do is add the ability to use keyboard key codes on a couple of the mouse buttons. I saw an example by gipetto but haven't had a chance to mess with it yet.

[attachurl=1]
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: inornate on Sat, 30 March 2019, 16:44:46
On your git page you mention the encoder. it should work, as long as it's mechanical and not optical (which it looks like it is).
Here's a link to buxtronix who's worked with the 3360 as well.
http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
https://github.com/buxtronix/arduino/tree/master/libraries/Rotary (arduino rotary library & examples)

gipetto on overclock did a optical scroll wheel as well (https://www.overclock.net/forum/375-mice/1561041-reverse-engineering-3366-a-42.html#post27056577)

Thanks for the references. I'm knowledgeable about how they work (both optical/rotary encoders) but it's a matter of free time I have for the project...


Also, attached is what our group is running on Teensy 2.0s. I only made a small adjustment to the resolutions in the profiles.
I'm also checking that firmware as well! A nicely implemented beauty.


(looks like this addresses the 16bit motion data too, look in usb_mouse.c).
The development branch of mine https://github.com/SunjunKim/PMW3360_Arduino/tree/development (https://github.com/SunjunKim/PMW3360_Arduino/tree/development) implemented the 16-bit motion report. I brought the HID report descriptor from the code you mentioned.


One thing i would like to do is add the ability to use keyboard key codes on a couple of the mouse buttons. I saw an example by gipetto but haven't had a chance to mess with it yet.

With Arduino it's fairly easy. Just add #include <Keyboard.h> on the top of a sketch, and send Keyboard.print(A_KEY_YOU_WANT). Check https://www.arduino.cc/reference/en/language/functions/usb/keyboard/ (https://www.arduino.cc/reference/en/language/functions/usb/keyboard/).

Thanks for your interest!
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: nevin on Sat, 30 March 2019, 21:17:05
The "public" is probably better than what we're running
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: inornate on Sun, 31 March 2019, 15:45:27
The "public" is probably better than what we're running

I see buxtronix's implementation is clear and concise. I'll start from that in my project. :)
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: nevin on Sun, 31 March 2019, 16:45:52
Yeah, after a a little more digging... public is good, 5 button.

Buxtronix is public with cleaned up wheel code.

So as far as what I can tell the Buxtronix is the latest/most complete? version

Some parts came in today, see if I have time tonight to try some stuff out.
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: xealous on Mon, 01 July 2019, 21:53:52
Thinking of building my own one:

What does the MrJohnK pcb actually do? I notice a bunch of smd components.
AFAICT the only thing these smd components provide is voltage regulation? But the Arduino Pro micro is 5v already, so no regulation is necessary?

Can we just solder from the atmega32u4 to the sensor (it's only $10.50usd with lens on aliexpress, vs $30 usd with the pcb).
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: inornate on Mon, 11 November 2019, 00:58:07
Thinking of building my own one:

What does the MrJohnK pcb actually do? I notice a bunch of smd components.
AFAICT the only thing these smd components provide is voltage regulation? But the Arduino Pro micro is 5v already, so no regulation is necessary?

Can we just solder from the atmega32u4 to the sensor (it's only $10.50usd with lens on aliexpress, vs $30 usd with the pcb).


PMW3360 sensor runs on 1.8V – 2.1V, a level converter is needed to communicate with any of Arduino boards runs on 3.3v or 5v. The SMDs on the MrJohnK PCB are for that.
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: gipetto on Thu, 02 January 2020, 17:48:46
I should clarify, I created a repo of mouse firmware based on bst and qsxcv's work. Then i ported buxtronix's rotary encoder code to the mouse firmware to take advantage of the better performance. ben buxton never worked on mouses afaik. just today i finished the assembly of this diy mouse pcb pictured. although you might think the pmw3360 is old hat and been surpassed, there has been a release of the srom_0x05 which removes smoothing at higher dpi, like the pmw3366. So it's still quite competitive.
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: mips on Mon, 06 July 2020, 09:12:52
I should clarify, I created a repo of mouse firmware based on bst and qsxcv's work. Then i ported buxtronix's rotary encoder code to the mouse firmware to take advantage of the better performance. ben buxton never worked on mouses afaik. just today i finished the assembly of this diy mouse pcb pictured. although you might think the pmw3360 is old hat and been surpassed, there has been a release of the srom_0x05 which removes smoothing at higher dpi, like the pmw3366. So it's still quite competitive.

Is there firmware out there that will work with a CoolerMaster MM530 mouse by any chance?

Some MM530 mice seem to develop an issue where the mouse freezes followed by usb disconnect. It's a known issue with no fix, not sure if it's hardware or firmware related.
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: nevin on Mon, 06 July 2020, 09:20:18
Quote
Is there firmware out there that will work with a CoolerMaster MM530 mouse by any chance?

Probably not, without replacing the controller. And at that point, it's probably easier to replace all the guts than to try & figure out how their pcb is designed/wired.

I haven't messed with one, but most off the shelf mice are locked into whatever programming utility they come with (if they have one).
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: gipetto on Tue, 07 July 2020, 03:24:38
Is there firmware out there that will work with a CoolerMaster MM530 mouse by any chance?

Some MM530 mice seem to develop an issue where the mouse freezes followed by usb disconnect. It's a known issue with no fix, not sure if it's hardware or firmware related.

I have little experience with arm but there's stm32 firmware here https://www.overclock.net/forum/375-mice/1724838-progress-fully-custom-mouse-16.html#post28500436
you would have to port the code to a slightly different arm architecture, probably not a huge job, just change registers following the datasheets and map the pinout the mouse uses.
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: Dont_Panic_101 on Thu, 18 February 2021, 16:09:07
So I am currently building this and I noticed that you have to files that say you have support for forward and back buttons. Which pins are they on? Or do I have to program them in myself?

Thanks!
Title: Re: Open source, DIY PMW3360 Gaming Mouse on Arduino
Post by: abraam on Thu, 21 October 2021, 14:55:09
Hello,

I know this was made a long time ago but I am planning on using this for the basics of something else. The thing is we are using an arduino uno. What pin would mt go to on the arduino uno?

Thank you in advance for the help to anyone that is still here