Tuesday, March 22, 2016

Making a Custom Keyboard Part 3: DONE!

Custom Keyboard Project Summary Page

It has been a while since my last post, but I have actually been done with my keyboard for some time. Now that I have a moment, I will finally post the update!

Here is the final layout I settled on:

I have been using and tweaking this layout for close to 4 months now, and it is getting close to how I think I will leave it. There is still some fiddling to do with how mode works and some of the symbol keys, but overall, it is really close.

Here are some pictures of the final product:

Ah, ain't she pretty!

So, for those who really want to know, here is the step-by step building process:

Step-By-Step Build


Step 1 - Design

I feel like I have beat this dead horse enough... go check out parts 0 through 2 for this step. Overall I mostly used http://www.keyboard-layout-editor.com/ in the end. I started with other tools, but this one is just faster and easier to mix things around.

Step 2 - Laser-Cut the Acrylic Case

I got access to the laser cutter up on campus. They let anyone get swipe-card access, so long as you fill out the paperwork. Hopefully you have some way to get access like this, it is an amazing machine that is super fun to use.
If you cannot get access to a laser cutter, you can always have the parts made for you by a company that does laser cutting. That will, of course, be more expensive.

To laser cut your piece, you simply need to make a vector graphics image of what it should cut. The laser cutter here would cut all the way through for "hairline" lines, and then do etching for any kind of gradient. I wanted to get mine done quick, so I stuck with all hairline cuts.

Here is what my vector image looked like:

*See the apendix if you want the inkscape file

The layers stack starting in the bottom left, moving up the left column, and then going from bottom to top on the right column. I will refer to them by their number, starting with 1 as the bottom piece. 
Layer 1 through 5 (the left column) and layers 7, 9, 10, and 11 were all cut into 0.06 in. (1.5mm) acrylic. (I used "12in. x 48 in. Acrylic Wire Shelf Liner (4-Pack)" for $31 from home depot.) I made duplicates of layers 9 and 11. (9 as a backup, since that's the most important piece, and 11 so one could go above, and one below the suit piece of layer 10.)
Layers 6 and 8 were cut into a spare piece of acrylic that was about 0.22 in. (5.6mm) thick. These layers are the main support layers for the switch mounting layers (7 and 9.) WARNING: Without these support layers, the switch mounting plates will break. I broke one just pushing the switches in and pulling them out a few times as I played with different switch profiles. You may be able to cut the support layers out of the same one you used for all other layers, and just double them up. I don't know, though, as I have not tried it.

Here are some pics of the final cut layers (Note, there is a tab in the top center of some of these, I removed that later and put in another key. It was a last minute change, but I designed it so I could do that. I was going to have my indicators top center, but changed my mind. Also note that I did not originally laser-cut the corner wholes in. I tried that later and it totally worked! Really well too!)
The thinner layers 1, 2, 3, 4, 5, 7, 9, 10, and 11:
Switches mounted on layers 7 and 9:
A stack of the thinner layers (top view on top, bottom view on bottom):
(I apologize, apparently I don't have pictures of just the thick pieces... oh well)

After cutting out all the layers, I found the posts I wanted at ace hardware and bolted it all together:

Step 3 - Soldering

This part takes, by far, the longest.
To save some cash, I just grabbed the nearest CAT5 (Ethernet) cable and pulled that apart. That gave me plenty of colors to work with for dirt cheap! You will also need some diodes if you wish to stop the ghosting effect (explained here, if you care...)
I recommend following the first few steps in the excellent guide created by matt3o on deskauthority.net found here:
Perhaps one day I will rewrite that part here for the sake of completeness, but I don't think I will today.
NOTE: When following the guide above, try to make sure you do your rows all the way across and your columns all the way down. I thought I would save some pins by trying to make mine as close to a square as possible. I ended up wiring the left and right halves as separate rows. While I saved some pins, it really just made the firmware step more complex and ugly. I was going to use the extra pins for some LED's but sticking to the rows and columns would have been just fine.

Here is a photo of my final wiring (Yeah, not toOOoo pretty, but I am a coder, not a hardware guy...)

Once all the columns and rows are soldered up good, you need to attach them to your microcontroller. Again, I used the Teensy 2.0 from PJRC. (That is what the firmware section below is aimed at too, so you might want to just use that one, unless you know what you're doing.)

Wire each row to a pin and each column to a pin on the Teensy 2.0.
NOTE: I messed up here again. I was looking at the keyboard upside-down for so long, that I forgot that I was looking at things backwards. I lined up my pins so nicely to follow a numerical, logical order, only to discover that they were all backwards. This doesn't matter too much, however, since the firmware has you put in the row-pin col-pin assignments. So... don't over think it. Just make sure you know what is hooked where.

Here are some pics of the teensy wired into the my keyboard:

And, putting it all together:
Note that I also ended up drilling a small (poorly lined up) whole in the bottom of the keyboard for quick access to the Teensy reset button. This made tweaking the firmware much faster, easier, and safer, as I didn't have to keep taking the thing apart anymore.

Step 4 - The Firmware

Surprisingly, this part was pretty easy. I had no soldering errors, so that helped, but overall, most of the work is done for you.
Once again, I would like to turn you over to matt3o. He has a great guide on using the TMK keyboard firmware:
Again, I may return to write up my own guide for the firmware, but for now, this suficeth me.

Step 5 - PLAY!!!

It's alive!




Now you can put away that old T.Oliver and be a high roller with your crazy custom keyboard (You are making an AlphaGrip, aren't you?)

If you do make one, send me a pic! I would love to see it.


Appendix

matt3o's guide. (I used this for most of the process. Thanks matt3o!)
Cherry MX datasheet (PDF) (if link breaks, just google "Cherry MX datasheet")
- This has all the dimensions of the switch. There are two main types, plate mounted and pcb mounted. If you are doing the method above, you want plate mounted. (The pcb mounted ones do not have the clips to hook into a plate, but are fastened purely by soldering them to a PCB.)
- Many other switches have the same profile. I used Gateron switches, which fit perfectly into the cherry-cut slots.

Laser Cutter file for inkscape (SVG) (CC Non-commercial share-alike, contact me if you want commercial license. I will let you have it for free, I just want to know when commercial folks are using it.)
- Some laser cutters don't like Inkscape files. I had to export the file as a pdf, then import the pdf into Corel Draw. From there, I ungrouped the items and changed all lines to "hairline" in Corel Draw. After lining things up with how I wanted them on the piece, they were ready to print!

Teensy 2.0 Purchase Page
Teensy 2.0 Pinout Sheet (PDF)

Wednesday, July 8, 2015

Making a Custom Keyboard Part 0

Custom Keyboard Project Summary Page

Ok, lets take a step back (while I wait for the rest of my parts which are coming slow because I am cheap...) Lets look at the designing phase.

As a programmer, I have be taught over and over that design is one of the most important phases of development. When I decided to make a custom keyboard, I started with several important goals. Here is a list of bad design points and what I wanted to do to fix those. I have saved most of the designs I went through so we can track each issue that I wanted to tackle.

Say hello to the first keyboard on this journey, The Super Keyboard:
I had had this basic idea for years. It always bothered me that I only really needed the spacebar on one thumb. The other thumb (my left) just sits there all day doing nothing. Why not free up both shift spots and the capslock spot for keys that are far more useful by putting the shift key on the other thumb! I also really wanted to move in the other control keys. Anyway, back when I made the image I included many of these feature descriptions, so feel free to read about them from that image.

Shortly after that initial design, I created a much smaller version. A 60% version of the super keyboard called the Katana (sorry I don't have a higher res... wish I did):

There are a few minor changes to the function keys at the top, but this version is mostly the same.

As I began to look more into keyboards and how they came to be what they are, I learned that the staggered keys actually come from the early typewriters. In the picture of this beautiful Monarch Typewriter (below,) you can see that the keys are staggered to fit the metal bars on the back of each key.

Now, this stagger was useful back then, and the keys were further apart making touch typing less about resting your hands on home row. (You may also notice that the space bar was even bigger back then. We have shrunken it once already, whats wrong with shrinking more it as I did for the super keyboard?) So, why do we still have the stagger? My guess is that when moving from typewriters to word processors, they were advertising to the same people. We made keyboards as close to the ones found on typewriters, so as to get more customers.

"So, whats wrong with the stagger?" you may ask. Well, lets just look at what keys are used by what fingers. Here is a finger diagram for a classic layout:
As you can see in the diagram above, typing on staggered keyboards means you are typing at an angle! Each finger moves along this strange diagonal path. This diagonal did not mean as much when your fingers were not always resting on home row, but nowadays, it means a lot more. Next time you type, pay attention to each finger and the comfort of hitting each key. For me, the right hand seems fine, but the left hand feels awkward as fingers are trying to reach in a diagonal that goes against the angle that hand is at.

Ok, so the next natural step in my design was to get rid of the stagger (as you probly guessed by now.) Here is the Katana II:
Now, there are a few other minor things here. After straightening out the keys, I noticed that the right pinky has waaaay more keys than the left one. Just look back up at the finger diagram above. The right pinky is one busy finger! So, in an attempt to make things right in the universe, I decided to try to even out the pinkys. I moved some keys like backspace, insert, delete, etc. to the right side. The keyboard was balanced!

It was around this time that I began to look into materials and buying parts. After deciding on a layered acrylic case, I drew an updated mock-up, The Butterfly:

Now, as you can see, the top two rows go all the way to the edge. That is because I discovered it was much cheaper to by acrylic sheets in increments of 12". In order to knock of some dollars, I had to make it strangely compact. I didn't really like it...

So I made The Butterfly II (though the name made less sense with the new shape...):

Notice that I had to change a few things around to get things to fit better. I moved all the edge keys in, shrunk many keys, and added more keys to the bottom row.

After a bit of negative feedback on the oddly shaped edges, I changed the design to be more uniform with The Butterfly III (Note: this one also has the Colemak layout on it instead of Dvorak):

Shortly after that, I found keycaps that I really liked, and ended up changing my drawing to match:


Now, the changes made to standard key positions in the Butterly II were hard to make. At that moment, I had stepped beyond the classic layout and begun moving keys to new locations. Once you throw out that inhibition, the design tends to snowball a bit...

After testing out this layout on paper and a simple mockup, I decided that I didn't like the bottom row still. One of my side goals was to never have to move my hands from home row ever again! The keys underneath my palms seems to go against that goals quite strongly. I decided to change things up a bit, and depart even further from the classic designs. Say hello to The Mantis (sorry again for the low res...):

So, I moved a ton of keys off of bottom row. I also moved the arrow keys a bit. The biggest thing to note is that the bottom 3 keys would now be sitting a full key-height below the rest of the keys (see the side view.) This would allow you to hit both of those bottom middle rows of keys with your thumbs. This felt right. Each finger now had at least 4 keys and the thumbs had that many as well.

I was feeling pretty good about my design. I decided to make another cardboard mock-up. This time I have a picture of it. (Well, most of it. I took some of the keys off later and I don't know where they are at the moment...)


Around this time, I began to program an android version of my keyboard with the colemak layout, so I could start learning it ahead of time. While creating that, I created a secondary keyboard for the numbers and symbols, as most keyboards have. That got me thinking, and eventually caused the birth of what is my current "final" design. The Mantis Hacker Keyboard:

Now, this adds a function key to the bottom most row. This function key would act like the "symbol" key on phones. It would give access to numbers and symbols. I optimized the keys to try to keep the numpad's configuration, and I organized it for programmers by placing all the brackets along the middle column.
Navigation seems more intuitive as the arrow keys are stacked with the end, home, page up, and page down keys. Think about it, now ctrl right moves right one word while 'fn' right will go to the end of the line. Based on what modifier your left thumb is on, you can move different amounts. The modifiers are in the configuration they are to allow for maximum keyboard shortcut access without lifting your hands from the keyboard. There are still a few I would like to tweak for, but it is really close.

I was so excited (and bored) that I created a 3D model of it:

There are still a few small changes to be made, I am sure, but I think I am close enough to the hardware layout that I want. The firmware will be much easier to change if I decide I want symbols in a different place or something.

I even made a nice little mock-up of this version. It even has the lovely cherry switches and white and blue keycaps so I can test it out. So far, I really like it:


Anyway, hope you enjoyed this little journey. If you have any comments, ideas, or suggestions, I would love to hear them.
Thanks,
Cory

Wednesday, April 29, 2015

Making A Custom Keyboard Part 2

Custom Keyboard Project Summary Page

Okay, I know I said the previous design was the one I would make, but I have not stopped redesigning things. I probably won't stop either. I just keep having better ideas. This latest version throws even more tradition out the window. I have dropped the number of keys down to 46 or 47 (if you don't include the "lock" key. Still not sure about that one.)
Here is a 3D model of the thing, just to give you a taste:


As you can see, the thumb is now much more responsible and the pinkeys have almost nothing to do compared to their old spot. I have also gotten rid of the top number row. HOW? I NEED NUMBERS!!! Don't worry. You can still do everything you used to be able to do. Here is the layout for this new 10.5" x 4.5" x 1.5" Mantis-Hackster:



Now, the basic idea is that you now have two "shift" modes. The regular shift key works like normal on the left thumb (much like the previous design.) This model puts the "fn" key on the left thumb as well, but down a level. Calling it "fn" is now kinda a misnomer as it does so much more. The "fn" key is now like a second shift. This key allows access to a full 10-key and all the symbols found on the outside edges of a normal keyboard. I have optimized it for programmers by having the brackets and parenthesis on the inside columns. Home, End, Page Up, and Page Dn have been combined with their respective arrow keys, which have also been moved. Backspace and delete share a key. Tab and Escape share a key. Yeah, it all makes sense. It is kinda like some phone keyboards, really. You have the regular text shift and then the symbol key. One other nice thing is that the symbols can be arranged according to commonality. (That gives those keyboard layout nuts another thing to argue over.) I picked a layout that seemed to make sense and just figured it was good enough. Symbols aren't that common, after all, so they won't be your bottleneck when it comes to typing.

For those confused about the Lock and macro key:
Lock can lock any set of keys on the keyboard. Hold down lock and then start hitting keys. This button just keeps keys from sending the "key up" message to the computer. When the lock is released, all pressed keys will stay "down" until lock or that key is hit again.
The macro key can just record a set of keystrokes and then play them back over and over. Useful for formatting things. Format one line then just hit replay for the next! I love this feature from some text editors and want it more readily available all the time.
Feel free to change the lock and macro buttons in your own version of this layout. Heck, if I get this all done and release the code for the teensy, you can swap out those keys real easy!

Anyway, here is the NEW price breakdown (price before shipping in parenthesis if there was shipping costs):
- Colored Keycaps: $30 ($25)
- Teensy 2.0: $16 ($19.03)
- Acrylic Case: $40.64
- 50 Cherry MX Blue switches: $61.65 ($46.50) (a few extras just in case)
- 50 (1N4148) Diodes: $1.85
- Cat5 7ft cable (for colored wires): $1.36
- USB 2.0 to Mini-B 5-pin 6ft cable: $1.41
--- (shipping for cat5 and usb2.0 was $5.99 together)
Total costs: $158.90

I am sure the case could be a little cheaper too, but I just took off the extra button costs.

Yay! A little bit cheaper. If this were on massdrop or some other group-buy site, the price would probly be about $120 and come with a more official case. I just found some Gateron switches on massdrop that cost closer to $45 for 120. That could make 2 keyboards. That would make the total above closer to $140. Were this to be made in a real production line, it could probly be made for close to $70-ish. That would be a pretty descent product right there.

Anyway,  I am sure I will tweak things even more as I get closer to making things for real. I now have all the parts but the case supplies. I have those on order and should get them by May 5th, so hang in there.

As a side note for making the case, I am currently a student at BYU and am going through the training stuff to get access to the shop lab. This will allow me to use the laser cutter for making the case. If you don't have a free option like this through a nearby school or library, you may have to get it made for you by someone online. Look around, there are a surprising number of solutions to getting a case made for your keyboard. If worse comes to worst you can always just make one out of wood or cardboard...

Oh, and feedback is always appreciated

Friday, April 17, 2015

Making A Custom Keyboard Part 1

Custom Keyboard Project Summary Page

I have started building my own custom keyboard. Have just finished the design phase and have purchased all the parts I need to make it. The following is a more detailed description.

I started by designing the keyboard I wanted to build in Inkscape. I drew everything to scale so I could measure and get exact amounts for everything. My original design looked something like this:


I continued to modify and tweak things. I built a crappy cardboard prototype with keys pulled off an old keyboard and finally came to the following design:


Yeah, a bit of a change... By making the keyboard under 12" wide and reducing the number of keys to 68, I was able to knock close to $100 off the end price. DEFINITELY design and redesign everything while hunting for materials. You can save yourself a lot of money.

Here is the price breakdown (price before shipping in parenthesis if there was shipping costs):
- Colored Keycaps: $30 ($25)
- Teensy 2.0: $16 ($19.03)
- Acrylic Case: $40.64
- 70 Cherry MX Blue switches: $80.25 ($65.10)
- 80 (1N4148) Diodes: $3.00
- Cat5 7ft cable (for colored wires): $1.36
- USB 2.0 to Mini-B 5-pin 6ft cable: $1.41
--- (shipping for cat5 and usb2.0 was $5.99 together)
Total costs: $178.65

NOTE: I am sure I have forgotten something... but this is a good initial cost point. Here is some more information on where I got things and the details about each part:

Colored Keycaps - $30 ($25)

A couple notes first. If a keyboard has a horizontal rectangle for an enter key, it is ANSI. If it has a upsidown L-ish shaped enter key, it is ISO.
There are two main types of Keyboard Profiiles for cherry keycaps. The ones with different shapes for each row are often known as OEM, Standard Profile, or DCS and will talk about R1, R2, etc. for which row that key will fit on (due to it's shape.) The non-shaped keys that will be the same for the whole board are often called DSA or flat keys. Be aware when buying your keys which rows are where or you may end up with a layout that has a jagged set of keys.
I purchased mine from MaxKeyboard. They seemed to have the best price for getting a full set of keys. For the above design I got an "Custom Color Cherry MX Full Replacement Keycap Set (Blank)" with ANSI 104-key full size set. I got the one with the 6.25 spacebar so that I could get the extra 1.25 control keys for the bottom row of my keyboard. (The 6.0 comes with smaller special keys and bigger control keys. See the description on their site. It is a good one.)
The full set like this gives me way more keys than I need, but any other deals would have costed a significant amount more. The above design needs 60 1x1 keys (The size of standard letter keys,) 6 1x1.25 keys (the size of the alt key on most keyboards,) and 2 1x1.5 keys (one and a half the size of a letter key. The size of the tab key on most keyboards.)
The big colored pack gives me all those keys and enough to replace the top row and a few others with blue if I want. This pack also ensures that the profiles for each row will be nice and tidy. The only ones that will be a bit off will be the spacebar and the shift key. This bothered me for a moment, then I decided I wanted the space and shift to stick a bit above the row above it.

Teensy 2.0 - $16 ($19.03)

I did not do too much reading or research on this one. Every custom keyboard guide I looked at online used this one. It seemed like the standard for custom keyboard controllers. There are even some really easy pre-written code things out there, apparently. This seems like a fairly no sweat buy. You can get them cheap straight from their maker: PJRC

Acrylic Case - $40.64

I don't have much to contribute here. The acrylic sheets I have found are all surprisingly expensive. If you have a cheaper way to make a case, let me know. I went with the layers approach described in this guide(in case that link breaks, it just talks about cutting out layers and stacking them up to make the case.) The Cherry MX switches will come in two types: MX1A-xxNN and MX1A-xxNW. The NN switches are meant to be attached to a 1.5mm mounting thing where the NW ones are meant to hook straight to a PCB (circuit board). I mention this here because you will need to get at least one sheet of acrylic that is 1.5mm for the switches to hook into if you are not using a pcb. I found shelf liners on Home Depot's website that fit the bill for my keyboard. From one sheet I could get close to a 3/4" case (and it comes with 4 sheets.) The sheets are actually 0.06" thick, but I figure I can sand them down a bit if that doesn't fit the 1.5mm switches.
Other case options: Most people follow a format similar to some other keyboard. In that case you can simply buy one of those and use the case from it. You may even be able to find a broken one for cheap.

70 Cherry MX1A-E1NN (Blue) switches - $80.25 ($65.10)

I got these with the diodes off of AlliedElec at a bulk rate. If you are getting the normal 104, your cost will be even cheaper per switch. I kinda wanted the brown MX1A-G1NN switches, but everywhere that has them cheap are out of them. If you want to know the difference between the MX switches, there are lots of videos online. Here is a summary of what they are so you are not going out there blind. There are three main types of actions available: Linear, Bump, Bump&Click.
Linear goes down and up at a constant pressure application level. This is supposedly better for gaming and things where you will be holding the key down or doing non-traditional presses with it.
Bump has a slight bump as you press down. This tactile feedback lets you know when the key registers. This is a good all-around key for typing and gaming.
Bump and Click keys are bump keys that also make a click sound when the key registers. These are the most "fun" to type with. They are meant for typing.
Please note that in some of the sound test videos the users are pressing to hard and are creating a "clack" for all keys. This is from the switch bottoming out. That is not the same as the click. There are little bumper rings and pads you can buy to get rid of the clack (if it bothers you) or you can just learn to type with the right amount of force (recommended.)
Within the three categories of linear, bump, and bump&click, there are several choices. Each category will have various switches with different amounts of "actuation force." Reds (Linear), Browns (Bump), and Blues (Bump and Click) are the lightest in each category. These are what you would choose for your letter keys unless you are super heavy handed. Spacebar and some modifiers (and Esc) are usually heavier switches (Unless using multiple switches for the spacebar.) Yeah, thumbs are heavy.
I purchased all blues, as I plan on this being a programming keyboard and I wanted the cheap bulk prices. I may purchase heavier switches for some keys later after I have got a feel for things.

80 (1N4148) Diodes: $3.00

I got these from AlliedElec with my cherry switches. Just search for 1N4148 and they should come up. Diodes are needed to prevent "Ghosting." This is where extra keys can be typed that you never touched. For more info on that see the wiring guide here. It is good and makes sense

Cat5 24awg 7ft cable (for colored wires) - $1.36

It is good to have different colors for wires. Most spools are huge and expensive. One tutorial then mentioned that you can use cat5 cables from Monoprice and I was like "BRILLIANT!" As for the gauge of wire, I have seen suggestions from 20 to 24 awg. I don't know much about wire, so if someone has a more exact answer, please let me know.

USB 2.0 to Mini-B 5-pin 6ft cable (for Teensy): $1.41

The folks at PJRC do not provide a USB cable, so I picked up a 6ft one on Monoprice when I got my cat5 cable.

Until Part 2...

Well, that is all I have for now. I have ordered by parts and they will be coming in the next few weeks. I will post more instructions as I complete them. Hope this helps someone out there who is a total nerd like me.

Also, If anyone actually wants my inkscape design files, let me know. I will gladly share them.