I was looking for a button to trigger a software release @ my work in a semi-dramatic fashion. So, I 3D-printed this red button enclosure for a switch I had and attached it to a microcontroller to use as an enter key for my computer.
With a terminal command queued up to initiate the deployment, all that’s left is to push the red button!1
Parts List
- A KE-011 switch2 These can be a bit expensive/hard to come by for what it is. I had bought these when I came across them a few years ago and was waiting for a project like this.
- Adafruit QT-PY - The main constraint is you choose a version with native USB, like the one noted. This can be replaced by any microcontroller that follows the footprint of a Seeed Xiao.
- A printed version of the STL file from: this page
- Some length of stranded copper wire
- A few inches of kapton tape for insulating the microcontroller.
- Four M3x8 screws
Assembly Notes
- I soldered two wires to the microcontroller and configured it as a digital input
- I then wrapped it in kapton tape to ensure that it fit snugly and that no metal from the button could contact it
- The microcontroller lays face down in the case with the USB-C connector sticking outside the slot. The wires slide into the two channels and are connected to the terminals on the button.
CircuitPython Code
import time
import board
from digitalio import DigitalInOut, Direction, Pull
import usb_hid
import time
# NOTE: need to add adafruit_hid from circuitpython bundle
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
# Initialize Keyboard
kbd = Keyboard(usb_hid.devices)
btn = DigitalInOut(board.A1)
btn.direction = Direction.INPUT
btn.pull = Pull.UP
was_down = False
while True:
if not btn.value:
if not was_down:
was_down = True
kbd.press(Keycode.ENTER)
print("BTN is down")
else:
if was_down:
kbd.release(Keycode.ENTER)
was_down = False
pass
time.sleep(0.1) # sleep for debounce
Additional Notes
I may design a fully 3d-printable version of this button, due to the lack of supply of real ones.
Footnotes
-
I used the button to release this blog post! ↩
-
Rumor has it, this is the type of button which triggered the Chernobyl accident in 1986 https://www.reddit.com/r/chernobyl/comments/l0iz44/it_was_mentioned_on_here_that_the_az5_button_was/ ↩