Skip to content

AACTools/simple-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Simple Switch

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.

Hardware

  • 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

How it behaves

  • 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

New to CircuitPython?

  • 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.py on 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.

Dependencies

  • None. This project uses only modules that are built into CircuitPython: board, digitalio, _bleio, alarm, plus the standard struct and time.
  • Many CircuitPython projects need extra libraries (downloaded from the Adafruit CircuitPython Bundle and copied into a lib/ folder on CIRCUITPY). This one does not, so there is no lib/ 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.

One-time setup (CircuitPython)

  1. Put the board in bootloader mode: double-tap the reset pads (the reset button is not used on this board).
  2. A drive named XIAO-SENSE appears. Copy the Seeed XIAO-CircuitPython.uf2 onto it (download it from the Seeed XIAO BLE wiki, CircuitPython section). The board reboots into CircuitPython and a CIRCUITPY drive appears.
  3. Copy code.py from this repo onto the CIRCUITPY drive, overwriting the default code.py.

How to push code changes to the board

  1. Plug the board into the computer over USB.
  2. The CIRCUITPY drive mounts.
  3. Copy code.py from this repo onto CIRCUITPY (overwrite the existing one).
  4. CircuitPython auto-reruns the file within a couple of seconds. No compile step, no flash tool.

Pairing

  • Open Bluetooth settings on the phone/tablet/computer.
  • Pair with Simple Switch (Just Works, no PIN).

Changing the keys

Edit the SWITCHES list at the top of code.py. Each entry sets a pin and the HID keycode it sends. Common keycodes:

  • 0x2C Space, 0x28 Enter, 0x2B Tab, 0x29 Escape, 0x2A Backspace
  • 0x52 Up, 0x51 Down, 0x4F Right, 0x50 Left
  • 0x04-0x1D letters a-z, 0x1E-0x27 numbers 1-9 then 0

To add a third switch, append an entry with a free pin (for example board.D8) wired to GND.

Serial monitor (debugging)

Run monitor.py to view switch events and status over USB serial:

python3 monitor.py

Files

  • code.py - the firmware; copy onto the CIRCUITPY drive
  • monitor.py - USB serial monitor for debugging

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages