{"id":370,"date":"2011-10-05T16:53:10","date_gmt":"2011-10-05T16:53:10","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=370"},"modified":"2011-10-05T16:55:36","modified_gmt":"2011-10-05T16:55:36","slug":"a-programmable-keyboard-controller","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2011\/10\/a-programmable-keyboard-controller\/","title":{"rendered":"A Programmable Keyboard Controller"},"content":{"rendered":"<p>I was frustrated by the Mac keyboard layout and also noticed that a lot of projects require some kind of custom keyboard controller (for example, if you&#8217;re trying to hack and old PS2 keyboard to work with a modern system. For this reason I decided to create a programmable keyboard controller.<\/p>\n<p><a href=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_powered1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_powered1-1024x273.jpg\" alt=\"\" title=\"kb_powered1\" width=\"630\" height=\"167\" class=\"aligncenter size-large wp-image-376\" srcset=\"https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_powered1-1024x273.jpg 1024w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_powered1-300x80.jpg 300w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_powered1.jpg 1263w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/a><\/p>\n<p>The controller is based around a <a href=\"http:\/\/www.atmel.com\/dyn\/products\/tools_card.asp?tool_id=3879\">AT90USBKey<\/a> and uses the <a href=\"http:\/\/www.fourwalledcubicle.com\/LUFA.php\">LUFA<\/a> library to manage the USB HID stuff.<\/p>\n<p>To use the keyboard controller you need to removed the existing controller from your keyboard (hence the <a href=\"http:\/\/41j.com\/blog\/2011\/09\/mac-aluminium-keyboard-disassembly\/\">Mac keyboard disassembly<\/a> I previously posted). Once removed you need to connect the keyboard matrix to the controller. It doesn&#8217;t really matter how you connect it, the idea is that the keyboard will learn the keyboard layout.<\/p>\n<p>Here&#8217;s a close up of the controller installed in a Mac full size keyboard:<\/p>\n<p><a href=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller1-1024x472.jpg\" alt=\"\" title=\"kb_controller1\" width=\"630\" height=\"290\" class=\"aligncenter size-large wp-image-371\" srcset=\"https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller1-1024x472.jpg 1024w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller1-300x138.jpg 300w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller1.jpg 1235w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/a><\/p>\n<p>And a slightly less elegant hack in to a Mini mac keyboard:<\/p>\n<p><a href=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller_2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller_2-1024x377.jpg\" alt=\"\" title=\"kb_controller_2\" width=\"630\" height=\"231\" class=\"aligncenter size-large wp-image-372\" srcset=\"https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller_2-1024x377.jpg 1024w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller_2-300x110.jpg 300w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/kb_controller_2.jpg 1245w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/a><\/p>\n<p>To program the keyboard, open notepad or another text editor on your computer. Plug the keyboard in while holding down a key. The keyboard will being typing text in to the text editor. It&#8217;ll start my printing a welcome message and will then ask you to press keys on your keyboard.<\/p>\n<p><a href=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/keyboard_output.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/keyboard_output.png\" alt=\"\" title=\"keyboard_output\" width=\"731\" height=\"537\" class=\"aligncenter size-full wp-image-373\" srcset=\"https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/keyboard_output.png 731w, https:\/\/41j.com\/blog\/wp-content\/uploads\/2011\/10\/keyboard_output-300x220.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/a><\/p>\n<p>The controller is now learning which key is which. It&#8217;s continually scanning the keyboard matrix, and when it detects a short between pins it registers this as the key it&#8217;s currently learning. Once training is complete the controller writes the matrix layout information to the AT90s internal flash. So you only need to train once.<\/p>\n<p>The whole thing seems to work pretty well, though I think my debouncing logic could do with some work. Suggestions are welcome.<\/p>\n<p>I&#8217;ve put all the code on sourceforge <a href=\"http:\/\/progkb.svn.sourceforge.net\/viewvc\/progkb\/trunk\/\">here<\/a>.<\/p>\n<p>If you&#8217;re interested in using or developing from this code, please let me know. I think a keyboard controller like this could be a generally useful tool for hacking projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was frustrated by the Mac keyboard layout and also noticed that a lot of projects require some kind of custom keyboard controller (for example, if you&#8217;re trying to hack and old PS2 keyboard to work with a modern system. For this reason I decided to create a programmable keyboard controller. The controller is based [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-5Y","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":9,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}