Showing posts with label USB HID. Show all posts
Showing posts with label USB HID. Show all posts

Wednesday, February 18, 2026

Build a Low-Cost DIY USB Volume Knob with Digispark ATtiny85

This project turns a cheap Digispark ATtiny85 USB dongle and a KY-040 rotary encoder into a dedicated hardware volume knob. Rotate clockwise for volume up, counter-clockwise for volume down, press to mute. It enumerates as a standard USB HID Consumer Control device — no custom driver, no desktop app. Linux, Windows, and many Android devices recognise it out of the box.

Last updated: February 19, 2026

3D render of the DIY USB volume knob showing a Digispark ATtiny85 board connected to a KY-040 rotary encoder

3D render of the assembled volume knob — Digispark ATtiny85 USB board with KY-040 rotary encoder.

Finished DIY USB volume knob plugged into a USB port, showing the Digispark board with rotary encoder attached

The finished USB volume knob — plug in and it works immediately as a standard HID device.

Why Build This?

Keyboard shortcuts work, but a physical knob is better when you are:

  • Switching between headphones and speakers
  • On a call and need instant mute
  • Using a media PC or mini server with no easy keyboard access
  • Tired of digging into software mixer panels

For around 5–10 USD in parts you get a dedicated hardware control that is always there.

Parts

Parts required for the DIY USB volume knob: Digispark ATtiny85 board, KY-040 rotary encoder, and jumper wires

Everything needed: Digispark ATtiny85 USB board, KY-040 rotary encoder module, and jumper wires.

  • Digispark ATtiny85 USB board — ~2 USD
  • KY-040 rotary encoder module — ~1 USD
  • Jumper wires (female-to-female) — ~1 USD
  • Optional: 3D-printed case or aftermarket knob for a cleaner finish

Wiring

Wiring diagram showing connections between KY-040 rotary encoder and Digispark ATtiny85 board

Connection diagram: KY-040 rotary encoder wired to the Digispark ATtiny85 USB board.

Rotary Encoder Digispark ATtiny85
CLK P5 (PB5)
DT P2 (PB2)
SW P0 (PB0)
+ 5V
GND GND

ATtiny85 pin mapping used by this project:

                 +-\/-+
ENC_A (CLK) PB5  1|    |8  Vcc
USB D-      PB3  2|    |7  PB2  ENC_B (DT)
USB D+      PB4  3|    |6  PB1
            GND  4|    |5  PB0  ENC_SW (SW)
                 +----+

Note: PB5 is used as GPIO for encoder input in this design (RSTDISBL fuse context applies when programming bare chips). Digispark boards typically ship in a suitable configuration already.

Assembly

The build is straightforward — solder the five wires between the encoder module and the Digispark board as shown in the wiring table above, then attach a knob cap. The numbered steps below show the full process from bare parts to finished device:

Step-by-step assembly of the DIY USB volume knob: 12 numbered photos showing progression from bare Digispark board and rotary encoder to finished USB device with knob cap

Assembly steps 1–12: from bare components to a finished USB volume knob ready to plug in.

Firmware

The firmware sends standard HID Consumer Control usages:

HID Usage Function
0xE9 Volume Increment
0xEA Volume Decrement
0xE2 Mute

Because these are standard HID usages, the host OS handles them natively — no custom driver needed.

Build and Flash

Clone the repository and build the firmware and uploader:

git clone https://github.com/hackboxguy/attiny85-hid-rotary-knob.git
cd attiny85-hid-rotary-knob
make all

This builds main.hex (firmware) and tools/micronucleus/micronucleus (uploader).

Flash via Micronucleus bootloader:

make upload

Tip: After running make upload, you will see "Waiting for device...". Plug in the Digispark within 60 seconds — the upload starts automatically once the bootloader is detected.

If your setup does not require sudo:

make upload SUDO=''

Note: Digispark boards come with the Micronucleus bootloader pre-installed — just plug in and upload. This blog assumes a board with a working bootloader. If you have a blank ATtiny85 chip without Micronucleus, flashing the bootloader requires an ISP programmer and is outside the scope of this guide.

Build prerequisites: Install gcc-avr, avr-libc, binutils-avr, libusb-1.0-0-dev, and pkg-config before running make.

Platform Compatibility

Linux

Works out of the box as a USB HID media control device. Desktop environments map it immediately to system volume and mute. Good fit for Ubuntu/Debian desktops, Arch with Wayland or X11, and Raspberry Pi media boxes.

Windows

Also works without drivers as a standard media-control device. If you briefly see "USB device not recognized" right after plugging in, that is the short Micronucleus bootloader window before the firmware enumerates. After handoff, the knob works normally.

Android

Works on Android devices that support USB OTG and HID media keys. You need a USB-C OTG adapter (or Micro-USB OTG on older phones) and OTG host support enabled on the device.

Android caveats: Behaviour can vary by OEM/ROM. Some devices only react when the screen is unlocked, and mute handling may differ across apps.

Troubleshooting

  • Build fails with missing AVR tools — Install the prerequisites listed in the Build and Flash section above.
  • Linux error -71 during USB enumeration — Reflash or repair the bootloader. See the repository troubleshooting section.
  • No response to rotation — Check CLK/DT wiring first (most common issue), then confirm the encoder module GND and 5V connections.

Going Further

The firmware is intentionally simple and stable, but the hardware supports extensions:

  • Multi-mode knob (volume / media transport / brightness)
  • Long-press and double-click actions
  • Mode indicator LED
  • Additional HID report descriptors

Start with a practical tool, then evolve it into a custom desktop controller.

Monday, January 09, 2012

OpenUI: IR Remote, LCD & I2C for Headless Linux

A tiny USB device called OpenUI that adds an IR remote receiver, LCD display, RTC, and I2C bus to any headless Linux box — built around an ATtiny2313 acting as a USB HID device.

OpenUI schematic

OpenUI schematic — ATtiny2313 with USB, IR receiver, LCD, RTC, and I2C expansion.

The problem

For most embedded applications, micro-controllers work well for their low cost and simplicity. But as soon as you need networking on an MMU-less processor, hardware becomes expensive and complex — you need a processor with an MMU and an OS for basic networking and file management.

Technology enthusiasts, hardware hackers, and DIYers find it difficult to use PC-like motherboards that are expensive, bulky, and power-hungry for tiny embedded needs. Over the past few years, we've seen the DIY community shift from micro-controller-based hardware to Linux single-board computers. The mobile market is driving semiconductor companies to build low-cost yet powerful SoCs capable of running Linux at the $5–$10 price range.

For hobbyists this is great news — cheap commercial products running open-source Linux are everywhere. But most of these devices are headless, with no keyboard or display, and lack GPIO, I2C, or UART interfaces needed for sensors, motors, and controls.

To bridge the gap between an off-the-shelf Linux box and the missing I/O interface, I built OpenUI — a USB device using Atmel's ATtiny2313 as a USB HID device. Since most Linux boxes have a USB port, an OpenUI add-on makes sense for anyone planning to use cheap Linux boxes for embedded projects.

Features

  • IR remote receiver — acts as a user input device (keyboard)
  • 16x2 LCD — acts as a user output device (display)
  • I2C bus interface — for connecting peripheral chips
  • I2C RTC chip — real-time clock with battery backup
  • 5x2 male header — for AVR programming or extending the I2C bus
  • 5V power — drawn from the host USB connector

Hardware design is based on Dick Streefland's usbtiny project. The only limitation of usbtiny is a missing I2C bus — OpenUI extends the design with an all-in-one solution for headless Linux boxes.

Building the ATtiny2313 firmware

Step 1 — Install the AVR toolchain:

sudo apt-get install gcc-avr binutils-avr avr-libc avrdude

Step 2 — Prepare a cheap AVR programmer (ponyser) from here.

Step 3 — Download Dick Streefland's usbtiny-1.6 sources and the OpenUI patch.

Step 4 — Build and flash:

mkdir openUI
cd openUI
cp /path/to/downloaded/usbtiny-1.6.tar.gz .
cp /path/to/downloaded/usbtiny-1.6.openui-0.1.diff .
tar -xvf usbtiny-1.6.tar.gz
cd usbtiny-1.6
patch -p1 < ../usbtiny-1.6.openui-0.1.diff
make clean
make all
cd ir
avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U flash:w:main.hex
avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U hfuse:w:0xdb:m
avrdude -p attiny2313 -P /dev/ttyUSB0 -c ponyser -U lfuse:w:0xef:m

Your ATtiny2313 is now ready to run on the OpenUI hardware.

Preparing the headless Linux box

  1. Build lircd along with lirc_dev.ko and lirc_igorplugusb.ko for your Linux box.
  2. Load the kernel modules before starting lircd.
  3. Verify /dev/lirc device node exists.
  4. Verify /var/run/lirc folder exists.
  5. Start lircd:
/usr/sbin/lircd --device=/dev/lirc /etc/lirc/lircd.conf
  1. Start the OpenUI daemon:
/path/to/openui &

If everything goes well, you'll see a message on the OpenUI's LCD.

Hardware photos

OpenUI board top view

OpenUI board — top view showing the ATtiny2313, IR receiver, and I2C header.

OpenUI board with LCD

OpenUI with 16x2 LCD display mounted.

OpenUI board close-up

Close-up of the OpenUI board.

OpenUI connected to router

OpenUI plugged into a router's USB port — the complete setup.

See OpenUI in action in the companion blog post.