# Wiring a momentary button to USB

Please forgive my lack of knowledge as all of this is VERY new to me... old dogs and new tricks and all ;)

I want to wire a usb cable to a simple momentary button to use as a push-to-talk button. I've done some LIGHT FIT stuff; built button boxes with zero latency boards and such, but I'm not sure how to find this answer. Heck, I'm not really sure how to search the question.

The button is 2 prong of course. I don't want to utilize a board (learning arduino now, but there's no room for a board in th his project) if it can be avoided, but would rather just have the button connected to the cable and plug it in to have Windows recognize it as a button.

Can I simply wire this button to a usb cable? If so, what fills the remaining 2 positions on the USB connector (data pins I believe) if anything? I don't want to blow up my newly built pc ;)

Thanks in advance for entertaining my ignorance.

• A simple image search for usb+button gives a load of results. Hack one of those to suit your needs. – Transistor Dec 19 '17 at 23:01
• One of the easiest ways would be to wire the button to the Velleman K8055 USB experimental interface board. – Brian Drummond Dec 19 '17 at 23:33
• It would be easier to wire it inline with the microphone, then you don't have to write a driver. – Ron Beyer Dec 20 '17 at 2:40
• use the guts from a usb keyboard ... get one that has a programmable hotkey .... or a used usb joystick .... make sure it works with your application before disassembling it – jsotola Dec 20 '17 at 5:29
• Every USB keyboard wires buttons to USB, as do the little lecture-slide-control-laser-pointer gadgets (wireless, most of 'em). 'Shift' is an innocuous choice. – Whit3rd Dec 20 '17 at 10:14

Cheapest and simplest solution I know of is to find an old USB PC keyboard.

Extract the small circuit board from it.

Run xev on your Linux machine to find which two contacts you have to short together on the board to get some character as an output. You can also trace out the patterns on the keyboard membrane to do this.

Then buy any momentary button and connect it to the two contacts you found.

This way I have PageUp/PageDown footswitches for my notes, when I play piano.

Unfortunately, you cannot wire a button directly to a USB cable. This will not work. You'll need an MCU to monitor your button, and communicate over USB. Using something like an ATmega32u4 that has a USB transceiver built-in would work. Give this sparkfun tutorial a read.

Note that you aren't limited to using the sparkfun board. I chose that tutorial because it is Arduino-compatible. You could use a different MCU that has a USB transceiver.

I would also research the difference between a virtual COM port over USB (which provides a serial link between your MCU and the PC), and USB configured as a HID (Human Interface Device). For your application, I imagine that you would like to emulate a keyboard (HID).

• Yeah... I've used the nano and uno in other button/potentiometer related DIY projects. Problem is that with this one there is nowhere to put a board in the system. I've got a pic of what I'm doing... but can't figure out how to post it here in the comments... I'd live someone to tell me where the board is in the pic! – Darksider72 Dec 19 '17 at 23:21
• Can you post a link to the photo? – Daniel Dec 19 '17 at 23:22
• Keep in mind that MOST of the black you see at the button is a Velcro loop fastener .... cdn3.volusion.com/nzfzp.aykwu/v/vspfiles/photos/… – Darksider72 Dec 19 '17 at 23:29
• There is definitely enough room for a small PCB, just not a full development board. – Daniel Dec 20 '17 at 3:40
• So you think there is a board in there? It's like 1" long x .5"... that'd be a tiny little board. I think I may be out of my depth here... that's discouraging lol. I'll just have to find an electronics guru like you guys that I can hire to figure this one out for me lol. I'm not near far enough along in my experience with this I don't think. – Darksider72 Dec 20 '17 at 6:23

No, USB does not support simply connecting a switch across pins. USB uses a complex comminication protocol that requires a chip.

That said, you could accomplish a simple contact detection using an FTDIchip.com FT232 chip in gpio bitbang mode; these are widely available and have decent software support. But there's no way to just detect a simple switch closure without any additional circuitry. I've read the usb.org specs. It's not at all like the old parallel printer ports.

I want to wire a usb cable to a simple momentary button to use as a push-to-talk button.

USB has a standard that includes PTT, it's called "HID Telephony"

For that you'll probably have to program a USB microcontroller, or pull apart an existing telephony device and us its circuit.

There is one simple way to manage one button on a USB port without full-blown device with full USB protocol. All you need is to pull D+ wire to 3.3V via a 1.5k resistor with your button. You can get 3.3V from VBUS (red wire) with some limit of a 3.3 - 3.6 V Zener diode. This will generate a "connect" event on USB port, and the system will try to figure out what is connected. Then it will fail to get any descriptors, and pop-up a failure message.

Then you need to find a way to intercept this Windows message that says something like "device not recognized" (I believe VBA scripts have means to do so). And trigger your application from there.

ADDENDUM: The above was a really wild idea. In cases like the OP, I usually recommend the multi-functional MCP2221 chip (UART/I2C bridge), which also has few GPIOs, and even ADC/DAC, all with libraries on host side to manage the pins. The entire USB device can fit into 10 x 10 mm area, and can be placed entirely into USB connector overmold. It is not blazing fast and libraries might be not in Visual Studio 2017 format, but anyway.

• interesting idea, but it would be too laggy for a push-to-talk application – jsotola Dec 20 '17 at 5:43
• @jsotola, upon sensing the low-to-high transition on D+, the host controller generates an interrupt almost immediately. Only then it allows 100-200 ms of de-bouncing delay before initiating USB_RESET and attempting to enumerate the port, three-four times. Yes, the final message is laggy, but if you can intercept/hack the ehci.sys interrupt handler, then it will be pretty fast. You likely can hack Linux/Android kernel for that, if you can... – Ale..chenski Dec 20 '17 at 7:00
• This sounds like a lot of extra work for something that wouldn't be portable between machines... – Daniel Dec 23 '17 at 18:19
• @DanielGiesbrecht, extra work compared with what? With making a full-blown hardware? And own driver? Connect event is the same across ALL USB systems. If you manage to intercept this event at some "filter driver" level, it will be very-very portable. – Ale..chenski Dec 23 '17 at 22:36