Software

Leadership

Experience

USB Volume Control Knob

Project Tags

#Adafruit #Trinkey

Rotary encoder top view Have you ever wished that your computer came with a knob to adjust its volume, like your stereo has? I have, and decided to do something about it. Searching on Adafruit for electronic goodies, I found their Rotary Trinkey. It plugs in to a standard USB A port, and can have a rotary encoder mounted on it. After a quick soldering job to attach the rotary encoder (only five signalling pins and two stabilizer tabs), it was ready to program.

Rotary encoder bottom view Adafruit has excellent learning guides, and their guide for this item is no exception. It covered the basics of installing CircuitPython, the device pinout, and included example Python code covering all the device features.

Looking at all the features available, I decided on the following:

  • Rotary encoder will change the volume, sending the virtual key codes XF86AudioRaiseVolume and XF86AudioLowerVolume (Linux equivalents to VK_VOLUME_UP and VK_VOLUME_DOWN in Windows).
  • Pressing down on the rotary encoder will act as a play/pause button, sending XF86AudioPlay (Linux equivalent to VK_MEDIA_PLAY_PAUSE in Windows).
  • As the dial is turned, the NeoPixel will change hue. When the Trinkey is first plugged in, it will start at red.
  • Touching the capacitive touch bar will cycle the brightness, increasing to 100%, then lowering to 0%, and back. Initial brightness will be 50%.

Rotary encoder in use Since a rotary encoder doesn’t know it’s absolute position (unlike a potentiometer), I don’t need to worry about the current volume setting, and can just send relative adjustments to the volume level. The virtual keys that I send work on any system that can handle a regular multimedia keyboard, as I’m sending the same keystrokes through the Trinkey - it behaves as a USB HID device.

See the full code on GitHub.