Author Topic: USB Volume Knob  (Read 5375 times)

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
USB Volume Knob
« on: January 11, 2013, 07:08:14 am »
I combined a Digispark with a two-bit clicky encoder to create a usb volume knob. I made it because the Griffin Powermate is surprisingly bad at being a volume knob.

Hook it up like this:



And upload the sketch.

Originally I connected the push button wire (pins on left side of encoder) to D0 instead of D5, but it wouldn't work for me - seems like the LED on that pin drains so much power it pulls the pin low!!! That's pretty annoying. Hopefully future Digisparks use a blue or white LED there to be more careful not to pull it low. Green is pretty though! ^_^

I tested it on my Mac and it's working great. It should work on any system which supports keyboards with volume buttons on them. <3
« Last Edit: January 11, 2013, 09:03:31 pm by Bluebie »

Russtang

  • Newbie
  • *
  • Posts: 2
USB Volume Knob
« Reply #1 on: January 11, 2013, 11:03:05 am »
Super cool!  Gotta dig up an encoder and check it out...

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
USB Volume Knob
« Reply #2 on: January 14, 2013, 04:30:39 pm »
I booted my computer in to windows, but it doesn\'t seem to work. The operating system detects the digispark and recognises the DigiKey keyboard but it doesn\'t seem to react at all to knob twisting or pressing. I don\'t know what is going on! Any ideas? I\'ll be curious to try it out in linux some time too.

plexer

  • Newbie
  • *
  • Posts: 23
USB Volume Knob
« Reply #3 on: January 15, 2013, 04:14:01 am »
What are the keyboard commands sent by the digispark in relation to the know twisting?

Ben

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
USB Volume Knob
« Reply #4 on: January 15, 2013, 05:51:06 am »
#define KEY_MUTE 127
#define KEY_VOLUME_UP 128
#define KEY_VOLUME_DOWN 129

Taken from http://www.usb.org/developers/devclass_docs/Hut1_11.pdf page 56

KEY_MUTE is used when the button is pressed in, KEY_VOLUME_UP is sent each time the knob clicks one notch clockwise, KEY_VOLUME_DOWN is sent when turned one notch anticlockwise.

plexer

  • Newbie
  • *
  • Posts: 23
USB Volume Knob
« Reply #5 on: January 15, 2013, 07:42:32 am »

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
USB Volume Knob
« Reply #6 on: January 15, 2013, 03:33:23 pm »
I guess so? This one uses the DigisparkKeyboard library

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
Re: USB Volume Knob
« Reply #7 on: March 13, 2013, 10:31:29 pm »
I updated the code a little so the mute button debounce is better. No more glitchy mute buttons yay! Does anyone know why it doesn't work in windows? It'd be nice if there were some way to fix this. I don't know much about windows though - I only use it as the backend for a steambox and occasionally compiling bootloader stuff.


On the topic of bootloaders, if you made one of these and wired it up like me you can use the micronucleus jumper varient to make it boot instantly instead of waiting five seconds. Just hold down the mute button when you plug it in to enter programming mode then choose upload in the digispark software to upload a new program at your leasure (it doesn't time out after five seconds). Then after uploading it will instantly run in the next version of the digispark software or with my mac beta build. In current versions I think you have to unplug and replug the device once done uploading still. Jumper varient is at http://digistump.com/board/index.php/topic,320.0.html

Mark

  • Full Member
  • ***
  • Posts: 196
Re: USB Volume Knob
« Reply #8 on: March 13, 2013, 11:29:09 pm »
Jenna

In windows the keys are mapped based on the country and keyboard mapping.
You can try these codes.
http://msdn.microsoft.com/en-nz/library/windows/desktop/dd375731%28v=vs.85%29.aspx
they may match.

Quote
#define KEY_MUTE 127  0xAD
#define KEY_VOLUME_UP 128  0xAF
#define KEY_VOLUME_DOWN 129  0xAE
Mark

koogar

  • Newbie
  • *
  • Posts: 1
Re: USB Volume Knob
« Reply #9 on: July 26, 2013, 02:08:58 pm »
Has anyone had any luck with this in windows yet.

From what i can gather to enable multimedia buttons in windows you need to configure it as a Consumer control device.

In order to control the device as determined by the media control keys was used corresponding USBHidReportDescriptor, taken from the USB descriptor multimedia keyboards, and writing the appropriate handling code.

Example USB descriptor
PROGMEM char usbHidReportDescriptor [25] = {/ * USB report descriptor * /
 0x05, 0x0c, / ??/ ??USAGE_PAGE (Consumer Devices)
 0x09, 0x01, / / ??USAGE (Consumer Control)
 0xa1, 0x01, / / ??COLLECTION (Application)
 0x85, 0x01, / / ??REPORT_ID (1)
 0x19, 0x00, / / ??USAGE_MINIMUM (Unassigned)
 0x2a, 0x3c, 0x02, / / ??USAGE_MAXIMUM (AC Format)
 0x15, 0x00, / / ??LOGICAL_MINIMUM (0)
 0x26, 0x3c, 0x02, / / ??LOGICAL_MAXIMUM (572)
 0x95, 0x01, / / ??REPORT_COUNT (1)
 0x75, 0x10, / / ??REPORT_SIZE (16)
 0x81, 0x00, / / ??INPUT (Data, Var, Abs)
 0xc0 / / END_COLLECTION};



That was taken from http://obruboff.ru/usb-volume-control-ver-2/  which uses V-USB an ATTiny 85

I have build the circuit from the link above and it works great but its nice to have a bootloader as in the digispark.

Consumer Device Codes  http://msdn.microsoft.com/en-us/windows/hardware/gg462991.aspx
 
MUTE                    0xe2
VOLUME DOWN       0xea
VOLUME UP            0xe9



The V-USB MAME panel example has joystick,keyboard and consumer device in its USBHidReportDescriptor this also includes volume control http://vusb.wikidot.com/project:mamepanel

Any chance we could have a digispark consumer device library with the volume control as an example, as its pretty useful.


Thanks

Rupert


Mercules

  • Newbie
  • *
  • Posts: 1
Re: USB Volume Knob
« Reply #10 on: September 11, 2013, 06:52:56 pm »
I bought a digispark to do the same thing and was concerned I'd have the problem of windows not recognizing the media keys. My work around will be setting the volume controls as joystick buttons and using and input emulator to convert them to media keys (glovepie or autohotkey).


Thanks for the code Bluebie. I will post if I get the media keys working natively. I will also post pictures when I build it.

EDIT: asked for code but I found it  :P
« Last Edit: September 11, 2013, 06:56:26 pm by Mercules »

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
Re: USB Volume Knob
« Reply #11 on: September 11, 2013, 07:09:29 pm »
I suggest instead of a joystick, you use function keys - if you make the knob emit function keys f14, f15, f16 for press and each direction of turn, that will be easy to map as a hotkey and be unlikely to mess with playing games, etc, plus if you ever want to assign it as a key in some program, it'll be easy. You could for instance assign the knob to turn an object around in a 3d editor, or zoom in and out in something, or scroll, or go through different tools in an art program.


Or maybe you could use a program like this? http://www.addictivetips.com/windows-tips/control-volume-with-hotkeys-using-volcontrol/ it might give you a better user interface anyway. With that one you can adjust how quickly it changes the volume setting.

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
Re: USB Volume Knob
« Reply #12 on: October 12, 2013, 10:25:55 pm »
Adafruit has made a keyboard library which can do multimedia keys on windows: http://learn.adafruit.com/trinket-usb-volume-knob/code

sys_spud

  • Newbie
  • *
  • Posts: 1
Re: USB Volume Knob
« Reply #13 on: December 14, 2013, 01:54:31 pm »
Hi Bluebie-

I tried making this, can only get the mute function to work, volume up/down no response. This is on a Mac Air OS/X 10.7.5. The troubleshooting I've done includes: continuity checks, changing the key codes. swapping out the encoder. I did a blink on the LED when the encoder is turned and that seemed to work. The encoder I'm using is the one adafruit sells.

I'm really surprised that something that worked for you and seems straightforward is giving me so much trouble.

I did have a question on the blue wire in your picture that seems to be connected to 5V pin, then can't tell where it connects up to. Your diagram doesn't show anything using 5V. Are you somehow connecting to GND with this instead, or something?

Any thoughts on troubleshooting this gratefully accepted!

Bluebie

  • Sr. Member
  • ****
  • Posts: 487
Re: USB Volume Knob
« Reply #14 on: December 15, 2013, 06:42:08 pm »
The blue and black wire in my photo are both connected to ground. Sadly this forum doesn't support holographic photos or else you'd be able to see it from another perspective. The wire is just soldered on from the side so it's sort of in front a bit from the camera's POV. The schematic doodle is correct.

I'm not sure what could be going on. I'm using mine with a Mac running 10.9. Maybe full USB support was a new addition and it'd be worthwhile to try using adafruit's library instead, which can emulate windows multimedia keyboards.