Design Tiny Keyboard for Dev Device

by 陳亮 in Circuits > Arduino

207 Views, 2 Favorites, 0 Comments

Design Tiny Keyboard for Dev Device

IMG_1068.jpeg
MINTIA Keyboard Demo

This instructables show how to build a tiny keyboard for a dev device.

All steps, from circuit design and PCB layout to 3D enclosure design and software development, will be included.

Supplies

Why Build Yourself?

Most tiny keyboard in the market connect with USB or bluetooth, it has many pain points for a dev device.

USB connection:

  1. not all dev devices have USB host interface
  2. it is clumsy for a tiny portable dev device connect 2 parts with a USB cable
  3. hard to hide the USB connection inside a tiny unibody enclosure
  4. consumed the USB host port by the keyboard

Bluetooth connection:

  1. not all dev devices are bluetooth capable
  2. bluetooth connection consume portable device battery power continuously
  3. the bluetooth keyboard also require charging intermittently

In contrast, most dev devices support I2C interface. So keyboard with I2C interface is more suitable for a dev device. However, I2C keyboards are not common in the market. So let's build it yourself!

What Is I2C Interface?

I2C (Inter-Integrated Circuit; pronounced as "eye-squared-see" or "eye-two-see"), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconductors).[1] It is widely used for attaching lower-speed peripheral integrated circuits (ICs) to processors and microcontrollers in short-distance, intra-board communication.
The I2C bus can be found in a wide range of electronics applications where simplicity and low manufacturing cost are more important than speed.

Many dev modules are connecting with I2C interface, it just like USB interface in microcontroller world.

Ref.:

https://en.wikipedia.org/wiki/I2C

Software Preparation

  1. For circuit design and PCB layout, this project using JLC EDA design software. Please download and install JLC EDA design software at lceda.cn.
  2. 3D enclosure design using Autodesk Fusion, please download at autodesk.com.
  3. Optional, download JLCONE for transparent 3d Enclosure printing order.
  4. Software development using Arduino IDE, please follow Waveshare WiKi to install software and ESP32 support.

Circuit Design

MINTIA Keyboard part 1 Schematic

In normal mini keyboard, not count the function key F1-12, has around 65 keys. The keys arranged in 5 rows, so each row can have 65 / 5 = 13 keys.

Most keyboard use matrix circuit design to connect all buttons 5 rows and 13 columns, so it requires 5 + 13 GPIOs. I2C interface used 2 GPIOs, then total requires 20 GPIOs. Waveshare RP2040-tiny dev board is a low profile dev board and have 20 GPIOs, it just fit for this project.

From previous experience, the normal tactile button is too hard to press compare with the mini keyboard in the market. It is related to the "Operating Force" attribute. Common tactile button is 160gf or 250gf. After testing, I think 100gf (~= 1N) is much better for a tiny keyboard.

Please view the above video for the circuit design details.

PCB Layout

MINTIA Keyboard part 2 PCB layout

After circuit design, the next step is export the schematic to PCB layout. I would like to build a tiny keyboard that can fit in a MINTIA mint box, so the PCB size is 74.5 x 44.3 mm.

some special keys are rotated 90 degree for easier identification. All buttons placed at PCB front side and the RP2040-tiny and the I2C pin header at the PCB back side.

Please view the above video for the PCB layout details.

The final version of schematic and PCB layout are shared at OSHWHub:

https://oshwhub.com/moononournation/project_bvgfbgsk

Soldering Work

MINTIA Keyboard part 3 soldering work

After finished the PCB layout, JLC EDA design software can direct order the PCB online. You can also order the SMT service at the same time. Soldering 65 tiny tactile buttons yourself is not easy, so I order the front side only SMT service. The PCB back side only has 2 components, RP2040-tiny and a pin header, so I can soldering myself.

Please view the above video for the soldering work details.

3D Enclosure Design

MINTIA Keyboard part 4 3D design enclosure

The 3D enclosure design first follow the MINTIA mint box back side appearance. And cut the hole for the I2C pin header port. Then follow the PCB buttons position cut the holes.

JLC EDA design software also can export the PCB layout 3D model, so I can import the model to the 3D enclosure design to cross check is it fit together.

Please view the above video for the 3D enclosure design details.

The final version of 3D enclosure STL files are shared at Thingiverse:

https://www.thingiverse.com/thing:7411628

3D Print & Assembly

MINTIA Keyboard part 5 3D print and assembly

Please download the STL at: https://www.thingiverse.com/thing:7411628

You can print it yourself or order 3D printout at thingiverse or transparent version at JLC.

Please view the above video for the 3D print and assembly details.

Optional: Key Label Design

IMG_0717.jpeg
IMG_0743.jpeg
IMG_0874.jpeg
IMG_1016.jpeg
IMG_1039.jpeg
IMG_1062.jpeg

If you are using transparent or frame only version 3D enclosure, you can see the key label printed on PCB. However, if you printed a non-transparent 3D enclosure, you need label the key yourself.

You can print on an adhesive A4 label sheet then cut and stick on the enclosure; you can direct use a marker pen write the key label on the button; or order a custom design UV DTF transfer sticker...

USB Keyboard Software

MINTIA Keyboard part 6 USB keyboard Compile, Upload & Test

Please download the source code at GitHub:

https://github.com/moononournation/ProjectMINTIA

Open RP2040Keyboard/RP2040KeyboardUSB/RP2040KeyboardUSB.ino in Arduino IDE, then compile and upload to RP2040-tiny.

After upload successfully, a new USB keyboard device is connected to your computer. You can use some online keyboard tester to check is it work, e.g. https://en.key-test.ru

Please view the above video for the details.

Fn Key Mapping

The USB Keyboard program defined some Fn mapping for more keys input. E.g. if you hold the "fn" key and press "1" key, it becomes "F1" key.

uint8_t key_fn_map[FN_KEY_PAIRS * 2] = {
/* from and to key pair */
'1', KEY_F1,
'2', KEY_F2,
'3', KEY_F3,
'4', KEY_F4,
'5', KEY_F5,
'6', KEY_F6,
'7', KEY_F7,
'8', KEY_F8,
'9', KEY_F9,
'0', KEY_F10,
'-', KEY_F11,
KEY_BACKSPACE, KEY_F12,
KEY_LEFT_SHIFT, KEY_RIGHT_SHIFT,
KEY_HOME, KEY_PAGE_UP,
KEY_END, KEY_PAGE_DOWN,
KEY_LEFT_CTRL, KEY_RIGHT_CTRL,
KEY_LEFT_ALT, KEY_RIGHT_ALT,
KEY_LEFT_GUI, KEY_RIGHT_GUI,
KEY_DELETE, KEY_INSERT,
'=', KEY_MENU,
};

You can change this mapping as your preference, e.g. you may want fn+up key become page up key.

I2C Keyboard Software

MINTIA Keyboard I2C test

I2C Keyboard software still work in progress. I am still struggling on the communication data format.

As mentioned at the beginning, I2C keyboards are not common in the market, so lack of a standard data format. After my research, there are 3 possible options I can follow:

  1. TI TCA8418 standard, this is a popular I2C keyboard chip that can handle 8x10 key matrix. It can handle 10 key press and release event for each enquiry. But the client side needs to interpret the matrix key code to actual key after read the data.
  2. USB keyboard HID standard, all key code is well defined so easy to handle at client side. Each enquiry can handle all modifier keys pressed and at most 6 key pressed. This is a proofed work solution all over the world user using USB keyboard everyday.
  3. Simply send all pressed keys, since RP2040 able to buffer all key pressed so it can simply send out all key pressed data.

Current RP2040KeyboardI2C.ino sample program simply send all pressed keys, but not yet handle the fn key mapping. In long term, there should have another version that can meet HID standard so it is more portable for the use case like vintage machine emulator and VNC thin client.

Enjoy!

Now you can develop the project that needs keyboard input, e.g. vintage machine emulator, VNC thin client, search a song to play in a large storage or simply input WiFi password ;>

Note:

The keyboard may not always connected, just plug it in with the I2C cable while required.

Simple Key Test Program

MINTIA Keyboard simple key test

At early key matrix development, a simple test program can help the quick PoC. RP2040KeyboardTest.ino is a simple program, simply define all rows and columns pins can check the press and release status.