geekhack

geekhack Projects => Making Stuff Together! => Topic started by: Yihui on Mon, 22 June 2020, 04:09:24

Title: keyboard powered by python
Post by: Yihui on Mon, 22 June 2020, 04:09:24
Two month ago I made a hand-wired keyboard powered by Python (CircuitPython). After spending some time to improve the python keyboard,
it has similar features like TMK/QMK based keyboards now.

(https://github.com/makerdiary/python-keyboard/blob/zh-cn/img/python-inside-keyboard.jpg?raw=true)

While, with python inside,  the keyboard has some unique features. When connected to a computer, it is not just a keyboard, but also a USB drive.
The python code is in the USB drive, which make it super easy to modify keyboard code and add a extension.
To configure the keyboard's keymap, we can just edit keyboard.py in the USB drive with any text editor.
For example, use d key as a Tap-key to activate navigation functions (similar to vim).

(https://github.com/makerdiary/python-keyboard/raw/master/img/d-for-navigation.png)

The keymap is:

Code: [Select]
L1D = LAYER_TAP(1, D)
KEYMAP = (
    # layer 0
    (
        ESC, 1,  2,  3,  4,  5,  6,  7,  8,  9,  0, '-', '=', BACKSPACE,
        TAB,  Q,  W,  E,  R,  T,  Y,  U,  I,  O,  P, '[', ']', '|',
        CAPS,  A, S, L1D,  F,  G,  H,  J,  K,  L, ';', '"',       ENTER,
        LSHIFT,  Z,  X,  C,  V,  B,  N,  M, ',', '.', '/',       RSHIFT,
        LCTRL, LGUI, LALT,        SPACE,         RALT, MENU,  L1, RCTRL
    ),
    # layer 1
    (
        '`',  F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9, F10, F11, F12, DEL,
        ___, ___, ___, ___, ___, ___, ___,PGUP, ___, ___, ___, ___, ___, ___,
        ___, ___, ___, ___, ___, ___,LEFT, UP,DOWN,RIGHT, ___, ___,      ___,
        ___, ___, ___, ___, ___, ___,PGDN, ___, ___, ___, ___,           ___,
        ___, ___, ___,                ___,               ___, ___, ___,  ___
    )
)

The project is at https://github.com/makerdiary/python-keyboard (https://github.com/makerdiary/python-keyboard)

As hand-wiring a keyboard is hard and is not for everyone, so I'm preparing a new keyboard pcb which will be powered by python.
What's your idea of a keyboard powered by python?


Title: Re: keyboard powered by python
Post by: suicidal_orange on Mon, 22 June 2020, 04:49:29
Being able to change the keymap anywhere there's a text editor sounds great :thumb:
Title: Re: keyboard powered by python
Post by: Findecanor on Mon, 22 June 2020, 05:09:51
BTW. I see that you are also the ones selling the microcontroller board in this keyboard.
It looks similar to a Feather board, but the pinout is not compatible. Why did you choose not to? I haven't seen any requirement for a license fee.
Title: Re: keyboard powered by python
Post by: Yihui on Mon, 22 June 2020, 06:15:18
BTW. I see that you are also the ones selling the microcontroller board in this keyboard.
It looks similar to a Feather board, but the pinout is not compatible. Why did you choose not to? I haven't seen any requirement for a license fee.

Feather form factor is cool. However, when designing the board, Feather was not as popular as today. Besides, Feather is a little small to place three antennas (NFC/Bluetooth/WiFi).
Title: Re: keyboard powered by python
Post by: Yihui on Sun, 05 July 2020, 22:16:06
The design of the keyboard PCBA is finished.

(https://github.com/makerdiary/python-keyboard/blob/master/img/hotswappable.jpg?raw=true)

It has modular design with nRF52840 M2 module and is hot-swappable.

Title: Re: keyboard powered by python
Post by: JCraftCables on Mon, 06 July 2020, 09:30:22
Cool! Who are you going to get to make the PCB?
Title: Re: keyboard powered by python
Post by: Yihui on Mon, 06 July 2020, 19:48:06
Cool! Who are you going to get to make the PCB?

As I'm in Shenzhen, finding a factory to make the PCB is quite easy.
Title: Re: keyboard powered by python
Post by: Yihui on Tue, 14 July 2020, 10:42:21
Have been tested the keyboard PCBA. It works well. With Python firmware, its latency is about 8 ms at the moment. It's OK for daily use.
While, there are a lot to improve.  Still working hard to decrease the latency and to improve power efficiency.
If you are interested, you can check our github repo https://github.com/makerdiary/python-keyboard (https://github.com/makerdiary/python-keyboard),
you can also pre-order the keyboard PCBA at https://makerdiary.com/collections/frontpage/products/m60-mechanical-keyboard-pcba (https://makerdiary.com/collections/frontpage/products/m60-mechanical-keyboard-pcba) now.

(https://cdn.shopify.com/s/files/1/0066/0865/0355/files/m60_hero_2048x_168dcced-db74-498b-94f3-01b98f24ada0.jpg?v=1593771860)

(https://github.com/makerdiary/python-keyboard/raw/main/img/m60.jpg)

(https://cdn.shopify.com/s/files/1/0066/0865/0355/files/m60-keyboard_parts_1200x_265a24a9-56ff-4904-b1f7-a59c6377a229.jpg?v=1594110086)

Title: Re: keyboard powered by python
Post by: Yihui on Tue, 28 July 2020, 09:11:41
Working on reducing power consumption of the python keyboard. Right now, its current is 400 uA when Bluetooth is connected an no key is pressed.

(https://user-images.githubusercontent.com/948283/88674932-fa7ce500-d11c-11ea-93f5-50e8ac994ba4.jpeg)

When holding a key down, the current is 550 uA

(https://user-images.githubusercontent.com/948283/88674972-01a3f300-d11d-11ea-8dce-20ac94c16f51.jpeg)

It is not final result yet. With further optimizing, it can be better.
Title: Re: keyboard powered by python
Post by: -Jerry- on Tue, 28 July 2020, 09:36:57
This is really interesting, excited to see how the performance increases go:)
Title: Re: keyboard powered by python
Post by: AngryCoder on Wed, 29 July 2020, 07:36:16
I love that. But what are the benefits of the nRF52840 over ESP32? I will follow this project.
Title: Re: keyboard powered by python
Post by: Yihui on Fri, 31 July 2020, 10:33:22
I love that. But what are the benefits of the nRF52840 over ESP32? I will follow this project.

IMHO, using ESP32 on a keyboard is not a good idea, as ESP32 doesn't have USB and is power hungry。
Title: Re: keyboard powered by python
Post by: Yihui on Sat, 22 August 2020, 08:44:34
With further works, the power consumption of the keyboard is lower. 0.05mA in sleep mode. 0.16mA when bluetooth is connected.
With a 1200mAh battery, the keyboard can be standby for several months.

(https://user-images.githubusercontent.com/948283/90957345-918c5100-e4bf-11ea-896c-a65c1b0efb77.jpg)


(https://user-images.githubusercontent.com/948283/90957346-94874180-e4bf-11ea-9f2c-ef9a3ed54e38.jpg)