Author Topic: How to add a Volume knob?  (Read 11948 times)

0 Members and 1 Guest are viewing this topic.

Offline Vladimir

  • Thread Starter
  • Posts: 80
  • Location: Brazil
  • Professional Dream Crusher
How to add a Volume knob?
« on: Wed, 06 September 2017, 19:15:04 »
I didn't see on QMK docs how to work with a potentiometer to control volume.


100 mΩ

Since every switch has 2 pins that we use for column and row, to indentify it in the matrix, can we connect the potentiometer with 1 row and 2 columns for its 3 pins (A,C,B on the scheme above)? Every column here would mean Raise and Lower Volume. Also, since there's no identification on it, there's a specfic order that I have to connect/solder the pins?

On QMK I've just use 2 keys on the same row to identify the potentiometer. This will work?
 
 Matias Mini Quiet Pro              Noppoo Nano 75-S Brown

Offline vvp

  • Posts: 887
Re: How to add a Volume knob?
« Reply #1 on: Thu, 07 September 2017, 11:03:08 »
I do not think that standard USB keyboard protocol supports analog information. If you want your keyboard to work without special drivers then you need to pass only discrete volume up/down signals. Use rotary encoder (instead of a potentiometer) to  obtain the signals. I do not know whether QMK supports rotary encoder directly. You may need to extend the firmware.

But the best is just to stick with the standard volume up/down keys ... it is less work that way :)

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: How to add a Volume knob?
« Reply #2 on: Thu, 07 September 2017, 11:12:48 »
Maybe you could interpret the rotary encoder pulses as repeated presses of the volume up/down key, perhaps doing some division if the encoder puts out a lot of pulses/turn.
REΛLFORCE

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: How to add a Volume knob?
« Reply #3 on: Thu, 07 September 2017, 13:27:18 »
The USB HID standard does support volume control knobs. Code 0xe0 "Volume" (LC) in the "Consumer" usage page 0x0c.
However, the question is what your operating system supports ... and AFAIK no operating system fully supports the entire HID standard.
It would most likely have to be a relative control, however - which I think is best anyway because otherwise you would have to make it motorised to have it update itself to volume changes done other ways in the operating system -- and I am not even sure that motorised volume controls are even supported by any operating system.

I think the best way to do it would be with a rotary encoder that you poll every millisecond. That speed should be fast enough for anything you can turn by hand.
Rotary encoders are relative, where as potentiometers are absolute.

Then.. you would have to implement this in QMK. From what I can glance, QMK does not seem to have support for a volume knob, so you would have to write it all yourself.
It does seem to support volume up/down keys but not a direct relative volume knob.

Edit:
I found an Arduino project for a volume knob that uses a rotary encoder and sends key presses.

Maybe you could interpret the rotary encoder as two keys - and you would get it debounced at the same time.
« Last Edit: Thu, 07 September 2017, 13:39:51 by Findecanor »

Offline 0100010

  • Posts: 1127
  • Location: DFW, TX, US
  • Not Sure
Re: How to add a Volume knob?
« Reply #4 on: Thu, 07 September 2017, 13:43:18 »
  Quoting me causes a posting error that you need to ignore.

Offline vvp

  • Posts: 887
Re: How to add a Volume knob?
« Reply #5 on: Fri, 08 September 2017, 03:43:15 »
Thanks Findecanor.
Volume control is there. But in the consumer electronics page (not a keyboard page). That makes OS support questionable ... as you indicated. Rotary encoder is a better option anyway.

Offline pomk

  • Posts: 470
  • Location: Finland
Re: How to add a Volume knob?
« Reply #6 on: Fri, 08 September 2017, 06:12:55 »
Thanks Findecanor.
Volume control is there. But in the consumer electronics page (not a keyboard page). That makes OS support questionable ... as you indicated. Rotary encoder is a better option anyway.
Consumer control page (0x0c, 0x01) does work at least in late windows releases, mac OS, iOS, Linux (at least most distros afaik) and android (though not all commands work with the base OS features). I don't know the status of DOS, Amiga, or Solaris etc. TMK uses the same consumer control page to send the volume commands forward (0xEA and 0xE9). Maybe worth trying to get the linear control (LC) command 0xE0 with the 'Absolute preferred state' flag set to work? It should be easy enough to test with any tmk kb that you have.
« Last Edit: Fri, 08 September 2017, 06:15:31 by pomk »

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: How to add a Volume knob?
« Reply #7 on: Fri, 08 September 2017, 06:54:55 »
Volume control is there. But in the consumer electronics page (not a keyboard page).
There is Volume Up and Volume Down in the Keyboard page and I think they were put there especially for Sun's keyboards .. and I think OS support for those is only in Solaris.
All other major OSs support at least Volume Increment and Volume Decrement in the Consumer page.

Offline vvp

  • Posts: 887
Re: How to add a Volume knob?
« Reply #8 on: Fri, 08 September 2017, 10:45:37 »
Thanks for comments.
Just one more data point. Volume up/down/mute keys from the keyboard page work in archlinux ... at least with xbindkeys. Other Linux distributions may work out of the box.
Code: [Select]
# File: .xbindkeysrc
# Increase volume
"pactl set-sink-volume `pactl list short sinks |cut -f1` +2%"
   XF86AudioRaiseVolume
# Decrease volume
"pactl set-sink-volume `pactl list short sinks |cut -f1` -2%"
   XF86AudioLowerVolume
# Mute
"pactl set-sink-mute `pactl list short sinks |cut -f1` toggle"
   XF86AudioMute

Offline hasu

  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: How to add a Volume knob?
« Reply #9 on: Sat, 09 September 2017, 22:47:25 »
Thanks Findecanor.
Volume control is there. But in the consumer electronics page (not a keyboard page). That makes OS support questionable ... as you indicated. Rotary encoder is a better option anyway.
Consumer control page (0x0c, 0x01) does work at least in late windows releases, mac OS, iOS, Linux (at least most distros afaik) and android (though not all commands work with the base OS features). I don't know the status of DOS, Amiga, or Solaris etc. TMK uses the same consumer control page to send the volume commands forward (0xEA and 0xE9). Maybe worth trying to get the linear control (LC) command 0xE0 with the 'Absolute preferred state' flag set to work? It should be easy enough to test with any tmk kb that you have.

I tried Volume Control(E0, LC) quickly but it doesn't seem to work with Ubuntu and WIndows 10. But I might be wrong with descriptor or something.

Potentiometer would not be good idea if OS doesn't support this usage.

Offline pomk

  • Posts: 470
  • Location: Finland
Re: How to add a Volume knob?
« Reply #10 on: Mon, 11 September 2017, 02:15:16 »
Thanks Findecanor.
Volume control is there. But in the consumer electronics page (not a keyboard page). That makes OS support questionable ... as you indicated. Rotary encoder is a better option anyway.
Consumer control page (0x0c, 0x01) does work at least in late windows releases, mac OS, iOS, Linux (at least most distros afaik) and android (though not all commands work with the base OS features). I don't know the status of DOS, Amiga, or Solaris etc. TMK uses the same consumer control page to send the volume commands forward (0xEA and 0xE9). Maybe worth trying to get the linear control (LC) command 0xE0 with the 'Absolute preferred state' flag set to work? It should be easy enough to test with any tmk kb that you have.

I tried Volume Control(E0, LC) quickly but it doesn't seem to work with Ubuntu and WIndows 10. But I might be wrong with descriptor or something.

Potentiometer would not be good idea if OS doesn't support this usage.
Oh, that's too bad :(