USB Scroll Wheel
I have been having a play with a rotary encoder this week and decided to turn it into a USB scroll wheel. I was using a very nice encoder but any standard potentiometer without the stop or a cheaper encoder would also work.
The whole experience turned out be much easier than I originally thought. To get a standalone USB device up and running took very little effort at all.
I took one of my ATtiny45 USB-Key PCBs and hacked on a voltage divider (two 330k resistors) and some wires to my encoder (+5v, GND, Signal). The purpose of the voltage divider is to keep the sensor output (or ADC input) below the 2.56 vRef being used on the chip and also below the 3.6V being used as Vcc on the PCB.
No pictures or videos yet as it is just a ball of wires.
The firmware is based on the Easy logger project from Objective Development
. I changed the USB HID report descriptor to reflect a mouse rather than a keyboard. I then added a bit of code to analyse the ADC reading and calculate the rotational velocity of the wheel.
The device is only active once you push the button. This is to stop everything going crazy when I plug in a half finished device during development. The device can be switched off again by another press of the button for the same reason.
I got pretty bored reading all the USB HID documentation so rather than figuring it all out properly, I just snooped in on my normal mouse, read the HID report descriptor and adapted the relevant parts used for it’s scroll wheel. The software I used to snoop was “USB Prober” which is in my Utilities folder (Mac OS X 10.5). This might be a standard issue tool or I may have installed it as part of the developer tools. A screen-shot of grabbing this information is shown here
. I don’t know where or how to find out this info on windows but I’d look at Jan Axelson’s site here
as a good place to start.
PROBLEMS / STATUS
Even though I’ve altered USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH in the code it doesn’t seemed to have effected the report descriptor on the computer. More than likely I’ve missed something somewhere but that is what you get for a quick hack.
It doesn’t work that well but it does work. Most importantly it proves to me that I can now take any sensor I like and turn it into a computer interface device of some description… perhaps even do something usefull … one day … maybe. If I ever get some presentable hardware together I’ll update with a picture or two.