{"id":1652,"date":"2014-07-31T12:02:56","date_gmt":"2014-07-31T11:02:56","guid":{"rendered":"http:\/\/blog.agm.me.uk\/blog\/?p=1652"},"modified":"2015-03-10T17:37:21","modified_gmt":"2015-03-10T17:37:21","slug":"zx-keyboard","status":"publish","type":"post","link":"https:\/\/blog.agm.me.uk\/blog\/2014\/07\/zx-keyboard.php","title":{"rendered":"ZX Keyboard"},"content":{"rendered":"<div id=\"attachment_1665\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"http:\/\/blog.agm.me.uk\/blog\/files\/2014\/07\/P1060215.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1665\" class=\"size-medium wp-image-1665\" src=\"http:\/\/blog.agm.me.uk\/blog\/files\/2014\/07\/P1060215-300x225.jpg\" alt=\"A ZX Spectrum converted in to a USB keyboard on show at Manchester Mini Maker faire.\" width=\"300\" height=\"225\" srcset=\"https:\/\/blog.agm.me.uk\/blog\/files\/2014\/07\/P1060215-300x225.jpg 300w, https:\/\/blog.agm.me.uk\/blog\/files\/2014\/07\/P1060215.jpg 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1665\" class=\"wp-caption-text\">The ZX Keyboard, a USB keyboard made from an old ZX Spectrum on show at\u00a0Manchester Mini Maker Faire.<\/p><\/div>\n<p>Several year ago I decided that I wanted to make an old ZX Spectrum keyboard work with an emulator and ended up making\u00a0one in to a USB keyboard. This is the\u00a0rather waffly history\u00a0of the project with a few tips and links for building your own. I have also created a <a href=\"http:\/\/hackaday.io\/project\/2076-ZX-Keyboard\">Hack a Day page<\/a> for the basic build instructions and a <a href=\"https:\/\/github.com\/alistairuk\/ZX-Keyboard\">GitHub repository<\/a> for the files.<\/p>\n<p>Although I have never owned a working rubber keyed ZX Spectrum (mine was a Spectrum+ with a more solid tactile keyboard) I was given a broken rubber keyed one many many years ago. It was in a bit bashed up and did not work, and I have used a few of it&#8217;s components to fix other machines, but surprisingly the keyboard was okay.<\/p>\n<p>Back in the\u00a0start of 2012\u00a0I wanted to mount a soon to be released\u00a0Raspberry Pi inside and emulate a full ZX Spectrum, as well as a Commodore 64 just to mess with people&#8217;s heads. I waited until the Model B was Pi eventually available but it would not fit without making\u00a0more modifications than I wanted, and the smaller Model A was a long way off becoming a reality. I then decided that instead of mounting the Pi inside I should turn it in to a USB keyboard so I could use it with a Pi or a normal desktop PC. Naturally I then forgot about it for another couple of years, until for some reason just now.<\/p>\n<p>Several people have asked why I did not use Bluetooth (some\u00a0more criticising that asking, but whatever) and\u00a0there was a\u00a0<a href=\"https:\/\/www.kickstarter.com\/projects\/952953995\/bluetooth-zx-spectrum-recreating-the-sinclair-zx-s\">Kickstarter making new Bluetooth ZX Spectrum style keyboards<\/a>,\u00a0but the project was to use an original ketboard, get it working with the Pi, and\u00a0to do it myself.<\/p>\n<p>Anyway, the build&#8230;<\/p>\n<p>The hardware\u00a0was surprisingly easy with the big unknown being the USB communication to which\u00a0I considered a few\u00a0solutions. Lots of projects use \u00a0a Arduino\u00a0Leonardo that can natively emulate a USB keyboard, or\u00a0<a href=\"http:\/\/www.kevindemarco.com\/2014\/01\/02\/arduino-uno-as-a-usb-hid-interface\/\">reprogramme the Arduino Uno&#8217;s serial controller<\/a>\u00a0that requires zero extra hardware, but will prevent the Arduino from being programmed via the USB port. I was keen to use a\u00a0low cost (the one used cost \u00a31.30)\u00a0<a href=\"http:\/\/arduino.cc\/en\/Main\/ArduinoBoardProMini\">Arduino Pro Mini<\/a>\u00a0clone and a small number of basic components.<\/p>\n<p>Having decided on the Arduino Pro Mini (yes, I have my cart pull the horse for pet projects) the easy solution\u00a0(for me because of prior knowledge) was to get the\u00a0Arduino to emulate a PS2 keyboard and use a cheap PS2 to USB converter. If it was a one off commercial project, or I was against the clock then this is what I would do as it is the quick and easy solution that adds pennies to to cost of the project. This however is a daft pet project that is an ideal excuse to use as a learning experience, so I\u00a0decided to play\u00a0with the\u00a0<a href=\"http:\/\/www.obdev.at\/products\/vusb\/index.html\">V-USB library<\/a>\u00a0from Objective Development. \u00a0In the end I found the\u00a0<a href=\"https:\/\/code.google.com\/p\/vusb-for-arduino\/\">VUSB\u00a0for Arduino<\/a>\u00a0library that had done a lot of the porting work for me, although I am bypassing the top levels of the library to increase compatibility and allow multiple keys to pressed. Now I have thins knowledge my default may well be to opt for USB for future projects.<\/p>\n<p>Connecting to the keyboard hardware was easy enough as I reused the original connectors from the old motherboard that already had components missing. The flat cable from the\u00a0membrane\u00a0was very tarnished and had cracks\u00a0across the connections but\u00a0I chopped an inch off the end and\u00a0this solved the problem. The connections\u00a0have been\u00a0well documented by\u00a0hobbyists over the years so there was no backwards engineering required. The way it is wired to the Arduino is not just to make things look neat mind. I will also help the software. Instead of having to check each button of each column\u00a0at a time it is arranged so multiple values can be read in an operation.<\/p>\n<p>The key mapping took a lot of thought and I have tried to make the keyboard usable for normal operations while keeping full compatibility for Spectrum Emulators. I think I have managed that and have written a little about how it works on the\u00a0hackaday page mentioned at the top of this post.<\/p>\n<p>So that is it.\u00a0I will be taking the keyboard to\u00a0future hack days, Bar Camps, and Mini Maker Fairs if you would like to see it. I hope you are inspired to have a go at building one, perhaps a better one than mine. Do let me know if you do. If you want one but don&#8217;t have the time or skills to convert your old ZX Spectrum (or any other machine for that matter) then I am happy to do it for a few quid so <a href=\"http:\/\/www.agm.me.uk\/contact\">get in touch<\/a>.<\/p>\n<p>Update: It appears that the latest Arduino IDE (version 1.6) will not compile the VUSB library because of an old big in it. A quick work around is to install an older version of the Arduino IDE. It works for me with version 1.0.5.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Several year ago I decided that I wanted to make an old ZX Spectrum keyboard work with an emulator and ended up making\u00a0one in to a USB keyboard. This is the\u00a0rather waffly history\u00a0of the project with a few tips and links for building your own. I have also created a Hack a Day page for [&hellip;]<\/p>\n","protected":false},"author":2,"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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,6],"tags":[],"class_list":["post-1652","post","type-post","status-publish","format-standard","hentry","category-fun","category-tech"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4t60H-qE","_links":{"self":[{"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/comments?post=1652"}],"version-history":[{"count":14,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions"}],"predecessor-version":[{"id":1707,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/posts\/1652\/revisions\/1707"}],"wp:attachment":[{"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/media?parent=1652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/categories?post=1652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.agm.me.uk\/blog\/wp-json\/wp\/v2\/tags?post=1652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}