Categories
DIY Projects

USB HID Footswitch

I put together a handy, super rugged, USB HID footswitch using off-the-shelf components!


Sometimes you just want a thing that works after an hour or so of mucking about. This turned out to be just such a project. I wanted to see what CircuitPython was about and I needed a USB HID footswitch for another project so I choose this to play with since its a simple and low stakes task. I use this footswitch in combination with VoIP software to control PTT. The code currently is set up to send an extended function key (F20) as to not interfere with other shortcuts/applications on the operating system. The particular version of the footswitch I used has a momentary SPST switch.


Note: U2F bootloader/CircuitPython presents the microcontroller to the operating system as a storage device. It’s best to turn off hotplug storage device notifications in Windows; it will get annoying if you don’t. If this is the only thing you ever do with CircuitPython, it’ll probably be fine. I however found it to be extremely irritating when prototyping a later project.

The connections are pretty simple. What is being detected is a digital pin being shorted to ground when the normally-open contact of the switch is closed. You connect one side of the SPST switch to the board pin you have set up in the code and the other side of the switch is connected to a broken out ground pin. Click on the picture and zoom in if you want to have a look. I use Kester 44 RA solder so you’ll see some flux residue on the board. Kester says not to clean it so I don’t. I was playing with the board prior to installing it and soldered and desoldered a few pins in the process. The residue looks gross but it doesn’t bother me unless I look at it. hihi

I slipped the bottom half of the anti-static bag the microcontroller came in over the board to protect it from potential shorts. The board is in there pretty snug as there really isn’t a whole lot of room in this configuration. More stuff could definitely be fit inside if the USB-C connector was lopped off and the conductors were soldered directly to the board. I may make a BLE version of this footswitch but I think it would probably need an external antenna to get out more than a couple of feet as the body and bottom plate are cast-iron.

I’ve been very happy with the pedal other than a race condition on startup in windows which was fixed with a simple delay in the code. If you turn on your computer and the pedal doesn’t work, try playing with the startup delay. It’s a massive heavy footswitch and has a nice anti-slip pad attached to the cast-iron bottom half that covers the internals; what’s more to say?

Parts:

Software:

Code:

# CTAND v0.1 7/12/22
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
# Delay to prevent race condition on PC startup
time.sleep(15)
kbd = Keyboard(usb_hid.devices)
ptt = digitalio.DigitalInOut(board.MOSI)
ptt.direction = digitalio.Direction.INPUT
ptt.pull = digitalio.Pull.UP
while True:
    if ptt.value:
        # Release key on switch release
        kbd.release_all()
    else:
        # Hold key down on switch press
        kbd.press(Keycode.F20)
    # Debounce delay
    time.sleep(0.01)

73,

N6CTA