TouchNav is a minimalist USB HID touch controller built using a custom SAMD21 board.It lets you control Spotify playback - play/pause, next/previous track, and volume using capacitive touch pads and a rotary encoder.
The goal was to build a sleek, touch-based interface that feels futuristic yet practical, allowing intuitive control of Spotify directly from your desk without touching your keyboard or mouse.
- Capacitive touch pads for Play/Pause, Next, and Previous
- Rotary encoder for Volume control
- HID-based media key emulation (no software needed on PC)
- Automatic Spotify open/close via keyboard shortcuts
- Works as a plug-and-play USB device
- Built on a custom SAMD21 board
At its core, TouchNav is built around a custom SAMD21 board designed for Fab Academy. The SAMD21E17A chip provides full-speed USB capability, which allows it to act as a HID (Human Interface Device) similar to a keyboard or mouse.
Atmel SAMD21E17AThe Atmel SAMD21E17A is a powerful yet compact ARM Cortex-M0+ based microcontroller running at up to 48 MHz. It’s the same family of chips used in the Arduino Zero and many modern development boards, making it ideal for USB-connected, low-power, and interactive projects like TouchNav.
- Processor: 32-bit ARM Cortex-M0+ core, running up to 48 MHz
- Memory: 128 KB Flash and 16 KB SRAM (for program and data storage)
- USB Support: Full-speed USB 2.0 interface, allowing native USB HID, keyboard, and serial functionality
Peripherals:
- Up to 6 configurable serial interfaces (SERCOM) — usable as UART, SPI, or I²C
- 12-bit ADC (Analog-to-Digital Converter) for reading sensors and touch inputs
- 10-bit DAC for analog output
- Timer/Counters (TC/TCC) for PWM, event timing, or signal generation
- Peripheral Touch Controller (PTC) for capacitive touch sensing
- Power Management: Low-power modes, SleepWalking peripherals, and brown-out detection.
- Debugging: Two-pin SWD (Serial Wire Debug) for programming and debugging
- Operating Voltage: 3.3 V logic
- I/O Pins: Up to 32 available GPIO pins (depending on package)
The SAMD21E17A’s native USB capability makes it ideal for projects that emulate keyboards, mice, or multimedia controllers - without extra hardware.Its touch sensing support and multiple serial interfaces also make it perfect for integrating sensors, LEDs, and rotary encoders.
The main input components include:
- Capacitive Touch Pads: Three metal or copper pads act as touch sensors. Each pad is assigned a function — Play/Pause, Next Track, and Previous Track.
- Rotary Encoder: A small knob used to increase or decrease system volume. It also includes an optional push button.
- Micro USB Interface: For both power and data, allowing the board to function as a USB HID device.
The capacitive touch pads are connected to the analog-capable pins on the SAMD21. The rotary encoder is connected to two digital pins configured to detect state transitions for clockwise and counter-clockwise rotation.
PCB Design - KiCADThe entire board was custom-designed in KiCad, an open-source PCB design tool. The schematic, layout, and pin mappings were tailored to fit the SAMD21E17A’s capabilities integrating touch pads, a rotary encoder, WS2812B LEDs, and USB connectivity in a compact, minimal design.
This allowed full control over the hardware design from component placement to routing USB differential pairs making TouchNav a purpose-built, professional-grade HID controller rather than a generic development board hack.
The pinouts are as follows:
- LED - 7
- WS2812B - 11
- Rotary Encoder - A - 9, B - 8, Switch - 10
- Capacitive Touch Slider - GPIO 2, 3, 4, 5, 6
The TouchNav Board has a SAMD21 E17 at its core, so to program the SAMD21 we need to add the bootloader to the board. To flash the bootloader initially, we need the Serial Debug Pins. Only after that can we program the board using USB.
The Serial Debug inerface is used to burn the bootloader onto the board. I am using a SAMD DAP Programmer Board developed by my Fab Academy Instructor Saheen
Adding the FAB SAMD Board to Arduino
To program the SAMD21 Board using Arduino IDE, we need to add the FAB SAMD Board to the Board Manager
To install, simply add the following URL to "Additional Boards Manager URLs" in the Arduino IDE: https://raw.githubusercontent.com/qbolsee/ArduinoCore-fab-sam/master/json/package_Fab_SAM_index.json
Install the board using the Board Manager
After burning the bootloader, I can program my board using the type C USB Interface.
BlinkAfter burning the bootloader the first step was to test the builtin example 'Blink'Initially I tested all my input and output functionalities by using some example codes.
SAMD21 Serial DemoThe next test was serial communication. After research, I realised the usual arduino command Serial.print doesn't work for the SAMD21, therefore we have to use SerialUSB.print. The below code is taken from my Fab Academy Embedded Programming class. SAMD21 Echo Code
Capacitive TouchThe Capcitive touch can be tested by using the test code provided by Professor Neil in the Fab Academy Input Devices Class. The required library for this is Adafruit FreeTouch library.
HIDI used the HID Project and HID Settings Library which is available in the Library Manager of Arduino by default. We just have to install it to use the library from the library manager. The main function that I used was the Consumer function whih allows to control Media Playback and some functions. There are two things happening mainly: Control the Media Playback and opening and closing Spotify on the Windows Device.
To control the Media Playback, the consumer function provides with functions like:
// Media key definitions, see official USB docs for more
#define MEDIA_FAST_FORWARD 0xB3
#define MEDIA_REWIND 0xB4
#define MEDIA_NEXT 0xB5
#define MEDIA_PREVIOUS 0xB6
#define MEDIA_STOP 0xB7
#define MEDIA_PLAY_PAUSE 0xCD
#define MEDIA_VOLUME_MUTE 0xE2
#define MEDIA_VOLUME_UP 0xE9
#define MEDIA_VOLUME_DOWN 0xEA
#define CONSUMER_EMAIL_READER 0x18A
#define CONSUMER_CALCULATOR 0x192
#define CONSUMER_EXPLORER 0x194
#define CONSUMER_BROWSER_HOME 0x223
#define CONSUMER_BROWSER_BACK 0x224
#define CONSUMER_BROWSER_FORWARD 0x225
#define CONSUMER_BROWSER_REFRESH 0x227
#define CONSUMER_BROWSER_BOOKMARKS 0x22A
Issues facedWhile programming the SAMD21, I faced an issue with the USB C connection. The board was not being detected by the computer. After some debugging, Irealised that the USB C Cable was an issue, I had to use another USB Cable and an additional USB Hub. I think it might be an powering issue. And the PCB Design Flaws
The rotary encoder was not very accurate, as it as not reading values when I was turning the knob faster. I think I need to add capacitors to the rotary encoder pins.
Comments