Author Topic: Hybris - A wireless 104 key keyboard from scratch  (Read 882 times)

0 Members and 1 Guest are viewing this topic.

Online RichardH

  • Thread Starter
  • Posts: 12
Hybris - A wireless 104 key keyboard from scratch
« on: Sat, 03 February 2018, 21:49:24 »


I've been working on this for the last few weeks and I thought I'd share here as a project log. The name hybris comes from an old Amiga game I liked as a kid. I'm planning on using the 2 rectangular lights inspired by the Amiga A500 to indicate charging and pairing. I'm also adding a rotary encoder for some basic media controls to the top right of the keyboard. I'm using the new Adafruit nrf52 feather platform for Bluetooth LE, which has pretty limited IO for a keyboard this big. I've built up a little dev kit using the guts from a Velocifire TM01 and a breadboard to start porting TMK over to Arduino where the Bluefruit/Nordic toolchain is. It looks like there's been a few attempts to use TMK with Arduino - so that's promising. Software wise, I have the keyboard and matrix parts ported and am now diving into the action layer.  I'm using this project mostly for educational purposes.

Planned so far:
- Adafruit Bluefruit BLE Feather (NRF52)
- 500mAh lipoly battery
- Universal plate from MK - probably not going to go too radical on key placement
- Small IO expansion using a few 74hc165s
- A nice 24 step rotary encoder with hardware debouncing
- Updating TMK (once I understand it better) and the hardware to use a tiny power budget
- Cherry MX browns and Cherry stabilizers
- Custom aluminum case probably designed in Design Spark Mechanical
- Custom Schematic and PCB using Circuitmaker
- USB for charging/programming only
- Perhaps some lighting effects on the top/bottom when using USB





I've got a gallery started on Flickr: https://www.flickr.com/gp/chaffneue/821407

The ongoing firmware port is here: https://github.com/century-synthetics/hybris/tree/master/firmware/hybris

More to come!

-Rich


Offline OldIsNew

  • Posts: 99
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #1 on: Sat, 03 February 2018, 23:50:59 »
Nice! Great work for sure!

Offline TalkingTree

  • Posts: 2024
  • Location: Italy (142)
    • My projects
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #2 on: Sun, 04 February 2018, 02:16:47 »
- Updating TMK (once I understand it better) and the hardware to use a tiny power budget
I'm following closely.

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #3 on: Mon, 05 February 2018, 01:58:30 »
Well hell yes! I've got the basic features of TMK running in Arduino's IDE and using the NRF as a host, which is a good step.



I'm getting some compiler errors with action tapping, so I'll re-enable it and tackle that next.  I'll try and clean up and port the debug code to something more usable in Arduino IDE.

This is one that has me scratching my head:

common/action_tapping.c
Code: [Select]
                        process_action(&(keyrecord_t){
                                .tap = tapping_key.tap,
                                .event.key = tapping_key.event.key,
                                .event.time = event.time,
                                .event.pressed = false
                        });

Gives me the error:

Code: [Select]
AppData\Local\Temp\arduino_build_452700\sketch\action_tapping.cpp: In function 'bool process_tapping(keyrecord_t*)':

action_tapping.cpp:160: error: expected primary-expression before ')' token

                         process_action(&(keyrecord_t){

Maybe G++ can't handle this syntax? Kind of a weird error.

-Rich

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #4 on: Tue, 06 February 2018, 04:50:45 »
Got some keycaps and put 'em on the dev board. I like the profile but I'm gonna keep looking for real GMK goodness :) Updated the firmware tonight to use SPI for the shift registers and fixed up a few usability things. Up super late coding.. ahh good times :)



-Rich

Offline TonyD

  • Posts: 10
  • Location: Newcastle, UK
    • dtronixs
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #5 on: Tue, 06 February 2018, 09:52:37 »
Looking good  :thumb:

I'm looking forward to seeing more pics as it progresses

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #6 on: Wed, 07 February 2018, 03:01:39 »




Tonight I finally got some current measurements - sitting at 12.5mA which is probably two or three orders of magnitude higher than I want. I've got a lot of work to do :P Surprisingly though, even when I comment out all my code from the main loop, the power consumption is still 12-13mA. So I found this issue in Github and I'll see if I can run a nightly build to try and crack this.

https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/51#issuecomment-363652938

Also some sweet sprites from the game! Ohhh the possibilties :)



-Rich

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #7 on: Fri, 09 February 2018, 02:59:12 »
After looking over the code for a few days, I found some other people with the same general issue- the current draw is pretty damned high all the time. This particular dev board has a hardware issue. The USB to UART interface, a CP2104 is powered full time, even when using a battery power source. So I've ripped that off the board and opted for an external interface to use when I'm programming and debugging only. It looks like there's a new product coming from Adafruit that has addressed this issue, but there's no ETA yet. Hope it'll be ready for the final design!



This has brought the unmodified TMK firmware down to around 4mA. I think I'll just have a few tweaks in the software and we'll be under 500uA peak, which will be a worthy target.   

-Rich

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #8 on: Sat, 10 February 2018, 00:08:48 »
I broke out my little FTDI module to replace the in circuit usb to serial converter and it has brought down the power to just 2.3mA with some minor modifications to make the code wait for interrupts. It looks like the dev board hardware has a minimum current draw of 1mA, so I'm getting pretty close to the limit - after that I may be building the bluetooth circuit onto my PCB component by component to better select the power supply parts. The next step will be to wake on keyboard activity and that should knock another milliamp off.

 



-Rich

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #9 on: Sun, 11 February 2018, 01:02:08 »
More work on firmware today and now we're down to a total of 1.4mA, which means with the quiescent draw from the board's other components, this slightly modified TMK is only drawing 400uA :D insane! I'll be looking into a sleep mode next for when the user goes AFK - that should bring the current down to 1mA. With this kind of current draw, a 500 mAh battery should get 10 days between charges. I might be looking at picking a better LDO regulator with less current leakage for the final design, but this works as a dev board for now.

The modification adds a diode to each column to a sense interrupt line on the MCU. This way, TMK's keyboard_task() is only run while a key is down and unset once the keys are released (the driver sends a zeroed out packet).





-Rich
                                     

Offline TalkingTree

  • Posts: 2024
  • Location: Italy (142)
    • My projects
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #10 on: Sun, 11 February 2018, 03:08:58 »
I'm posting only to say that I'm totally supporting this idea and following it closely.
Keep up the good work.

Offline senso

  • Posts: 11
  • Location: Portugal
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #11 on: Tue, 13 February 2018, 12:57:53 »
Almost all of the Atmega32U4 support PCINT(pin change interrupt), you config the PCINT masks to config which pins fire the PCINT interrupt vector, not sure if/how this would work nicely when the keyboard goes into sleep and there is no row/column scanning going on.

Using high value or switched pull-up resistors is also a thing, for a ultra low power project I used 300K resistors as pull-ups for local i2c switched via a MOSFET, because using 4.7K pull-ups was killing
my power budget and even when on deep sleep even the 300K lead to a much higher battery discharge, got 2 years out a CR2032 with a AtmegaRFA256 with a bunch of sensors, the only thing always up was a RTC, it had lower quiescent than using the built in RTC timer/counter.

Reading all sensor data used 1.3mA, RF comms spiked to 13mA, all turned off, around 0.003-0.007mA(flux residues caused this value to go up, scrubbed the prototype boards real good).

Read a bit about PCINT and see if it can work for you, I know that PCINT wont wake up the micro from all sleep states, but can wake it from some, maybe you already hit this nail and thats why you are using a diode-OR into one of the INT pins that can wake the micro from deep sleep states.

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #12 on: Wed, 14 February 2018, 02:48:33 »
These Bluefruit nrf52 boards are a different architecture - ARM Cortex M4 - but they do have a PCINT concept. I'm planning to run an extra diode from each column into a single pin to do the task-on-keypress and deep wake stuff.. I'm guessing during sleep it'll mean you'll need to press a key to wake it up and therefore it's going to miss the first keypress. Good call on the pullup/pulldown resistors - sounds like something I need to tune especially with so many columns. I'm not sure where exactly this 1mA quiescent load is coming from (this is while holding reset on the MCU - should be no brain activity there) - maybe a voltage divider, the LDO or other components on the board. It seems like that would be the first big thing to knock down.

In the meantime I got some other features working like the rotary encoder, the battery level report and the indicator for bluetooth connectivity.



-Rich


Offline pomk

  • Posts: 440
  • Location: Finland
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #13 on: Wed, 14 February 2018, 09:35:20 »
There is no need to add more diodes or lines to the mcu. In case there is no activity in the matrix, you can set all your rows high and attach active high interrupts to your columns. At the isr you just re-define the matrix pins for regular scanning and restart the matrix scanning timer. You will not miss the first keypress, as the matrix scan finds the pressed button as normal.

With pure nRf51 in minimal config I get around 200uA current when typing and as low as 15uA when only keeping the ble connection active (depending on the connection parameters forced by the host).

Btw. LEDs are your enemy, a single low power led easily multiplies your power usage by a factor of 10-50 :D

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #14 on: Wed, 14 February 2018, 10:28:40 »
The complication is the shift registers Iím using to expand the i/o - they need to receive a clock signal to read them. Thatís why I need the diodes to feed directly to the mcu - that way I can set the rows high and catch activity on the matrix without needing to latch and clock the registers. All of the leds are off during normal operation - Iíll just be using them for indicating charging and when the keyboard has disconnected from Bluetooth.

-Rich

Offline pomk

  • Posts: 440
  • Location: Finland
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #15 on: Wed, 14 February 2018, 10:36:05 »
Surely the raytac module supports enough IO by itself? They are about 5 USD per piece if you buy directly from raytac.

Online RichardH

  • Thread Starter
  • Posts: 12
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #16 on: Wed, 14 February 2018, 11:08:21 »
Yeah this was a possible way to go if I want to drop the Adafruit board (might still do that)

-The matrix for a full size is 6x20
-I've got a rotary encoder using 2 pins
-I've got 2 LEDs
-trying to keep the i2c bus for under lighting

so that's a total of 30 pins if I don't want to use registers

Still seems kinda high - the Raytac module itself has 20 total GPIO pins so I'm not sure I'd be able to squeeze it all in. The shift registers use like 10uA when actively clocked, so it's not a big bite out of the power budget.

-Rich

Offline pomk

  • Posts: 440
  • Location: Finland
Re: Hybris - A wireless 104 key keyboard from scratch
« Reply #17 on: Wed, 14 February 2018, 17:59:21 »
The raytac modules (save for some small footprint ones) have the full 32 io mapped out. Two youíll probably use for the 32k crystal, but the rest are usable. Though 10uA of excess current is pretty ok regardless.