{"id":14467,"date":"2017-10-28T14:14:50","date_gmt":"2017-10-28T18:14:50","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=14467"},"modified":"2020-04-10T08:56:22","modified_gmt":"2020-04-10T12:56:22","slug":"teensy-usb-keypad","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2017\/10\/28\/teensy-usb-keypad\/","title":{"rendered":"Teensy USB Keypad"},"content":{"rendered":"<figure id=\"attachment_14469\" aria-describedby=\"caption-attachment-14469\" style=\"width: 649px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14469 size-large\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb-649x1024.png\" alt=\"\" width=\"649\" height=\"1024\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb-649x1024.png 649w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb-101x160.png 101w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb-203x320.png 203w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb-768x1211.png 768w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/Phone_Keypad_Teensy_bb.png 900w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/a><figcaption id=\"caption-attachment-14469\" class=\"wp-caption-text\">in which I finally learn about Fritzing&#8217;s wire alignment facility \u00e2\u20ac\u00a6<\/figcaption><\/figure>\n<p>I&#8217;ve had a couple of <a href=\"https:\/\/www.pjrc.com\/teensy\/teensy31.html\">Teensy<\/a> boards for a while, but a misunderstanding that they needed a load of of extra software installed (they need one thing, and it&#8217;s easy) had kept me away. They&#8217;ve got really impressive specs, and they&#8217;re especially easy to turn into USB devices like keyboards.<\/p>\n<figure id=\"attachment_14468\" aria-describedby=\"caption-attachment-14468\" style=\"width: 266px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/c-004.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14468 size-full\" src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/c-004.jpg\" alt=\"\" width=\"266\" height=\"330\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/c-004.jpg 266w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/c-004-129x160.jpg 129w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/c-004-258x320.jpg 258w\" sizes=\"auto, (max-width: 266px) 100vw, 266px\" \/><\/a><figcaption id=\"caption-attachment-14468\" class=\"wp-caption-text\">Super-heavy CEECO keypad<\/figcaption><\/figure>\n<p>Here&#8217;s a little demo that turns a phone keypad \u00e2\u20ac\u201d in my case, a ridiculously solid <a href=\"http:\/\/www.ceeco.net\/\">CEECO<\/a> solid metal keypad designed for institutional use \u00e2\u20ac\u201d into a simple USB keyboard. Plug it into any machine (including a Raspberry Pi) and it will be identified as a keyboard. No drivers are required.<\/p>\n<p>The code is based on the standard Arduino <a href=\"https:\/\/playground.arduino.cc\/Code\/Keypad\">Keypad<\/a> library basic demo. That code was meant for a different keypad, so I eventually found a configuration that worked in the Sparkfun <a href=\"https:\/\/www.sparkfun.com\/products\/8653\">12 button keypad<\/a> <a href=\"https:\/\/cdn.sparkfun.com\/datasheets\/Components\/General\/SparkfunCOM-08653_Datasheet.pdf\">datasheet<\/a>. Rather than printing characters to the serial port, I used calls to Teensy&#8217;s <a href=\"https:\/\/www.pjrc.com\/teensy\/td_keyboard.html\">USB Keyboard<\/a> library instead.<\/p>\n<p>The pinout is (from left to right, key side up):<\/p>\n<ol>\n<li>do not connect<\/li>\n<li>Column 2<\/li>\n<li>Row 1<\/li>\n<li>Column 1<\/li>\n<li>Row 4<\/li>\n<li>Column 3<\/li>\n<li>Row 3<\/li>\n<li>Row 2<\/li>\n<li>n\/c<\/li>\n<\/ol>\n<p><script src=\"https:\/\/gist.github.com\/scruss\/e047f2a46aa94e84238226547f3012a0.js\"><\/script><\/p>\n<p>There&#8217;s no reason why this wouldn&#8217;t work with those very cheap <a href=\"https:\/\/scruss.com\/blog\/2017\/10\/31\/fritzing-generic-4x4-keypad-part\/\">4\u00c3\u20144 button matrix keypads for Arduino<\/a> too with only minor modifications. Those keypads use 8 data lines, and they&#8217;re arranged (I think) as <del>rows 1-4 on pins 1-4 and columns 1-4 are pins 5-8.<\/del> columns 4-1 then rows 1-4 from the top of the pin connector down:<\/p>\n<p><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/4x4keypad.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14472\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/4x4keypad.jpg\" alt=\"\" width=\"336\" height=\"304\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/4x4keypad.jpg 336w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/4x4keypad-160x145.jpg 160w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2017\/10\/4x4keypad-320x290.jpg 320w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/a>The Teensy USB keyboard isn&#8217;t limited to sending single characters: a single button press could trigger sending a whole string. I haven&#8217;t yet thought out any major uses for this (except \u00e2\u20ac\u0153Crypto!\u00e2\u20ac\u009d, which is my usual idea when I have no idea what I&#8217;m doing), but you might have better plans.<\/p>\n<p><strong>Update, 2020-04<\/strong>: These keypads don&#8217;t have diodes on every key to prevent key ghosting if you press multiple keys. <a href=\"https:\/\/playground.arduino.cc\/Code\/Keypad\/\">Despite what the Arduino Playground Keypad section might tell you<\/a>, you can&#8217;t do useful multi-key\/rollover detection with them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had a couple of Teensy boards for a while, but a misunderstanding that they needed a load of of extra software installed (they need one thing, and it&#8217;s easy) had kept me away. They&#8217;ve got really impressive specs, and they&#8217;re especially easy to turn into USB devices like keyboards. Here&#8217;s a little demo that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2],"tags":[2208,2510,3091,229],"class_list":["post-14467","post","type-post","status-publish","format-standard","hentry","category-goatee-stroking-musing-or-something","tag-electronics","tag-raspberrypi","tag-teensy","tag-usb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-3Ll","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=14467"}],"version-history":[{"count":3,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14467\/revisions"}],"predecessor-version":[{"id":16145,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/14467\/revisions\/16145"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=14467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=14467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=14467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}