
Macropad - Seeed Xiao RP2040 - 1 phím
- Downloads
- 186
- Likes
- 23
- Views
- 2,347
- Remixes
- 1
- Comments
- 0
Files 7 4.4 MB
- Seed_Xiao_RP2040_-_Macropad_-_One_Key_1767416214.stlSTL · 322.5 KB
- Seed_Xiao_RP2040_-_Macropad_-_One_Key_-_Top_only_1767416215.stlSTL · 282.5 KB
- Seed_Xiao_RP2040_-_Macropad_-_One_Key_-_Bottom_only_1767416216.stlSTL · 40.1 KB
- Seed_Xiao_RP2040_-_Macropad_-_One_Key_-_Top3Colors_-_0.25n_-_0.10mm_1767416217.3mf3MF · 81.9 KB
Make a variant with AI
Build another version of this model.
Remix versions 1
See all 1 remixDetails
- Model ID
- #190517
- Category
- Dụng Cụ Tiện Ích
- Published
- License
- Creative Commons — Attribution
Description
Features:
- Designed for Cherry MX compatible switches.
- LED Window to leverage the built-in RP2040 neopixel RGB LED.
- No screws!
- Mechanical peg holders for the RP2040.
- Snap cover.
- USB port access hole on the back of the macropad.
- Cute and small footprint, just 1 key!
- Just 2 wires to solder!
Keycaps
Productivity
Coming soon!
Various (48+)
https://www.printables.com/model/414597-cherry-mx-keycap-various-icons-50
Dices
https://www.printables.com/model/414603-cherry-mx-keycap-dices
Playing cards
https://www.printables.com/model/414613-cherry-mx-keycap-playing-cards
Blank
https://www.printables.com/model/397305-cherry-mx-keycap-blank
Overview
Microcontroller:
I built the macropad using a Seeed Studio Xiao RP2040 microcontroller (MCU) board. It is a 10$ (Canadian) board available on Amazon. I won’t go into the detailed specifications of the board but it is built around a dual-core RP2040 Raspberry PI processor. It can run Arduino, MicroPython, and CircuitPython. For this project, I opted to use CircuitPython and I am using 1 digital IO pin, the built-in neopixel RGB led, and the USB C port.
Wiring:
Keyboards and macropads are typically wired in a matrix of rows and columns interconnected using diodes. Each of the rows and columns are then connected to a digital IO on the MCU which allows to have more keys than digital IOs. As an example, if you wire a matrix of 5 rows and 6 columns, you can have 30 keys with just 11 digital IOs. I did not want to use diodes so I connected the switch directly to the MCU. QMK (not a typo, this is another popular keyboard firmware) has a very good hand wiring guide here.
In my case, one pin from the switch is connected to IO pin D0 on the MCU. I am using internal pull up resistors so no need for external resistors either. The other switch pin is connected to the ground pin on the MCU.
Macropad firmware (the code):
For the keyboard code, rather than reinventing the wheel, I used KMK, a keyboard focused layer that runs on top of CircuitPython. It is pretty well documented for matrix wiring with diodes but not so much for direct connections like I did so I'll share some code to help you get started if you go that route too.
When you connect the board, it starts by running _boot.py_ and then _code.py_. _boot.py_ is optional and only needed if you want to hide the USB drive (CIRCUITPY) and serial interface (COM port). I put code in _boot.py_ to mount the USB drive and serial interface when the key connected to D0 is pushed and held while booting but otherwise only the keyboard interface is enabled.
The sample below has macros to open Google, notepad, cmd, powershell, your password (not secure, don't do it!), etc. It can be customized for your own needs. I did not do much yet but KMK allows you to create layers, change the color of the LED based on the layer and tons of other fun stuff. This is a work in progress so I will add more features later. If you come up with something nice, please share it in the comments!
I haven't seen examples using the keypad KeysScanner module so I hope this helps you.
code.py contains the main keyboard code:
#
# <code.py>
# Import modules
# KeysScanner is needed because we use direct switch connections instead
# of a matrix with diodes.
# simple_key_sequence and send_string are used in macros.
# RGB enables using the built-in RP2040 neopixel RGB LED.
# Mediakeys enables assigning things like increasing the volume to keys.
# Layers enables alternate key mapping by layer.
#
import board
from kmk.kmk_keyboard import KMKKeyboard
from kmk.scanners.keypad import KeysScanner
from kmk.keys import KC
from kmk.handlers.sequences import simple_key_sequence
from kmk.handlers.sequences import send_string
from kmk.extensions.RGB import RGB
from kmk.extensions.RGB import AnimationModes
from kmk.extensions.media_keys import MediaKeys
from kmk.modules.layers import Layers as _Layers
from kmk.modules.modtap import ModTap
#
# Print a string to the serial console
#
print("NPQ Macropad")
#
# GPIO to key mapping - We are using all the board digital IOs
#
# Seed Xiao RP2040 pins:
# 'A0', 'A1', 'A2', 'A3'
# 'D0', 'D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10'
# 'I2C', 'MISO', 'MOSI', 'RX', 'SCK', 'SCL', 'SDA', 'SPI', 'TX', 'UART', 'board_id'
# 'LED', 'LED_BLUE', 'LED_GREEN', 'LED_RED', 'NEOPIXEL', 'NEOPIXEL_POWER'
#
_KEY_CFG = [
# 0 - D0
board.D0
]
#
# Our own Keyboard class. We need to do this because we have direct wiring of the switches
# to the MCU instead of the "standard" matrix of columns and rows interconnected with diodes.
#
class MyKeyboard(KMKKeyboard):
def init(self):
# create and register the scanner
self.matrix = KeysScanner(
# require argument:
pins=_KEY_CFG,
# optional arguments with defaults:
value_when_pressed=False,
pull=True,
interval=0.02, # Debounce time in floating point seconds
max_events=64,
)
# Our keyboard object!
keyboard = MyKeyboard()
#
# Neopxiel RGB LED extension - http://kmkfw.io/docs/rgb
#
neopix = RGB(
pixel_pin=board.NEOPIXEL,
num_pixels=1,
hue_default=170, # Blue = 170
sat_default=255, # Blue = 255
val_default=255, # Blue = 255
animation_mode=AnimationModes.BREATHING,
animation_speed=6,
)
#
# Layers
#
# Layer colors
LYR_BLUE, LYR_WHITE, LYR_RED, LYR_GREEN, LYR_PINK, LYR_YELLOW = 0, 1, 2, 3, 4, 5
LAYOR_COLOR = ["BLUE", "WHITE", "RED", "GREEN", "PINK", "YELLOW"]
# Replacing the Layers class with our own to implement
# a LED layer color indicator
class Layers(_Layers):
last_top_layer = 0
# HSV values for each layer
# BLUE WHITE RED GREEN PINK YELLOW
lyr_hue = [ 170, 0, 0, 85, 213, 42, ]
lyr_sat = [ 255, 0, 255, 255, 255, 255, ]
lyr_val = [ 255, 255, 255, 255, 255, 255, ]
# Handles the LED color change when a layer is changed
def after_hid_send(self, keyboard):
if keyboard.active_layers[0] != self.last_top_layer:
self.last_top_layer = keyboard.active_layers[0]
neopix.hue = self.lyr_hue[self.last_top_layer]
neopix.sat = self.lyr_sat[self.last_top_layer]
neopix.val = self.lyr_val[self.last_top_layer]
# I used the serial console for debugging
# print(LAYOR_COLOR[self.last_top_layer])
# print(keyboard.active_layers)
# modtap
# optional: set a custom tap timeout in ms
# modtap.tap_time = 300
modtap = ModTap()
#
# Append extensions
#
keyboard.extensions.append(neopix)
keyboard.extensions.append(MediaKeys())
keyboard.modules.append(Layers())
keyboard.modules.append(modtap)
#
# Macros - Can be assigned to keys
#
# My keyboard layout is Canadian French so some keys did not work well for me.
# The backslash and slash were problematic. I resolved the issue of the slash
# (gives me é) by using the keycode from the numeric pad. For the backslash,
# I haven't found a KC that will work on all layouts so this will need to be
# adjusted in the macros...
#
# On Canadian French keyboard:
# \ = KC.RALT(KC.GRAVE) # KC.BSLASH give "é" on a Canadian French keyboard
# / = KC.LSFT(KC.N3) # KC.SLASH gives "<" on a Canadian French keyboard
#
# On a US keyboard:
# \ = KC.BSLASH
# / = KC.SLASH
#
# This one works on both:
# / = KC.KP_SLASH
#
# This is a sample of what you can do but there is more... Look at the KMK
# documentation to see what is possible.
#
# Notepad
NOTEPAD = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("notepad.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Calculator
CALC = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("calc.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Command prompt
CMD = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("cmd.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Windows PowerShell
WPOWERSHELL = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("powershell.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Windows PowerShell ISE
WPOWERSHELLISE = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("powershell_ise.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# PowerShell 7
POWERSHELL7 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("pwsh.exe"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Certificate manager - Local Machine
CERTLM = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("mmc.exe CERTLM.MSC"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Certificate manager - Current User
CERTMGR = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("mmc.exe CERTMGR.MSC"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# Opens Google in a new tab in the default browser
GOOGLE = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("https:"),
#KC.LSFT(KC.N3), # / on a Canadian french keyboard
#KC.LSFT(KC.N3), # / on a Canadian french keyboard
KC.KP_SLASH, # / on Canadian French and US layout!
KC.KP_SLASH, # / on Canadian French and US layout!
send_string("www.google.com"),
KC.ENTER,
KC.MACRO_SLEEP_MS(250),
)
)
# MS Word (32bit)
# C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE
MSWORD32 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files (x86)"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("WINWORD.EXE"),
KC.ENTER,
)
)
# MS Excel (32bit)
# C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE
EXCEL32 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files (x86)"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("EXCEL.EXE"),
KC.ENTER,
)
)
# MS Outlook (32bit)
# C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE
OUTLOOK32 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files (x86)"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("OUTLOOK.EXE"),
KC.ENTER,
)
)
# MS Word (64bit)
# C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE
MSWORD64 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("WINWORD.EXE"),
KC.ENTER,
)
)
# MS Excel (64bit)
# C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE
EXCEL64 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("EXCEL.EXE"),
KC.ENTER,
)
)
# MS Outlook (64bit)
# C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE
OUTLOOK64 = simple_key_sequence(
(
KC.LWIN(KC.R),
KC.MACRO_SLEEP_MS(250),
send_string("C:"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Program Files"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Microsoft Office"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("root"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("Office16"),
KC.RALT(KC.GRAVE), # \ on a Canadian french keyboard
# KC.BSLASH, # \ on a US keyboard
send_string("OUTLOOK.EXE"),
KC.ENTER,
)
)
# I doubt that you will actually use these "color" macros in real life but this
# is what i used for debugging and clarity
# Types: BLUE
BLUE = simple_key_sequence(
(
send_string("BLUE"),
KC.ENTER,
)
)
# Types: WHITE
WHITE = simple_key_sequence(
(
send_string("WHITE"),
KC.ENTER,
)
)
# Types: RED
RED = simple_key_sequence(
(
send_string("RED"),
KC.ENTER,
)
)
# Types: GREEN
GREEN = simple_key_sequence(
(
send_string("GREEN"),
KC.ENTER,
)
)
# Types: PINK
PINK = simple_key_sequence(
(
send_string("PINK"),
KC.ENTER,
)
)
# Types: YELLOW
YELLOW = simple_key_sequence(
(
send_string("YELLOW"),
KC.ENTER,
)
)
# Aliases - looks better in the keymap
_______ = KC.TRANSPARENT # Transparent
XXXXXXX = KC.NO # No key
#
Print spec
- Formats
- 3mfgcodestl
- Model files
- 7
- Total size
- 4.4 MB
- Largest file
- 3.2 MB













