element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member Blogs Mystery Project #1 - Pi Pico HID Volume Controller
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Community Hub requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dougw
  • Date Created: 5 Apr 2025 2:00 PM Date Created
  • Views 2686 views
  • Likes 12 likes
  • Comments 51 comments
  • dougw
  • mystery project
  • pi pico volume controller
  • volume controller
Related
Recommended

Mystery Project #1 - Pi Pico HID Volume Controller

dougw
dougw
5 Apr 2025

Intro

This is the opening salvo in my 4 project push. Rather than simply presenting a chronological documentary or a report format with objectives and dry design documents, I wanted to make it a bit more interactive, so I presented pictures of the system for viewers to creatively deduce what they were looking at. This added a lot of interesting ideas to the blog comments. This blog is now updated, including a new title (to make the blog more searchable) and information identifying what the project does. I would like to thank the commenters for making this simple project into a more interesting and entertaining blog. 

This project was a result of my need for volume control of the speakers on my PC. The speakers have a volume control, but it is in an awkward location. I wanted something more convenient. My keyboard actually has function keys that can control volume, but I also find that an awkward method of volume control. It requires 2 keys to be pressed multiple times to reach a desired volume. The device shown here is an intuitive volume knob that can be positioned very conveniently. And I use it every day.

These are the clue images

  • this view does not show any cables....Relaxed

image

Here is the second image - showing an additional surface with the usual feline photobomber...

image

The next image will show the PCBs inside...

Okay - here is the exploded view....some of it should be quite recognizable...

image

Note how the main PCB slides into a slot making the set screw in the knob the only fastener in the system.

I had to play hockey this evening, so I didn't get around to a more complete description of the system, but I will try again tomorrow.

In the mean time - here is another picture of the assembled system....

image

Project Description

This device is a simple volume control for PC speakers.

It uses a Raspberry Pi Pico to read a mechanical rotary encoder and convert the rotation into HID keyboard volume control commands sent to a host PC via USB.

The Pi Pico is mounted on a custom PCB which simply provides connections between the Pico and the encoder.

Here is a schematic of the relevant connections:

Schematic

image

Firmware

# Pi Pico Volume Contrroller by Doug Wong 2025
# Pi Pico HID volume firmware
# This program reads a mechanica rotary encoder that generates a quadrature signal on 2 pins
#  the up or down pulses are sent to the host computer via a HID USB driver that emulates a keyboard
#  the HID commands are volume controol instructions

# import libraries
import usb_hid
import board
import digitalio
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode

# Define pin numbers for the rotary encoder 
CLK_PIN = board.GP16
DT_PIN = board.GP17
SW_PIN = board.GP18

# debouncing variables
clk_last = None
count = 0
 
keyboard = ConsumerControl(usb_hid.devices)

# Define Encoder pins
clk = digitalio.DigitalInOut(CLK_PIN)
clk.direction = digitalio.Direction.INPUT
 
dt = digitalio.DigitalInOut(DT_PIN)
dt.direction = digitalio.Direction.INPUT
 
sw = digitalio.DigitalInOut(SW_PIN)
sw.direction = digitalio.Direction.INPUT
 
# Define USB HID volume control commands
def ccw():
    print("CCW")
    keyboard.send(ConsumerControlCode.VOLUME_DECREMENT)
 
def cw():
    print("CW")
    keyboard.send(ConsumerControlCode.VOLUME_INCREMENT)

# Endless loop to read encoder and send volume commands 
while(1):
    clkState = clk.value
    if(clk_last !=  clkState):
        if(dt.value != clkState):
            cw()
        else:
            ccw()
    clk_last = clkState;

Discussion

This volume control device is a very simple build that uses parts I already had lying around. Normally I probably wouldn't design a PCB board just to connect an encoder, but I had a PCB that already included the right connections. I enjoyed the simplicity of the build and I really enjoy the convenience it provides for a function I use every day. One thing I may do to improve this device is to replace the knob with a more massive knob that would allow it to be spun and have its momentum continue spinning until it is stopped.

Again, I would like to say I enjoyed the interesting comments in response to the mystery images.

Other Mystery Projects

Mystery Project #1

Mystery Project #2

Mystery Project #3

  • Sign in to reply
Parents
  • Andrew J
    Andrew J 1 month ago

    Sweet.  If the encoder had a press switch you could incorporate play/pause feature.  A larger knob would make it more comfortable to operate for sure.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 1 month ago in reply to Andrew J

    "...A larger knob would make it more comfortable to operate for sure..."

    Looks like Mackie already thought of that one
        https://mackie.com/en/products/studio-monitoring/big-knob-series/big_knob_passive.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J 1 month ago in reply to beacon_dave

    I'm not sure I would call it that, particularly if marketing into the UK!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave 1 month ago in reply to Andrew J

    Luckily, they have taken precautions in their previous documentation...

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • beacon_dave
    beacon_dave 1 month ago in reply to Andrew J

    Luckily, they have taken precautions in their previous documentation...

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube