A 1- or 2-switch Bluetooth HID keyboard for the Seeed XIAO nRF52840 (Sense). Each switch sends a configurable key (space, enter, arrows, letters, etc.) over Bluetooth to a phone, tablet, or computer. It pairs as a standard keyboard, so no host software or drivers are needed.
Runs on CircuitPython. The firmware uses only built-in modules (_bleio, alarm), so no external libraries are required.
- Board: Seeed XIAO nRF52840 (or Sense)
- Switch 1: wired between D10 and GND
- Switch 2: wired between D9 and GND
- No external resistors; the firmware enables the internal pull-ups
- Switches are active-low (idle HIGH, pressed LOW)
- Trigger on the leading edge (the keystroke fires on press-down)
- Powered via USB or a LiPo battery on the BAT pads
- Tap a switch -> sends its key (key-down on press, key-up on release)
- Pressing two switches at once sends both keys (chords work)
- Hold either switch for 3 seconds -> deep sleep (Bluetooth off, very low power)
- Press any switch -> wakes the board and re-advertises (the board reboots on wake)
- A short hold still sends one keystroke before sleeping
- CircuitPython is a version of Python that runs directly on the board. You do not need to install Python on your computer.
- When you plug the board in over USB, it shows up as a small USB drive called
CIRCUITPY. - To change what the board does, edit the file
code.pyon that drive. A few seconds after you save, the board restarts and runs the new code automatically. There is no compiler and no upload step. - The very first time, you have to install CircuitPython itself onto the board once (see below). After that, changing the code is just editing a file.
- None. This project uses only modules that are built into CircuitPython:
board,digitalio,_bleio,alarm, plus the standardstructandtime. - Many CircuitPython projects need extra libraries (downloaded from the Adafruit CircuitPython Bundle and copied into a
lib/folder onCIRCUITPY). This one does not, so there is nolib/step and no bundle to download. - The only requirement is the CircuitPython runtime itself, which you install once (next section). Use the Seeed build for the XIAO nRF52840; a generic build will be missing
_bleio.
- Put the board in bootloader mode: double-tap the reset pads (the reset button is not used on this board).
- A drive named
XIAO-SENSEappears. Copy the SeeedXIAO-CircuitPython.uf2onto it (download it from the Seeed XIAO BLE wiki, CircuitPython section). The board reboots into CircuitPython and aCIRCUITPYdrive appears. - Copy
code.pyfrom this repo onto theCIRCUITPYdrive, overwriting the defaultcode.py.
- Plug the board into the computer over USB.
- The
CIRCUITPYdrive mounts. - Copy
code.pyfrom this repo ontoCIRCUITPY(overwrite the existing one). - CircuitPython auto-reruns the file within a couple of seconds. No compile step, no flash tool.
- Open Bluetooth settings on the phone/tablet/computer.
- Pair with Simple Switch (Just Works, no PIN).
Edit the SWITCHES list at the top of code.py. Each entry sets a pin and the HID keycode it sends. Common keycodes:
0x2CSpace,0x28Enter,0x2BTab,0x29Escape,0x2ABackspace0x52Up,0x51Down,0x4FRight,0x50Left0x04-0x1Dletters a-z,0x1E-0x27numbers 1-9 then 0
To add a third switch, append an entry with a free pin (for example board.D8) wired to GND.
Run monitor.py to view switch events and status over USB serial:
python3 monitor.py
code.py- the firmware; copy onto theCIRCUITPYdrivemonitor.py- USB serial monitor for debugging