HacKeyboard, an open hardware mechanical keyboard – part IV

Hi everyone! This is the fourth post on building the HacKeyboard. In case you haven’t read the first ones, here are the links:

HacKeyboard, an open hardware mechanical keyboard, part I

HacKeyboard, an open hardware mechanical keyboard, part II

HacKeyboard, an open hardware mechanical keyboard, part III

Where were we?… Oh, yes… HacKeyboard case complete!

In the last part of this project I had just finished describing the process I used to make the keyboard case. Below you can see a few photos of how it looked like. By then I was kind of proud that I managed to make such a beautiful keyboard 🙂

Hackeyboard case

Hackeyboard placing switches keycaps

Hackeyboard placing switches and keycaps

Hackeyboard case complete

So, mechanics are done. Let’s move on to the electronics! 🙂

Selecting the components, designing the schematic and PCB

I’ll start by giving you the list of components necessary for the electronics part and then I’ll explain a little bit of the circuit and PCB design. Just as extra information, the list of components provided is the result of three iterations of the schematic and PCB. To reach the final design I designed three versions of the schematic, three versions of the PCB, manually fabricated three huge double sided PCBs, including drilling, vias and soldering components. It took me some time to do all of this, but I didn’t give up and reached a final working design.

Gladly for you, you won’t have to go through all of it since now the working design is fully open source and you can just use it it or work on it to make your own modifications (different switches, different layouts, extra features, etc.).

Here’s the list of used components:

I bought most of the stuff on ebay. In case you’re a student you can use your school/university email to order free samples of the Microchip and Maxim parts, which are the ‘less cheap’ parts.

As I mentioned, this list of components was not defined in the first iteration. In the first version of the PCB I tried to make I used a TPS60130 5V regulated Charge pump with 300mA output from Texas Instruments but it’s small footprint made it difficult both to solder and to make a homemade PCB with such thin traces. The first version also had a footprint for a RN-42-HID Bluetooth module, connector for Li-Ion batteries, and a Microchip MCP73871 (datasheet) Li-Ion battery charger with load sharing but I ended up giving up on it because I was in a hurry to get the keyboard done for Lisbon Mini Maker Faire and it would slow everything down: the PCB would need to have a lot more vias and I would need to spend more time writing the firmware for Bluetooth and power management and debugging. As such, these features were abandoned in this version. Maybe next time.

I used KiCAD for the electronics and PCB design. All the KiCAD project files and schematic and PCB in PDF format can be downloaded in my Github.

Designing the schematic was fairly simple and you can see the result below. I’ll explain the essential parts of it below.

hackeyboard schematic

Designing the PCB took a lot more time since I had to place all the components in the correct position, place all the vias and route all the tracks. Also, I had to redesign it twice due to problems with some components previously chosen, other mistakes and to make it easier to manufacture at home. Below you can see the final result:

hackeyboard pcb top

hackeyboard pcb bottom

Brief explanation of the electronics: HacKeyboard has a single microcontroller, the PIC18F4550, which has built-in USB. The word ‘microcontroller’ and the reference ‘PIC18F4550’ may seem complicated or strange to some of you but it is basically the same kind of thing as the ATMega328 that you find on Arduinos, but from a different manufacturer, with a different architecture and different built-in features. Having that said, the microcontroller is responsible for managing and controlling everything on the keyboard:

  • Reading the switch matrix: Taking into account that a keyboard is a big matrix of switches, each column and each line are connected to a different IO (input/output) pin on the microcontroller. The microcontroller turns each column on at each time, one by one and reads the logic levels in all the lines, evaluating which switches in that column are pressed. Then it turns that column off and proceeds for the next one. This happens several times per second. It is a very fast process that is always running on the microcontroller. Once the key presses are evaluated it outputs the respective characters via USB;
  • Controlling the hidden USB Flash Drive: The flash drive is powered via the MAX682, which is a 5V charge Pump regulator that has a ‘Shutdown’ pin. To activate or deactivate the USB flash drive, the microcontroller activates or deactivates this pin, turning it on or off;
  • Saving macros and key log: In the circuit there is a 24AA512 Serial EEPROM (64K x 8 bits) which is a memory that is used to store all the macros and the key activity log. When in saving modes, the microcontroller, which is connected to the memory via a serial protocol (SPI) sends to specific memory positions the keys that must be stored. This memory holds the data even if you disconnect the keyboard. In the default firmware each macro position can store up to 150 bytes and the rest of the memory is used by the key logger. This can easily be modified by just changing some address values in the provided source code;
  • Controlling the WS2812B RGB LEDs: The microcontroller is also responsible for controlling the RGB LEDs. These LEDs have their own serial protocol where a ‘0’ is represented by a pulse with a certain timing and a ‘1’ is represented by another pulse with a different timing (check the datasheet for timings). The LEDs have a built in 3 byte memory where they store the 3 values for Red, Green and Blue. These values must be in a range from 0 to 255. They also have a built-in shift register, which allows them to pass on information to the next LEDs. If you only have 2 WS2812B LEDs, you connect your microcontroller to the data input pin of only one of them and you connect the data input pin of the second one to the data output pin of the first one. Then the microcontroller will have to send 6 bytes, 3 for each LED, starting from the second LED (more distant in terms of connections). The first LED will pass on the information to the second one.

Are you enjoying this project? Follow the link to continue reading and for the full set of photos of the build: [HacKeyboard, an open hardware mechanical keyboard – part V]

Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! 🙂