Overview
In this project we're making a USB foot switch with CircuitPython!
We were inspired to make a new foot switch which could be really nice for young folks and even animals.
For tasks that require both hands, we think using feet can help complete tasks much quicker!
We designed and 3d printed a three button foot pedal that snap fits together.
This project can be powered by either an Adafruit QT Py RP2040 or the KB2040.
CircuitPython makes USB HID project really easy to put together.
You can customize the key codes and set up different keyboard shortcuts or media controls like play/pause and volume.
You can 3D print the parts without any support material using your favorite filament.
The bottom features mounting holes to use M3 hardware to secure the switches and brackets.
The case is compatible with the QTPy or KB2040 board. We used the QTPy in this build.
Boards press fit into a mount that can then attach to the case.
Top covers can then be installed to the built-in hinges on the base. Theres nubbin's on the sides that are press fitted into the dimples on the hinges.
The micro-switch features a bump actuator so it works nicely without the need of an additional spring!
Prerequisite Guides
If your new to electronics and soldering, I suggest walking through the following guides to get the basics. The Adafruit Excellent guide to soldering will walk you through process of learning how to use a soldering iron to make solid electrical connections.
Page last edited May 13, 2024
Text editor powered by tinymce.
Circuit Diagram
This provides a visual reference for wiring of the components. They aren't true to scale, just meant to be used as reference. Generic micro switches follow a standard pin out with visible markings on the body of the switch. Here's each label markings:
- (C1) – "common ground".
- (NO2) – "normally open".
- (NC3) – "normally closed".
Page last edited May 13, 2024
Text editor powered by tinymce.
CircuitPython
CircuitPython is a derivative of MicroPython designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the CIRCUITPY drive to iterate.
CircuitPython Quickstart
Follow this step-by-step to quickly get CircuitPython running on your board.
Click the link above to download the latest CircuitPython UF2 file.
Save it wherever is convenient for you.
To enter the bootloader, hold down the BOOT/BOOTSEL button (highlighted in red above), and while continuing to hold it (don't let go!), press and release the reset button (highlighted in red or blue above). Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!
If the drive does not appear, release all the buttons, and then repeat the process above.
You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.
A lot of people end up using charge-only USB cables and it is very frustrating! Make sure you have a USB cable you know is good for data sync.
You will see a new disk drive appear called RPI-RP2.
Drag the adafruit_circuitpython_etc.uf2 file to RPI-RP2.
The RPI-RP2 drive will disappear and a new disk drive called CIRCUITPY will appear.
That's it, you're done! :)
Safe Mode
You want to edit your code.py or modify the files on your CIRCUITPY drive, but find that you can't. Perhaps your board has gotten into a state where CIRCUITPY is read-only. You may have turned off the CIRCUITPY drive altogether. Whatever the reason, safe mode can help.
Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode bypasses any code in boot.py (where you can set CIRCUITPY read-only or turn it off completely). Second, it does not run the code in code.py. And finally, it does not automatically soft-reload when data is written to the CIRCUITPY drive.
Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the CIRCUITPY drive.
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)
In Safe Mode
If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.
If you connect to the serial console, you'll find the following message.
Auto-reload is off. Running in safe mode! Not running saved code. CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode. Press any key to enter the REPL. Use CTRL-D to reload.
You can now edit the contents of the CIRCUITPY drive. Remember, your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode.
Flash Resetting UF2
If your board ever gets into a really weird state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. You will lose all the files on the board, but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.
Page last edited May 13, 2024
Text editor powered by tinymce.
Code
Once you've installed the latest version of CircuitPython onto your board, you'll need to grab the code, libraries and any assets included with the project.
Click the download project bundle button below to get the code, libraries and assets all in one!
# SPDX-FileCopyrightText: 2022 Ruiz Bros for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import digitalio
import board
import usb_hid
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
# The button pins we'll use, each will have an internal pullup
buttonpins = [board.A1, board.A2, board.A3]
# The keycode sent for each button, will be paired with a control key
buttonkeys = [
ConsumerControlCode.PLAY_PAUSE, # Center Foot Pad
ConsumerControlCode.VOLUME_DECREMENT, #Left Foot Pad
ConsumerControlCode.VOLUME_INCREMENT, # Right Foot Pad
]
# the keyboard object!
cc = ConsumerControl(usb_hid.devices)
# our array of button objects
buttons = []
# make all pin objects, make them inputs w/pullups
for pin in buttonpins:
button = digitalio.DigitalInOut(pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
buttons.append(button)
print("Waiting for button presses")
while True:
# check each button
for button in buttons:
if not button.value: # pressed?
i = buttons.index(button)
print("Button #%d Pressed" % i)
while not button.value:
pass # wait for it to be released!
# type the keycode!
k = buttonkeys[i] # get the corresp. keycode
cc.send(k)
time.sleep(0.01)
Upload Code, Libraries and Assets
Unzip the project bundle and upload the files to the CIRCUITPY drive.
Your CIRCUITPY drive should look like this after you've uploaded the code, libraries and assets.
Check out the guides linked below for more information on using the USB-HID library for CircuitPython.
Modify Controls
The three switches are assigned the consumer controls for play/pause volume up, and volume down. Adjust the following code to change the keys control or the order of the arrangement. The buttonpins and buttonkeys are ordered chronologically.
# The button pins we'll use, each will have an internal pullup
buttonpins = [board.A1, board.A2, board.A3]
# The keycode sent for each button, will be paired with a control key
buttonkeys = [
ConsumerControlCode.PLAY_PAUSE,
ConsumerControlCode.VOLUME_INCREMENT,
ConsumerControlCode.VOLUME_DECREMENT
]
Page last edited May 13, 2024
Text editor powered by tinymce.
3D Printing
Parts List
STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material. Original design source may be downloaded using the links below.
Slice with settings for PLA material.
The parts were sliced using CURA using the slice settings below.
- PLA filament 220c extruder
- 0.2 layer height
- 10% gyroid infill
- 60mm/s print speed
- 60c heated bed
Page last edited May 13, 2024
Text editor powered by tinymce.
Assemble
Assemble switch brackets
M3 x 16mm long screws are used to attach the micro switches to the printed brackets.
Mount switch brackets
Brackets are mounted to the base with M3 x 5mm long screws.
Connect the arcade quick connect wires before mounting to the base.
Solder board
Wires are soldered to the pins on the micro-controller.
The board is inserted into the PCB mount at an angle with the corners fitting under these clips.
The mount is then secured to the main base using hardware screws with all of the connections made.
Mount board
The board mount attaches to the base with two M3x5mm long screws.
Panel Mount 1/8" / 3.5mm TRS Audio Jack Connector fit next to the USB port on the case.
Attach lid
The top covers can then be installed to the built-in hinges on the base.
Theres nubbin's on the sides that are press fitted into the dimples on the hinges.
The micro-switch features a bump actuator so it works nicely without the need of an additional spring.
Complete!
Additional rubber feet make it grip to any hard surface and they just stick to the bottom of the case.
This project uses code from the Lemon KeyPad: https://learn.adafruit.com/qtpy-lemon-mechanical-keypad-macropad/code
We hope this inspires you to try out CircuitPython for your next USB controller project.
Page last edited May 13, 2024
Text editor powered by tinymce.